OpenSlides/client/src/app/core/core-services/offline.service.ts

52 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-10-26 10:23:14 +02:00
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
2018-10-26 10:23:14 +02:00
/**
* 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 what happens here..
2018-10-26 10:23:14 +02:00
*/
@Injectable({
providedIn: 'root'
})
2019-02-08 17:24:32 +01:00
export class OfflineService {
2018-10-26 10:23:14 +02:00
/**
* BehaviorSubject to receive further status values.
2018-10-26 10:23:14 +02:00
*/
private offline = new BehaviorSubject<boolean>(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(): Observable<boolean> {
return this.offline;
}
2018-10-26 10:23:14 +02:00
/**
* Sets the offline flag. Restores the DataStoreService to the last known configuration.
*/
2019-03-04 11:45:15 +01:00
public goOfflineBecauseFailedWhoAmI(): void {
this.offline.next(true);
2018-10-26 10:23:14 +02:00
console.log('offline because whoami failed.');
}
/**
* Sets the offline flag, because there is no connection to the server.
2018-10-26 10:23:14 +02:00
*/
public goOfflineBecauseConnectionLost(): void {
this.offline.next(true);
2018-10-26 10:23:14 +02:00
console.log('offline because connection lost.');
}
/**
* Function to return to online-status.
2018-10-26 10:23:14 +02:00
*/
public goOnline(): void {
this.offline.next(false);
2018-10-26 10:23:14 +02:00
}
}