Skip to content

Commit

Permalink
Fix ServerProvider problems with zerconf breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fttx committed Apr 2, 2017
1 parent 8405273 commit ff1f125
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/pages/select-server/select-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class SelectServerPage {
});
alert.present();
}
}, 20 * 1000)
}, 60 * 1000)
} // scanForServers


Expand Down
16 changes: 9 additions & 7 deletions src/pages/welcome/welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ export class WelcomePage {
setTimeout(() => {
this.serverProvider.watchForServers().subscribe(data => {
let server = data.server;
if (this.connecting) {
this.serverProvider.unwatch();
this.settings.setDefaultServer(server);
this.slider.slideTo(this.slider.length() - 1);
this.ngZone.run(() => {
this.connecting = false;
this.showNext = false;
});
}

this.serverProvider.unwatch();
this.settings.setDefaultServer(server);
this.slider.slideTo(this.slider.length() - 1);
this.ngZone.run(() => {
this.connecting = false;
this.showNext = false;
});
});
}, 3000)

Expand Down
9 changes: 5 additions & 4 deletions src/providers/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class ServerProvider {
}
}

watchForServers() {
watchForServers(): Observable<any> {
return Observable.create(observer => {
if (typeof cordova == typeof undefined) { // for browser support
observer.next({ server: { address: 'localhost', name: 'localhost' }, action: 'added' });
Expand All @@ -131,9 +131,11 @@ export class ServerProvider {
var action = result.action;
var service = result.service;
// console.log("ACTION:", action, service);
if (service.port == Config.SERVER_PORT && service.addresses && service.addresses.length) {
if (service.port == Config.SERVER_PORT && service.ipv4Addresses && service.ipv4Addresses.length) {
this.NgZone.run(() => {
observer.next({ server: new ServerModel(service.addresses[0], service.server), action: action });
service.ipv4Addresses.forEach(ipv4 => {
observer.next({ server: new ServerModel(ipv4, service.hostname), action: action });
})
});
}
});
Expand All @@ -142,7 +144,6 @@ export class ServerProvider {

unwatch() {
if (typeof cordova != typeof undefined) {
cordova.plugins.zeroconf.unwatch('_http._tcp.', 'local.');
cordova.plugins.zeroconf.close();
}
}
Expand Down

0 comments on commit ff1f125

Please sign in to comment.