From 78b110b0812efa3591c98d90036c0f8572ea9621 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Mon, 5 Aug 2024 12:46:02 +0530 Subject: [PATCH 1/2] chore: Fix WebSocket connection issue with proxy URLs --- connect/src/utils.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/connect/src/utils.ts b/connect/src/utils.ts index a5199418c..37294c1d4 100644 --- a/connect/src/utils.ts +++ b/connect/src/utils.ts @@ -14,12 +14,15 @@ export async function connectWebSocket(url, timeout = 10000) { return Promise.race([ new Promise((resolve, reject) => { try { + if (url.includes("proxy")) { + resolve(new WebSocket(url)); + } const websocket = new WebSocket(url); - + websocket.onopen = () => { resolve(websocket); }; - + websocket.onerror = (error) => { reject(error); }; From e0dfda0217e6709db9f9278d91c7bf206f248259 Mon Sep 17 00:00:00 2001 From: Fayeed Pawaskar Date: Mon, 5 Aug 2024 12:46:55 +0530 Subject: [PATCH 2/2] remove timeout --- connect/src/core.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/connect/src/core.ts b/connect/src/core.ts index 92a4cc629..0304d64f2 100644 --- a/connect/src/core.ts +++ b/connect/src/core.ts @@ -193,7 +193,7 @@ export default class Ad4mConnect { if (data.serviceId) { this.setPort(data.port); this.setUrl(data.url); - + this.isHosting = true; setForVersion('ad4mhosting', 'true'); @@ -297,15 +297,7 @@ export default class Ad4mConnect { try { const websocket = new WebSocket(this.url); - websocket.onerror = (error) => { - this.notifyConnectionChange("not_connected"); - }; - setTimeout(() => { - if (websocket.readyState !== WebSocket.OPEN) { - this.notifyConnectionChange("not_connected"); - } - }, 10000); } catch (e) { this.notifyConnectionChange("not_connected"); return; @@ -315,6 +307,8 @@ export default class Ad4mConnect { this.requestedRestart = true; this.wsClient.dispose(); this.apolloClient.stop(); + this.wsClient = null; + this.apolloClient = null; } this.wsClient = createClient({