2018-10-26 10:23:14 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
2019-07-26 11:46:59 +02:00
|
|
|
|
2019-03-29 11:05:44 +01:00
|
|
|
import { WebsocketService } from './websocket.service';
|
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 whats happens here..
|
|
|
|
*/
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
2019-02-08 17:24:32 +01:00
|
|
|
export class OfflineService {
|
2018-10-26 10:23:14 +02:00
|
|
|
private _offline = false;
|
|
|
|
|
|
|
|
public get offline(): boolean {
|
|
|
|
return this._offline;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2019-03-29 11:05:44 +01:00
|
|
|
public constructor(private socketService: WebsocketService) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
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 {
|
2018-10-26 10:23:14 +02:00
|
|
|
this._offline = true;
|
|
|
|
console.log('offline because whoami failed.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: Should be somehow connected to the websocket service.
|
|
|
|
*/
|
|
|
|
public goOfflineBecauseConnectionLost(): void {
|
|
|
|
this._offline = true;
|
|
|
|
console.log('offline because connection lost.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: Should be somehow connected to the websocket service.
|
|
|
|
*/
|
|
|
|
public goOnline(): void {
|
|
|
|
this._offline = false;
|
|
|
|
}
|
|
|
|
}
|