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