Skip to content

Commit

Permalink
Merge pull request #511 from coasys/connect-proxy-fixes-1
Browse files Browse the repository at this point in the history
Connect proxy fix not connecting to proxy even if its runnning
  • Loading branch information
lucksus authored Aug 6, 2024
2 parents 4ea0111 + e0dfda0 commit 8a5328a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 3 additions & 9 deletions connect/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand All @@ -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({
Expand Down
7 changes: 5 additions & 2 deletions connect/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit 8a5328a

Please sign in to comment.