Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
watchForConnection() {
var self = this;
let connectSubscription = Network.onConnect().subscribe(() => {
console.log('network connected!');
// We just got a connection but we need to wait briefly
// before we determine the connection type. Might need to wait
// prior to doing any api requests as well.
setTimeout(() => {
console.log(Network.connection);
console.log('we got a connection..');
console.log('Firebase: Go Online..');
self.dataService.goOnline();
self.events.publish('network:connected', true);
}, 3000);
});
}
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();
checkNetworkConnection() {
this.networkConnectSubscription = Network.onConnect().subscribe(() => {
this.events.publish('native:networkConnect', Network.type);
}, error => {
console.log('checkNetworkConnection Error: ', error);
})
}
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();
});
}
});
}
initialize(mapElement: HTMLElement) {
this.isOnline = !this.onDevice || navigator.connection.type !== 'none';
this.mapElement = mapElement;
this.connectSub = Network.onConnect().subscribe(() => this.connected());
this.disconnectSub = Network.onConnect().subscribe(() => this.disconnected());
if (this.isOnline) {
this.getMapsKey().then(key => {
this.createMap(key);
});
}
else {
this.deferMapsCreation = true;
this.logger.info('deferring map creation');
}
}
private handleNetworkChanges() {
this.initDisconnectSubscription();
Network.onConnect().subscribe(() => {
this.initDisconnectSubscription();
setTimeout(() => {
this.queueService.processQueue();
}, 3000);
});
}