Skip to content

Commit f7110d4

Browse files
authored
Fixed a reconnect bug with websockets (#31)
* Fixed a reconnect bug with websockets * Added no-sandbox arg * Added chrome as browser * Added puppeteer as dependency * removed puppeteer install. Added --no-sandbox * Added allow-chrome-as-root
1 parent dc072f0 commit f7110d4

File tree

3 files changed

+215
-183
lines changed

3 files changed

+215
-183
lines changed

lib/client/socket.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,32 +174,32 @@ function createNewConnection() {
174174
}
175175
});
176176

177-
socket.addEventListener("error", (error) => {
178-
ready = false;
179-
console.error(error);
177+
stateChangeEvents.forEach(callback => callback("OPEN"));
178+
} else {
179+
createNewConnection();
180+
}
181+
});
180182

181-
stateChangeEvents.forEach(callback => callback("ERROR"));
182-
});
183+
socket.addEventListener("error", (error) => {
184+
ready = false;
185+
console.error(error);
183186

184-
socket.addEventListener("close", () => {
185-
ready = false;
186-
const timeout: number = typeof setOptions.reconnectTimeOut === "function" ? setOptions.reconnectTimeOut() : setOptions.reconnectTimeOut;
187+
stateChangeEvents.forEach(callback => callback("ERROR"));
188+
});
187189

188-
// wait for a little before reconnecting
189-
if (setOptions.reconnect) {
190-
setTimeout(createNewConnection, timeout);
191-
}
192-
// if the previous state wasn't auth failed then send a closed message
193-
if (getCurrentState() !== "AUTHFAILED") {
194-
stateChangeEvents.forEach(callback => callback("CLOSED"));
195-
}
196-
});
190+
socket.addEventListener("close", () => {
191+
ready = false;
192+
const timeout: number = typeof setOptions.reconnectTimeOut === "function" ? setOptions.reconnectTimeOut() : setOptions.reconnectTimeOut;
197193

198-
stateChangeEvents.forEach(callback => callback("OPEN"));
199-
} else {
200-
createNewConnection();
194+
// wait for a little before reconnecting
195+
if (setOptions.reconnect) {
196+
setTimeout(createNewConnection, timeout);
197+
}
198+
// if the previous state wasn't auth failed then send a closed message
199+
if (getCurrentState() !== "AUTHFAILED") {
200+
stateChangeEvents.forEach(callback => callback("CLOSED"));
201201
}
202-
})
202+
});
203203
}
204204

205205
/**

0 commit comments

Comments
 (0)