ng-idle-observable-interrupt-source
v0.9.0
Published
An add-on for @ng-idle/core to use RxJS Observables as idle interrupt sources
Downloads
522
Maintainers
Readme
ng-idle-observable-interrupt-source
An add-on for @ng-idle/core to use RxJS Observables as idle interrupt sources
Installation
npm install ng-idle-observable-interrupt-source
Usage
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();
}
}