UNPKG

ng-idle-observable-interrupt-source

Version:

An add-on for @ng-idle/core to use RxJS Observables as idle interrupt sources

47 lines (35 loc) 1.19 kB
# ng-idle-observable-interrupt-source An add-on for [@ng-idle/core](https://www.npmjs.com/package/@ng-idle/core) to use RxJS Observables as idle interrupt sources ## Installation ```sh npm install ng-idle-observable-interrupt-source ``` ## Usage ```typescript import ObservableInterruptSource from 'ng-idle-observable-interrupt-source'; import { Idle, DEFAULT_INTERRUPTSOURCES } from '@ng-idle/core'; import { Store } from '@ngrx/store'; const idleSeconds = 300; const logoutWarningSeconds = 30; export class SomeComponent implements OnInit, OnDestroy { constructor( private idle: Idle, store: Store, someService: SomeService, ) { this.idle.setIdle(idleSeconds); this.idle.onIdleStart(() => store.dispatch(showLogoutWarningDialog())); this.idle.setTimeout(logoutWarningSeconds); this.idle.onTimeout(() => store.dispatch(logout())); const someServiceInterruptSource = new ObservableInterruptSource(someService.observable$); this.idle.setInterrupts([...DEFAULT_INTERRUPTSOURCES, someServiceInterruptSource]); } ngOnInit() { this.idle.watch(); } ngOnDestroy() { this.idle.clearInterrupts(); this.idle.stop(); } } ```