2018-10-26 10:23:14 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
2019-07-26 11:46:59 +02:00
|
|
|
|
2019-08-20 14:57:20 +02:00
|
|
|
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
|
2019-08-20 14:57:20 +02:00
|
|
|
* 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
|
|
|
/**
|
2019-08-20 14:57:20 +02:00
|
|
|
* BehaviorSubject to receive further status values.
|
2018-10-26 10:23:14 +02:00
|
|
|
*/
|
2019-08-20 14:57:20 +02:00
|
|
|
private offline = new BehaviorSubject<boolean>(false);
|
2019-03-29 11:05:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines of you are either in Offline mode or not connected via websocket
|
|
|
|
*
|
|
|
|
* @returns whether the client is offline or not connected
|
|
|
|
*/
|
2019-08-20 14:57:20 +02:00
|
|
|
public isOffline(): Observable<boolean> {
|
|
|
|
return this.offline;
|
2019-03-29 11:05:44 +01:00
|
|
|
}
|
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 {
|
2019-08-20 14:57:20 +02:00
|
|
|
this.offline.next(true);
|
2018-10-26 10:23:14 +02:00
|
|
|
console.log('offline because whoami failed.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-20 14:57:20 +02:00
|
|
|
* Sets the offline flag, because there is no connection to the server.
|
2018-10-26 10:23:14 +02:00
|
|
|
*/
|
|
|
|
public goOfflineBecauseConnectionLost(): void {
|
2019-08-20 14:57:20 +02:00
|
|
|
this.offline.next(true);
|
2018-10-26 10:23:14 +02:00
|
|
|
console.log('offline because connection lost.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-20 14:57:20 +02:00
|
|
|
* Function to return to online-status.
|
2018-10-26 10:23:14 +02:00
|
|
|
*/
|
|
|
|
public goOnline(): void {
|
2019-08-20 14:57:20 +02:00
|
|
|
this.offline.next(false);
|
2018-10-26 10:23:14 +02:00
|
|
|
}
|
|
|
|
}
|