我正在使用“黄单”/双芯包,在我的单体2应用中(目前为14英寸)实行一次性的排位。 超过闲置时间,代码将用户排出。 单项探测和伐木功能已编入我的备份档案。
在编造单面值时,该法典完全有效。 然而,我想,我的背后可以想象的闲.时间。 因此, 我写了一门服务班,该班在申请负荷时从后台取值。 守则的其余部分与硬编码的闲置时间版本完全相同(但现在属于我服务订阅的订阅部分)。 然而,ng的订阅从来就没有火灾。 该法典如下:
constructor(
private router: Router,
private idle: Idle, cd: ChangeDetectorRef,
private authSvc: AuthService,
private sessionDataSvc: SessionDataService,
private countdownSvc: CountdownService
) {
// set idle parameters
this.sessionDataSvc.getSessionProperties().subscribe(( {data} ) => {
let session_timeout = data.sessionProperties.session_idle_timeout
// set the idle and timeout values
// let session_timeout = 30;
idle.setIdle(session_timeout) // how long can they be inactive before considered idle, in seconds
idle.setTimeout(this.TIMEOUT); // how long can they be idle before considered timed out, in seconds
idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); // provide sources that will "interrupt" aka provide events indicating the user is active
console.log("Setting idle timeout to " + session_timeout + " seconds")
// Some code snipped for brevity
// do something when the user has timed out
idle.onTimeout.subscribe(() => {
console.log("onTimeout called")
this.idleState = "TIMED_OUT"
this.authSvc.logout()
this.reset()
this.router.navigate([ login ], { queryParams: { reason: "Session Timeout. Please re-login" } });
});
// do something as the timeout countdown does its thing
});
console.log("Done with setting idle timeout")
});
}
reset()
{
// we ll call this method when we want to start/reset the idle process
// reset any component state and be sure to call idle.watch()
this.idle.watch();
this.idleState = "NOT_IDLE";
this.countdown = null;
this.lastPing = null;
}
值得注意的是,包裹有4种订阅方法,即IdleStart、IdleEnd、实时停战和停工。 我故意从上述法典中删除了头三个,以便在我的发言中作简短的发言,否则在法典中就存在。 这本书是作为青少年运作的。 日志信息正在显示日志信息
Setting idle timeout to 30 seconds
正在黄色记录中显示(如上面代码中其他标识信息,“设定闲置时间”。 但是,没有哪怕是哪怕是哪一subscription。
As I mentioned above, if I was to comment out the lines
this.sessionDataSvc.getSessionProperties().subscribe(( {data} ) => {
let session_timeout = data.sessionProperties.session_idle_timeout
and enable the line:
// let session_timeout = 30;
instead (this is the hard-coded case), the @ng-idle subscriptions work as designed and documented. So why are they not inside a service subscription?