@@ -8,15 +8,11 @@ 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' ;
1514import { UserService } from './user.service' ;
1615
17- import debounce = require( 'lodash/debounce' ) ;
18-
19-
2016const DEFAULT_SESSION_REFRESH_INTERVAL = 60 ;
2117
2218@Injectable ( )
@@ -33,7 +29,6 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
3329
3430 constructor (
3531 protected asyncJobService : AsyncJobService ,
36- protected cacheService : CacheService ,
3732 protected configService : ConfigService ,
3833 protected storage : StorageService ,
3934 protected router : Router ,
@@ -43,33 +38,26 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
4338 ) {
4439 super ( ) ;
4540 this . loggedIn = new BehaviorSubject < boolean > ( ! ! this . userId ) ;
41+ }
4642
47- debounce ( this . refreshSession , 1000 , { leading : true } ) ;
48- debounce ( this . resetTimer , 1000 , { leading : true } ) ;
49-
43+ public startInactivityCounter ( ) {
5044 Observable . forkJoin (
5145 this . getInactivityTimeout ( ) ,
5246 this . getSessionRefreshInterval ( )
5347 )
5448 . subscribe ( ( [ inactivityTimeout , sessionRefreshInterval ] ) => {
5549 this . inactivityTimeout = inactivityTimeout ;
5650 this . sessionRefreshInterval = sessionRefreshInterval ;
57- this . resetTimer ( ) ;
51+ this . resetInactivityTimer ( ) ;
5852 this . addEventListeners ( ) ;
5953 } ) ;
60-
61- this . loggedIn . subscribe ( ( ) => {
62- this . asyncJobService . completeAllJobs ( ) ;
63- this . cacheService . invalidateAll ( ) ;
64- this . storage . resetInMemoryStorage ( ) ;
65- } ) ;
6654 }
6755
6856 public setInactivityTimeout ( value : number ) : Observable < void > {
6957 return this . userService . writeTag ( 'sessionTimeout' , value . toString ( ) )
7058 . map ( ( ) => {
7159 this . inactivityTimeout = value ;
72- this . resetTimer ( ) ;
60+ this . resetInactivityTimer ( ) ;
7361 } ) ;
7462 }
7563
@@ -174,7 +162,7 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
174162
175163 private refreshSession ( ) : void {
176164 if ( ++ this . numberOfRefreshes * this . sessionRefreshInterval >= this . inactivityTimeout * 60 ) {
177- this . clearTimer ( ) ;
165+ this . clearInactivityTimer ( ) ;
178166 this . zone . run ( ( ) => this . router . navigate ( [ '/logout' ] , this . routerUtilsService . getRedirectionQueryParams ( ) ) ) ;
179167 } else {
180168 this . sendRefreshRequest ( ) ;
@@ -185,23 +173,23 @@ export class AuthService extends BaseBackendService<BaseModelStub> {
185173 const events = 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll' . split ( ' ' ) ;
186174 const observables = events . map ( event => Observable . fromEvent ( document , event ) ) ;
187175 this . zone . runOutsideAngular ( ( ) => {
188- Observable . merge ( ...observables ) . subscribe ( ( ) => this . resetTimer ( ) ) ;
176+ Observable . merge ( ...observables ) . subscribe ( ( ) => this . resetInactivityTimer ( ) ) ;
189177 } ) ;
190178 }
191179
192- private resetTimer ( ) : void {
193- this . clearTimer ( ) ;
180+ private resetInactivityTimer ( ) : void {
181+ this . clearInactivityTimer ( ) ;
194182 this . numberOfRefreshes = 0 ;
195183 if ( this . inactivityTimeout ) {
196- this . setTimer ( ) ;
184+ this . setInactivityTimer ( ) ;
197185 }
198186 }
199187
200- private clearTimer ( ) : void {
188+ public clearInactivityTimer ( ) : void {
201189 clearInterval ( this . refreshTimer ) ;
202190 }
203191
204- private setTimer ( ) : void {
192+ private setInactivityTimer ( ) : void {
205193 if ( this . sessionRefreshInterval && this . inactivityTimeout ) {
206194 this . refreshTimer = setInterval ( this . refreshSession . bind ( this ) , this . sessionRefreshInterval * 1000 ) ;
207195 }
0 commit comments