You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// the static methods for event handlers are used to provide doc via typedoc and do not need to be tested.
57
59
/* istanbul ignore next -- @preserve */
58
60
/**
59
-
* Event handler for when a session expires and the `token` it no longer valid.
61
+
* Event handler for when the current session expires and the session token it no longer valid. This event will only fire if {@linkcode BaseSession.checkingExpirationTime}
62
+
* is `true` which is the default. Once this event fires, {@linkcode BaseSession.checkingExpirationTime} will be set to `false` until the session is refreshed with
63
+
* {@linkcode BaseSession.refreshCredentials}.
60
64
*
61
65
* @event expired
62
66
* @param e - The parameters for the expired event.
* Internal instance of [`mitt`](https://github.com/developit/mitt) used for event handlers. It is recommended to use {@linkcode BasemapSession.on}, {@linkcode BasemapSession.off} or {@linkcode BasemapSession.once} instead of `emitter.`
* Checks if the session is expired. If it is expired, it emits an "expired" event. The event will fire **before** the method returns true.
220
+
* Checks if the session is expired. If it is expired, it emits an "expired" event and disables expiration time checking. The event will fire **before** the method returns true.
212
221
*
213
222
* @returns {boolean} - Returns true if the session is expired, otherwise false.
214
223
*/
215
224
isSessionExpired(){
216
225
if(this.isExpired){
226
+
this.disableCheckingExpirationTime();
227
+
217
228
this.emitter.emit("expired",{
218
229
token: this.token,
219
230
startTime: this.startTime,
220
231
endTime: this.endTime,
221
232
expires: this.expires
222
233
});
223
234
}
235
+
224
236
returnthis.isExpired;
225
237
}
226
238
227
239
/**
228
240
* Starts checking the expiration time of the session. This will check the expiration time immediately and then on an interval.
229
241
* If the session is expired, it will emit an "expired" event.
* Enables auto-refresh for the session. This will automatically refresh the session when it expires.
416
-
* It will also start checking the expiration time of the session if it is not already started via {@linkcode BaseSession.startCheckingExpirationTime}.
471
+
* It will also start checking the expiration time of the session if it is not already started via {@linkcode BaseSession.enableCheckingExpirationTime}.
* Disables auto-refresh for the session. This will stop automatically refreshing the session when it expires.
434
489
* This will **not** stop checking the expiration time of the session. If you want to stop automated expiration
435
-
* checking, call {@linkcode BaseSession.stopCheckingExpirationTime} after calling this method.
490
+
* checking, call {@linkcode BaseSession.disableCheckingExpirationTime} after calling this method.
436
491
*/
437
-
stopAutoRefresh(){
492
+
disableAutoRefresh(){
438
493
if(this.autoRefreshHandler){
439
494
this.off("expired",this.autoRefreshHandler);
440
495
this.autoRefreshHandler=null;
441
496
}
442
497
}
443
498
499
+
/**
500
+
* Removes all event listeners and disables auto-refresh and expiration time checking. This is useful for cleaning up the session when it is no longer needed or replaced with a new session.
501
+
*/
502
+
destroy(){
503
+
this.disableAutoRefresh();
504
+
this.disableCheckingExpirationTime();
505
+
this.emitter.off("expired");
506
+
this.emitter.off("refreshed");
507
+
this.emitter.off("error");
508
+
this.emitter.off("*");
509
+
}
510
+
444
511
/**
445
512
* A handler that listens for an eventName and returns custom handler.
0 commit comments