Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chg(ws): use platform factory (#853)

teo219a02854ad3
diff --git a/js/app/packages/websocket/core/websocket.ts b/js/app/packages/websocket/core/websocket.ts
index 1ab85cf82b..b9bd30c05c 100644
--- a/js/app/packages/websocket/core/websocket.ts
+++ b/js/app/packages/websocket/core/websocket.ts
@@ -1,5 +1,5 @@
+import { platformWebSocketFactory } from '@websocket/platform/factory';
import { match, P } from 'ts-pattern';
-import { browserWebSocketFactory } from '../platform/minimal-websocket';
import type { Backoff } from './backoff/backoff';
import type { WebsocketBuffer } from './websocket-buffer';
import { WebsocketConnectionState } from './websocket-connection-state';
@@ -343,7 +343,7 @@ export class Websocket<Send = WebsocketData, Receive = WebsocketData> {
}
);
this.dispatchEvent(WebsocketEvent.UrlResolved, event);
- const factory = this._options.factory ?? browserWebSocketFactory;
+ const factory = this._options.factory ?? platformWebSocketFactory;
const newSocket = factory(this.url, this.protocols); // create new browser-native websocket and add all event listeners
this._underlyingWebsocket = newSocket;
this._underlyingWebsocket.addEventListener(
diff --git a/js/app/packages/websocket/platform/factory.ts b/js/app/packages/websocket/platform/factory.ts
new file mode 100644
index 0000000000..918096c9e5
--- /dev/null
+++ b/js/app/packages/websocket/platform/factory.ts
@@ -0,0 +1,18 @@
+import { isTauri } from '@core/util/platform';
+import {
+ browserWebSocketFactory,
+ type WebSocketFactory,
+} from './minimal-websocket';
+import { tauriWebSocketFactory } from './tauri-websocket';
+
+/**
+ * Dynamic WebSocket factory that returns the right websocket wrapper
+ * depending on the platform
+ */
+export const platformWebSocketFactory: WebSocketFactory = (url, protocols) => {
+ if (isTauri()) {
+ return tauriWebSocketFactory(url, protocols);
+ }
+
+ return browserWebSocketFactory(url, protocols);
+};