mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
add popup message
This commit is contained in:
@@ -15,38 +15,40 @@ export enum ConnectionStatus {
|
||||
})
|
||||
export class NetworkServiceService {
|
||||
private status: BehaviorSubject<ConnectionStatus> = new BehaviorSubject(ConnectionStatus.Offline);
|
||||
|
||||
|
||||
private wsCallbacks: {[key: string]: {
|
||||
function: Function,
|
||||
event: ConnectionStatus
|
||||
}} = {}
|
||||
|
||||
constructor(private network: Network, private toastController: ToastController, private plt: Platform) {
|
||||
this.plt.ready().then(() => {
|
||||
this.initializeNetworkEvents();
|
||||
let status = this.network.type !== 'none' ? ConnectionStatus.Online : ConnectionStatus.Offline;
|
||||
this.status.next(status);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
this.onNetworkChange().subscribe((status) => {
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
public initializeNetworkEvents() {
|
||||
|
||||
this.network.onDisconnect().subscribe(() => {
|
||||
if (this.status.getValue() === ConnectionStatus.Online) {
|
||||
this.updateNetworkStatus(ConnectionStatus.Offline);
|
||||
}
|
||||
});
|
||||
|
||||
this.network.onConnect().subscribe(() => {
|
||||
if (this.status.getValue() === ConnectionStatus.Offline) {
|
||||
this.updateNetworkStatus(ConnectionStatus.Online);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private async updateNetworkStatus(status: ConnectionStatus) {
|
||||
this.status.next(status);
|
||||
|
||||
|
||||
let connection = status == ConnectionStatus.Offline ? 'Offline' : 'Online';
|
||||
let toast = this.toastController.create({
|
||||
message: `You are now ${connection}`,
|
||||
@@ -55,11 +57,9 @@ export class NetworkServiceService {
|
||||
});
|
||||
toast.then(toast => toast.present());
|
||||
}
|
||||
|
||||
public onNetworkChange(): Observable<ConnectionStatus> {
|
||||
return this.status.asObservable();
|
||||
}
|
||||
|
||||
public getCurrentNetworkStatus(): ConnectionStatus {
|
||||
return this.status.getValue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user