From 5e6371b5eb1adc2c31445278bbc18b8bea3ba955 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Fri, 28 Mar 2025 18:34:01 +0000 Subject: [PATCH] support custom origin for ws --- src/index.js | 4 +++- src/ws.js | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 19acf4b..6e5caca 100755 --- a/src/index.js +++ b/src/index.js @@ -77,7 +77,9 @@ export function createClient({ if (typeof ws === "object") { if (ws.enable === true) { - __comty_shared_state.ws = new WebsocketManager() + __comty_shared_state.ws = new WebsocketManager({ + origin: origin, + }) if (ws.autoConnect === true) { sharedState.ws.connectAll() diff --git a/src/ws.js b/src/ws.js index 48c558b..971acbd 100644 --- a/src/ws.js +++ b/src/ws.js @@ -6,6 +6,10 @@ import { RTEngineClient } from "linebridge-client/src" //import { RTEngineClient } from "../../linebridge/client/src" class WebsocketManager { + constructor({ origin }) { + this.origin = origin + } + sockets = new Map() async connect(remote) { @@ -23,7 +27,7 @@ class WebsocketManager { } } - const socket = io(Remotes.origin, opts) + const socket = io(this.origin, opts) socket.on("connect", () => { globalThis.__comty_shared_state.eventBus.emit( @@ -57,7 +61,7 @@ class WebsocketManager { const client = new RTEngineClient({ refName: remote.namespace, - url: `${Remotes.origin}/${remote.namespace}`, + url: `${this.origin}/${remote.namespace}`, token: Storage.engine.get("token"), })