static: backoff retrying to connect to ws

This commit is contained in:
Jens Langhammer 2020-11-26 18:04:24 +01:00
parent 89400b4ea4
commit a91d0ddc6c
3 changed files with 7 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -27,6 +27,8 @@ export class Messages extends LitElement {
messageSocket?: WebSocket; messageSocket?: WebSocket;
retryDelay: number = 200;
createRenderRoot() { createRenderRoot() {
return this; return this;
} }
@ -47,9 +49,10 @@ export class Messages extends LitElement {
this.messageSocket.addEventListener("close", (e) => { this.messageSocket.addEventListener("close", (e) => {
console.debug(`passbook/messages: closed ws connection: ${e}`); console.debug(`passbook/messages: closed ws connection: ${e}`);
setTimeout(() => { setTimeout(() => {
console.debug(`passbook/messages: reconnecting ws`); console.debug(`passbook/messages: reconnecting ws in ${this.retryDelay}`);
this.connect(); this.connect();
}, 1000); }, this.retryDelay);
this.retryDelay = this.retryDelay * 2;
}); });
this.messageSocket.addEventListener("message", (e) => { this.messageSocket.addEventListener("message", (e) => {
const container = <HTMLElement>( const container = <HTMLElement>(