angular - how to pevent ng2-idle instantiating multiple times with each successful login -
i have problem set idle display popup minute before session expiration. session times out or user logs out. next time user logs on, have 2 popups when there timeout. user logs out , in again , have 3 popups, , on. how destroy current instance of idle when user logs out?
my setup follows:
constructor(private idle: idle, ...) {} ngoninit() { this.setidle(); } private setidle() { // client activity timeout. 29 minutes 'idle', 1 minute beyond timeout this.ngzone.runoutsideangular(() => { // this.idle.setidle(29 * 60); // this.idle.settimeout(1 * 60); this.idle.setidle(10); this.idle.settimeout(10); this.idle.setinterrupts(default_interruptsources); }); this.idle.ontimeout.subscribe(() => { this.ngzone.run(() => { this.errordialogref.close(); sessionstorage.setitem('sessionexpired', 'true'); this.displayerrormodal(true); }); }); this.idle.onidlestart.subscribe(() => { this.ngzone.run(() => { this.displayidlewarning(); }); }); this.ngzone.runoutsideangular(() => { this.idle.watch(); }); }
during logout process, tried this.idle.stop()
, delete this.idle
. neither worked.
fyi: has run outside angular zone or else our protractor tests break.
update: until found solution of zeroing out arrays, did try:
this.idle.ontimeout.unsubscribe(); this.idle.onidlestart.unsubscribe(); this.idle.onidleend.unsubscribe();
but resulted in following error during subsequent login:
core.es5.js?0445:1084 error error: uncaught (in promise): objectunsubscribederror: object unsubscribed
it seems me component holding on references or not getting destroyed during logout.
i able inspect this.idle
object , discovered "do stuff" objects (ontimeout
, onidlestart
, onidleend
, oninterrupt
, , ontimeoutwarning
) eventemitters. , each of had object called observers
. observers
array of observer. each time new popup created, noticed array had increased. so, during logout process, cleared observers:
this.idle.stop(); this.idle.ontimeout.observers.length = 0; this.idle.onidlestart.observers.length = 0; this.idle.onidleend.observers.length = 0;
this may not best way. i'm sure there's better way delete observer eventemitter. couldn't find , quick , dirty way it.
Comments
Post a Comment