import { switchMap, distinctUntilChanged } from 'rxjs/operators'; import { interval, of, Observable } from 'rxjs'; export class NetworkService { get isOnline(): Observable { return interval(10).pipe( switchMap(() => of(window.navigator.onLine)), distinctUntilChanged() ); } }