Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
fix(idle): fix idle for protractor (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Shakhov authored Jan 15, 2019
1 parent 1909c1f commit 09e7734
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/app/root-store/idle-monitor/idle-monitor.effects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core';
import { Injectable, NgZone } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Action, select, Store } from '@ngrx/store';
import { Keepalive } from '@ng-idle/keepalive';
Expand Down Expand Up @@ -69,31 +69,38 @@ export class IdleEffects {
private store: Store<State>,
private authService: AuthService,
private tagService: TagService,
private ngZone: NgZone,
) {
this.setupPersistentIdleServiceParameters();
}

private startIdleMonitor(sessionTimeout: number, sessionRefreshInterval: number) {
this.idle.setIdle(sessionTimeout * 60);
// The Session Refresh Interval can't be moved to setupPersistentIdleServiceParameters() function
// because the ConfigService service will not have any config values when this service is initialized
this.keepalive.interval(sessionRefreshInterval);
this.ngZone.runOutsideAngular(() => {
this.idle.setIdle(sessionTimeout * 60);
// The Session Refresh Interval can't be moved to setupPersistentIdleServiceParameters() function
// because the ConfigService service will not have any config values when this service is initialized
this.keepalive.interval(sessionRefreshInterval);

this.idle.watch();
this.idle.watch();
});
}

private stopIdleMonitor() {
this.idle.stop();
this.ngZone.runOutsideAngular(() => {
this.idle.stop();
});
}

private setupPersistentIdleServiceParameters() {
this.idle.setTimeout(0);
this.idle.setAutoResume(2);
// Default interrupt source includes:
// mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll
this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
this.ngZone.runOutsideAngular(() => {
this.idle.setTimeout(0);
this.idle.setAutoResume(2);
// Default interrupt source includes:
// mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll
this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);

this.idle.onIdleStart.subscribe(() => this.store.dispatch(new IdleLogout()));
this.keepalive.onPing.subscribe(() => this.store.dispatch(new RefreshSessionRequest()));
this.idle.onIdleStart.subscribe(() => this.store.dispatch(new IdleLogout()));
this.keepalive.onPing.subscribe(() => this.store.dispatch(new RefreshSessionRequest()));
});
}
}

0 comments on commit 09e7734

Please sign in to comment.