Merge pull request #4544 from FinnStutzenstein/delayedOfflineMessage

delay the offline message
This commit is contained in:
Finn Stutzenstein 2019-03-29 09:11:04 +01:00 committed by GitHub
commit b130a28a4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,6 +94,11 @@ export class WebsocketService {
*/ */
private retry = false; private retry = false;
/**
* Counter for delaying the offline message.
*/
private retryCounter = 0;
/** /**
* Constructor that handles the router * Constructor that handles the router
* @param matSnackBar * @param matSnackBar
@ -147,6 +152,7 @@ export class WebsocketService {
// The error notice will be removed and the reconnectSubject is published. // The error notice will be removed and the reconnectSubject is published.
this.websocket.onopen = (event: Event) => { this.websocket.onopen = (event: Event) => {
this.zone.run(() => { this.zone.run(() => {
this.retryCounter = 0;
if (this.retry) { if (this.retry) {
if (this.connectionErrorNotice) { if (this.connectionErrorNotice) {
this.connectionErrorNotice.dismiss(); this.connectionErrorNotice.dismiss();
@ -183,13 +189,17 @@ export class WebsocketService {
this.zone.run(() => { this.zone.run(() => {
this.websocket = null; this.websocket = null;
this._connectionOpen = false; this._connectionOpen = false;
// 1000 is a normal close, like the close on logout
if (event.code !== 1000) { if (event.code !== 1000) {
console.error(event); console.error(event);
// Do not show the message snackbar on the projector // Do not show the message snackbar on the projector
// tests for /projector and /projector/<id> // tests for /projector and /projector/<id>
const onProjector = this.router.url.match(/^\/projector(\/[0-9]+\/?)?$/); const onProjector = this.router.url.match(/^\/projector(\/[0-9]+\/?)?$/);
// 1000 is a normal close, like the close on logout if (this.retryCounter <= 3) {
if (!this.connectionErrorNotice && !onProjector) { this.retryCounter++;
}
if (!this.connectionErrorNotice && !onProjector && this.retryCounter > 3) {
// So here we have a connection failure that wasn't intendet. // So here we have a connection failure that wasn't intendet.
this.connectionErrorNotice = this.matSnackBar.open( this.connectionErrorNotice = this.matSnackBar.open(
this.translate.instant('Offline mode: You can use OpenSlides but changes are not saved.'), this.translate.instant('Offline mode: You can use OpenSlides but changes are not saved.'),