Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
watchForDisconnect() {
var self = this;
// watch network for a disconnect
let disconnectSubscription = Network.onDisconnect().subscribe(() => {
console.log('network was disconnected :-(');
console.log('Firebase: Go Offline..');
self.sqliteService.resetDatabase();
self.dataService.goOffline();
self.events.publish('network:connected', false);
});
}
ngOnInit() {
this.connectSub = Network.onConnect().subscribe(() => this.ngZone.run(() => this.connected()));
this.disconnectSub = Network.onDisconnect().subscribe(() => this.ngZone.run(() => this.disconnected()));
this.settingsSrvc.get(Settings.BackendUrl).then((val) => {
if (!val) {
let registration = this.modalCtrl.create(RegistrationPage);
registration.onDidDismiss(data => {
if(!data){
navigator.app.exitApp();
}
Promise.all([
this.settingsSrvc.set(Settings.BackendUrl, data.baseUrl),
this.settingsSrvc.set(Settings.SecurityToken, data.deviceToken),
]).then(() => {this.continueInitialization();});
});
registration.present();
}
checkNetworkDisconnection() {
this.networkDisconnectSubscription = Network.onDisconnect().subscribe(() => {
this.events.publish('native:networkDisconnect', {networkDisconnect: true});
}, error => {
console.log('checkNetworkDisconnection Error: ', error);
})
}
private initDisconnectSubscription() {
this.disconnectSubscription = Network.onDisconnect().subscribe(() => {
this.networkCheckService.showNoNetworkAlert();
this.disconnectSubscription.unsubscribe();
});
}
}
this.platform.ready().then(()=> {
if (this.platform.is("ios") || this.platform.is("android")) {
this.logger.debug(`The platform is ios or android, setting up disconnectModal.`);
this.disconnectModal = Modal.create(DisconnectModal);
this.onDisconnect = Network.onDisconnect().subscribe(() => {
this.logger.debug(`Disconnected, show disconnectModal.`);
this.nav.present(this.disconnectModal, {animate: true});
});
this.onConnect = Network.onConnect().subscribe(() => {
this.logger.debug(`Connected, show disconnectModal.`);
this.disconnectModal.dismiss();
});
}
});
}