@@ -8,7 +8,6 @@ import { BaseModelStub } from '../models';
88import { AsyncJobService } from './async-job.service' ;
99
1010import { BaseBackendService } from './base-backend.service' ;
11- import { CacheService } from './cache.service' ;
1211import { ConfigService } from './config.service' ;
1312import { RouterUtilsService } from './router-utils.service' ;
1413import { StorageService } from './storage.service' ;
@@ -33,7 +32,6 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
3332
3433 constructor (
3534 protected asyncJobService : AsyncJobService ,
36- protected cacheService : CacheService ,
3735 protected configService : ConfigService ,
3836 protected storage : StorageService ,
3937 protected router : Router ,
@@ -45,31 +43,27 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
4543 this . loggedIn = new BehaviorSubject < boolean > ( ! ! this . userId ) ;
4644
4745 debounce ( this . refreshSession , 1000 , { leading : true } ) ;
48- debounce ( this . resetTimer , 1000 , { leading : true } ) ;
46+ debounce ( this . resetInactivityTimer , 1000 , { leading : true } ) ;
47+ }
4948
49+ public startInactivityCounter ( ) {
5050 Observable . forkJoin (
5151 this . getInactivityTimeout ( ) ,
5252 this . getSessionRefreshInterval ( )
5353 )
5454 . subscribe ( ( [ inactivityTimeout , sessionRefreshInterval ] ) => {
5555 this . inactivityTimeout = inactivityTimeout ;
5656 this . sessionRefreshInterval = sessionRefreshInterval ;
57- this . resetTimer ( ) ;
57+ this . resetInactivityTimer ( ) ;
5858 this . addEventListeners ( ) ;
5959 } ) ;
60-
61- this . loggedIn . subscribe ( ( ) => {
62- this . asyncJobService . completeAllJobs ( ) ;
63- this . cacheService . invalidateAll ( ) ;
64- this . storage . resetInMemoryStorage ( ) ;
65- } ) ;
6660 }
6761
6862 public setInactivityTimeout ( value : number ) : Observable < void > {
6963 return this . userService . writeTag ( 'sessionTimeout' , value . toString ( ) )
7064 . map ( ( ) => {
7165 this . inactivityTimeout = value ;
72- this . resetTimer ( ) ;
66+ this . resetInactivityTimer ( ) ;
7367 } ) ;
7468 }
7569
@@ -174,7 +168,7 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
174168
175169 private refreshSession ( ) : void {
176170 if ( ++ this . numberOfRefreshes * this . sessionRefreshInterval >= this . inactivityTimeout * 60 ) {
177- this . clearTimer ( ) ;
171+ this . clearInactivityTimer ( ) ;
178172 this . zone . run ( ( ) => this . router . navigate ( [ '/logout' ] , this . routerUtilsService . getRedirectionQueryParams ( ) ) ) ;
179173 } else {
180174 this . sendRefreshRequest ( ) ;
@@ -185,23 +179,23 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
185179 const events = 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll' . split ( ' ' ) ;
186180 const observables = events . map ( event => Observable . fromEvent ( document , event ) ) ;
187181 this . zone . runOutsideAngular ( ( ) => {
188- Observable . merge ( ...observables ) . subscribe ( ( ) => this . resetTimer ( ) ) ;
182+ Observable . merge ( ...observables ) . subscribe ( ( ) => this . resetInactivityTimer ( ) ) ;
189183 } ) ;
190184 }
191185
192- private resetTimer ( ) : void {
193- this . clearTimer ( ) ;
186+ private resetInactivityTimer ( ) : void {
187+ this . clearInactivityTimer ( ) ;
194188 this . numberOfRefreshes = 0 ;
195189 if ( this . inactivityTimeout ) {
196- this . setTimer ( ) ;
190+ this . setInactivityTimer ( ) ;
197191 }
198192 }
199193
200- private clearTimer ( ) : void {
194+ public clearInactivityTimer ( ) : void {
201195 clearInterval ( this . refreshTimer ) ;
202196 }
203197
204- private setTimer ( ) : void {
198+ private setInactivityTimer ( ) : void {
205199 if ( this . sessionRefreshInterval && this . inactivityTimeout ) {
206200 this . refreshTimer = setInterval ( this . refreshSession . bind ( this ) , this . sessionRefreshInterval * 1000 ) ;
207201 }
0 commit comments