diff --git a/client/src/app/core/core-services/offline.service.ts b/client/src/app/core/core-services/offline.service.ts index 9af961e4a..89b7b9f83 100644 --- a/client/src/app/core/core-services/offline.service.ts +++ b/client/src/app/core/core-services/offline.service.ts @@ -1,56 +1,51 @@ import { Injectable } from '@angular/core'; -import { WebsocketService } from './websocket.service'; +import { BehaviorSubject, Observable } from 'rxjs'; /** * This service handles everything connected with being offline. * * TODO: This is just a stub. Needs to be done in the future; Maybe we cancel this whole concept - * of this service. We'll see whats happens here.. + * of this service. We'll see what happens here.. */ @Injectable({ providedIn: 'root' }) export class OfflineService { - private _offline = false; - - public get offline(): boolean { - return this._offline; - } - /** + * BehaviorSubject to receive further status values. */ - public constructor(private socketService: WebsocketService) {} + private offline = new BehaviorSubject(false); /** * Determines of you are either in Offline mode or not connected via websocket * * @returns whether the client is offline or not connected */ - public isOffline(): boolean { - return this.offline || !this.socketService.isConnected; + public isOffline(): Observable { + return this.offline; } /** * Sets the offline flag. Restores the DataStoreService to the last known configuration. */ public goOfflineBecauseFailedWhoAmI(): void { - this._offline = true; + this.offline.next(true); console.log('offline because whoami failed.'); } /** - * TODO: Should be somehow connected to the websocket service. + * Sets the offline flag, because there is no connection to the server. */ public goOfflineBecauseConnectionLost(): void { - this._offline = true; + this.offline.next(true); console.log('offline because connection lost.'); } /** - * TODO: Should be somehow connected to the websocket service. + * Function to return to online-status. */ public goOnline(): void { - this._offline = false; + this.offline.next(false); } } diff --git a/client/src/app/core/core-services/websocket.service.ts b/client/src/app/core/core-services/websocket.service.ts index eb147901a..c7fb739e2 100644 --- a/client/src/app/core/core-services/websocket.service.ts +++ b/client/src/app/core/core-services/websocket.service.ts @@ -1,13 +1,13 @@ import { EventEmitter, Injectable, NgZone } from '@angular/core'; -import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar'; +import { MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar'; import { Router } from '@angular/router'; -import { TranslateService } from '@ngx-translate/core'; import { compress, decompress } from 'lz4js'; import { Observable, Subject } from 'rxjs'; import { take } from 'rxjs/operators'; import { TextDecoder, TextEncoder } from 'text-encoding'; +import { OfflineService } from './offline.service'; import { OpenSlidesStatusService } from './openslides-status.service'; import { formatQueryParams, QueryParams } from '../definitions/query-params'; @@ -189,17 +189,17 @@ export class WebsocketService { /** * Constructor that handles the router - * @param matSnackBar + * * @param zone - * @param translate * @param router + * @param openSlidesStatusService + * @param offlineService */ public constructor( - private matSnackBar: MatSnackBar, private zone: NgZone, - private translate: TranslateService, private router: Router, - private openSlidesStatusService: OpenSlidesStatusService + private openSlidesStatusService: OpenSlidesStatusService, + private offlineService: OfflineService ) {} /** @@ -380,12 +380,7 @@ export class WebsocketService { } 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.'), - '', - { duration: 0 } - ); + this.offlineService.goOfflineBecauseConnectionLost(); } // A random retry timeout between 2000 and 5000 ms. @@ -405,10 +400,7 @@ export class WebsocketService { } private dismissConnectionErrorNotice(): void { - if (this.connectionErrorNotice) { - this.connectionErrorNotice.dismiss(); - this.connectionErrorNotice = null; - } + this.offlineService.goOnline(); } /** diff --git a/client/src/app/shared/components/projector/projector.component.html b/client/src/app/shared/components/projector/projector.component.html index 8f8dfd9b5..be4c5f1c4 100644 --- a/client/src/app/shared/components/projector/projector.component.html +++ b/client/src/app/shared/components/projector/projector.component.html @@ -1,6 +1,6 @@
-
+
fiber_manual_record diff --git a/client/src/app/shared/components/projector/projector.component.ts b/client/src/app/shared/components/projector/projector.component.ts index bca0cd4f6..df4dd3d6a 100644 --- a/client/src/app/shared/components/projector/projector.component.ts +++ b/client/src/app/shared/components/projector/projector.component.ts @@ -148,11 +148,21 @@ export class ProjectorComponent extends BaseComponent implements OnDestroy { */ public scale = 0; + /** + * Info about if the user is offline. + */ + public isOffline = false; + /** * The subscription to the projector. */ private projectorSubscription: Subscription; + /** + * Holds the subscription to the offline-service. + */ + private offlineSubscription: Subscription; + /** * A subject that fires, if the container is resized. */ @@ -226,15 +236,8 @@ export class ProjectorComponent extends BaseComponent implements OnDestroy { this.updateScaling(); } }); - } - /** - * determine if the server is offline - * - * @returns whether the client is offlien - */ - public isOffline(): boolean { - return this.offlineService.isOffline(); + this.offlineSubscription = this.offlineService.isOffline().subscribe(isOffline => (this.isOffline = isOffline)); } /** @@ -327,5 +330,9 @@ export class ProjectorComponent extends BaseComponent implements OnDestroy { } document.head.removeChild(this.styleElement); this.styleElement = null; + if (this.offlineSubscription) { + this.offlineSubscription.unsubscribe(); + this.offlineSubscription = null; + } } } diff --git a/client/src/app/site/site.component.html b/client/src/app/site/site.component.html index a7024a6f4..6a92429ef 100644 --- a/client/src/app/site/site.component.html +++ b/client/src/app/site/site.component.html @@ -1,3 +1,4 @@ +
cloud_offOffline mode
You are using the history mode of OpenSlides. Changes will not be saved. ({{ getHistoryTimestamp() }}) @@ -133,7 +134,6 @@ -