mirror of
https://github.com/owncast/owncast.git
synced 2024-11-22 04:40:37 +03:00
fix(chat): make websocket reconnects happen faster. Closes #3021
This commit is contained in:
parent
d5b0159f4a
commit
05f7075244
1 changed files with 4 additions and 4 deletions
|
@ -18,7 +18,7 @@ export default class WebsocketService {
|
|||
|
||||
isShutdown = false;
|
||||
|
||||
backOff = 1000;
|
||||
backOff = 0;
|
||||
|
||||
handleMessage?: (message: SocketEvent) => void;
|
||||
|
||||
|
@ -54,7 +54,6 @@ export default class WebsocketService {
|
|||
url.port = window.location.port === '3000' ? '8080' : window.location.port;
|
||||
url.searchParams.append('accessToken', this.accessToken);
|
||||
|
||||
console.debug('connecting to ', url.toString());
|
||||
const ws = new WebSocket(url.toString());
|
||||
ws.onopen = this.onOpen.bind(this);
|
||||
ws.onerror = this.onError.bind(this);
|
||||
|
@ -68,6 +67,7 @@ export default class WebsocketService {
|
|||
clearTimeout(this.websocketReconnectTimer);
|
||||
}
|
||||
this.socketConnected();
|
||||
this.backOff = 0;
|
||||
}
|
||||
|
||||
// On ws error just close the socket and let it re-connect again for now.
|
||||
|
@ -88,11 +88,11 @@ export default class WebsocketService {
|
|||
if (this.websocketReconnectTimer) {
|
||||
clearTimeout(this.websocketReconnectTimer);
|
||||
}
|
||||
this.backOff *= 2;
|
||||
this.websocketReconnectTimer = setTimeout(
|
||||
this.createAndConnect,
|
||||
5000 + Math.min(this.backOff, 10_000),
|
||||
Math.min(this.backOff, 10_000),
|
||||
);
|
||||
this.backOff += 1000;
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
|
|
Loading…
Reference in a new issue