我使用了 Ng Idle 版本 6.0.0-beta.3 并使用 angular 6,这个库工作正常,系统开启,但是当系统进入睡眠模式时计时器停止。如何实现空闲状态是系统进入睡眠状态?
import {Idle, DEFAULT_INTERRUPTSOURCES} from '@ng-idle/core';
import {Keepalive} from '@ng-idle/keepalive';
constructor(
private idle: Idle, private keepalive: Keepalive) {
// sets an idle timeout of 5 seconds, for testing purposes.
idle.setIdle(900);
// sets a timeout period of 5 seconds. after 10 seconds of
inactivity, the user will be considered timed out.
idle.setTimeout(5);
// sets the default interrupts, in this case, things like clicks,
scrolls, touches to the document
idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
idle.onIdleEnd.subscribe(() => {this.idleState = 'No longer idle.'
console.log(this.idleState)
});
idle.onTimeout.subscribe(() => {
if(sessionStorage.getItem('loggedInTab') == 'true' ||
localStorage.getItem('loggedInStatus') == 'true'){
this.logoutService.logout().subscribe(res => {
console.log(res);
localStorage.clear();
this.router.navigate(['/']);
});
}
this.idleState = 'Timed out!';
this.timedOut = true;
});
idle.onIdleStart.subscribe(() => {this.idleState = 'You\'ve gone
idle!';
console.log(this.idleState);
});
idle.onTimeoutWarning.subscribe((countdown) => this.idleState = 'You
will time out in ' + countdown + ' seconds!');
// sets the ping interval to 15 seconds
keepalive.interval(15);
keepalive.onPing.subscribe(() => this.lastPing = new Date());
this.reset();
}
reset() {
this.idle.watch();
this.idleState = 'Started.';
this.timedOut = false;
}
ngOnDestroy() {
this.idle.stop();
}
我使用了 Ng Idle 版本 6.0.0-beta.3 并使用 angular 6,这个库工作正常,系统开启,但是当系统进入睡眠模式时计时器停止。如何实现空闲状态是系统进入睡眠状态?