From ccf37758d4f59f04d8bfeeb318ae6bcb7df90e1a Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 29 Mar 2019 08:36:18 +0100 Subject: [PATCH] delay the offline message --- .../app/core/core-services/websocket.service.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/src/app/core/core-services/websocket.service.ts b/client/src/app/core/core-services/websocket.service.ts index 224d8f855..09e7c9360 100644 --- a/client/src/app/core/core-services/websocket.service.ts +++ b/client/src/app/core/core-services/websocket.service.ts @@ -94,6 +94,11 @@ export class WebsocketService { */ private retry = false; + /** + * Counter for delaying the offline message. + */ + private retryCounter = 0; + /** * Constructor that handles the router * @param matSnackBar @@ -147,6 +152,7 @@ export class WebsocketService { // The error notice will be removed and the reconnectSubject is published. this.websocket.onopen = (event: Event) => { this.zone.run(() => { + this.retryCounter = 0; if (this.retry) { if (this.connectionErrorNotice) { this.connectionErrorNotice.dismiss(); @@ -183,13 +189,17 @@ export class WebsocketService { this.zone.run(() => { this.websocket = null; this._connectionOpen = false; + // 1000 is a normal close, like the close on logout if (event.code !== 1000) { console.error(event); // Do not show the message snackbar on the projector // tests for /projector and /projector/ const onProjector = this.router.url.match(/^\/projector(\/[0-9]+\/?)?$/); - // 1000 is a normal close, like the close on logout - if (!this.connectionErrorNotice && !onProjector) { + if (this.retryCounter <= 3) { + this.retryCounter++; + } + + if (!this.connectionErrorNotice && !onProjector && this.retryCounter > 3) { // So here we have a connection failure that wasn't intendet. this.connectionErrorNotice = this.matSnackBar.open( this.translate.instant('Offline mode: You can use OpenSlides but changes are not saved.'),