I want to know when my application goes offline and comes back online. I have the following events registered in rxjs
:
const online = Rx.Observable.fromEvent(window, 'online');
const offline = Rx.Observable.fromEvent(window, 'offline');
const source = Rx.Observable.combineLatest(online, offline).map(() => navigator.onLine);
source.subscribe(result => {
console.log('I\'m online: ' + (result ? 'jup' : 'nope'));
});
But, the first time I go offline the event isn't triggered allthough if I add the regular addEventListener
events I see they're getting triggered fine:
window.addEventListener('online', () => console.log('online triggered'));
window.addEventListener('offline', () => console.log('offline triggered'));
Take a look at this jsbin as example, switch of your netwerk via devtools and you'll see the first time it won't log I'm online: ...
.