Class
The base class for all basemap sessions. This class implements the @esri/arcgis-rest-request!IAuthenticationManager interface and provides methods to start, refresh, and check the expiration of a session.
This is not intended to be used directly, but instead is extended by other classes such as BasemapStyleSession .
Implements
Constructors
constructor
Class ConstructorBaseSession(params: IBasemapSessionParams): BaseSessionCreates a new instance of the BaseSession class. Generally you should not create an instance of this class directly, but instead use the static methods to start a session or deserialize a session.
You may need to create an instance of this class directly if you are not using the built in deserialize method.
Parameters
| Parameter | Type | Notes |
|---|---|---|
params | IBasemapSessionParams | The parameters for the session. |
Returns
BaseSessionProperties
| Property | Type | Notes |
|---|---|---|
authentication | string | IAuthenticationManager | The authentication manager or token used for the session.
This can be an instance of |
duration | number | The duration of the session in seconds. This is used to determine how long the session will last when the session is refreshed. |
endTime | Date | The end time of the session. This is the time returned from the API when the session will end. |
expires | Date | The expiration date of the session. This is the |
portal | string | The portal URL that the session is associated with. This generally is not used but exists to implement the |
safetyMargin | number | The safety margin in milliseconds. This subtracted from the |
startSessionUrl | string | The URL used to start the session. |
startTime | Date | The start time of the session. This is the time returned from the API when the session war started. |
styleFamily | StyleFamily | The style family of the session. This is used to determine the type of basemap styles that are available. |
token | string | The token for the session. |
error | (e: Error) => void | Event handler for when an error occurs during session management. |
authentication
Class Propertyauthentication: string | IAuthenticationManagerThe authentication manager or token used for the session.
This can be an instance of @esri/arcgis-rest-request!ApiKeyManager , @esri/arcgis-rest-request!ArcGISIdentityManager , @esri/arcgis-rest-request!ApplicationCredentialsManager or a string token.
duration
Class Propertyduration: numberThe duration of the session in seconds. This is used to determine how long the session will last when the session is refreshed.
endTime
Class PropertyendTime: DateThe end time of the session. This is the time returned from the API when the session will end.
expires
Class Propertyexpires: DateThe expiration date of the session. This is the BaseSession.endTime minus the BaseSession.safetyMargin . This is used internally to determine if the session is expired.
portal
Class Propertyportal: stringThe portal URL that the session is associated with. This generally is not used but exists to implement the IAuthenticationManager interface.
safetyMargin
Class PropertysafetyMargin: numberThe safety margin in milliseconds. This subtracted from the BaseSession.endTime to get the expiration time of the session.
startTime
Class PropertystartTime: DateThe start time of the session. This is the time returned from the API when the session war started.
styleFamily
Class PropertystyleFamily: StyleFamilyThe style family of the session. This is used to determine the type of basemap styles that are available.
Accessors
| Accessor | Returns |
|---|---|
autoRefresh() | boolean |
canRefresh() | boolean |
checkingExpirationTime() | boolean |
isExpired() | boolean |
millisecondsUntilExpiration() | number |
secondsUntilExpiration() | number |
autoRefresh
Class AccessorautoRefresh(): booleanIndicates if the session is set to automatically refresh when it expires.
Returns
boolean- Returns true if auto-refresh is enabled, otherwise false.
canRefresh
Class AccessorcanRefresh(): booleanIndicates if the session can be refreshed. This is always true for this basemap sessions.
Returns
boolean- Always returns true.
checkingExpirationTime
Class AccessorcheckingExpirationTime(): booleanIndicates if the session is currently checking for expiration time.
Returns
boolean- Returns true if the session is checking for expiration time, otherwise false.
Methods
| Method | Returns | Notes |
|---|---|---|
destroy() | void | 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. |
disableAutoRefresh() | void | Disables auto-refresh for the session. This will stop automatically refreshing the session when it expires.
This will not stop checking the expiration time of the session. If you want to stop automated expiration
checking, call |
disableCheckingExpirationTime() | void | Stops checking the expiration time of the session. This will clear the |
enableAutoRefresh() | void | Enables auto-refresh for the session. This will automatically refresh the session when it expires.
It will also start checking the expiration time of the session if it is not already started via |
enableCheckingExpirationTime() | any | Starts checking the expiration time of the session. This will check the expiration time immediately and then on an interval. If the session is expired, it will emit an "expired" event. |
getToken() | Promise<string> | Gets the session token. If the session is expired, it will refresh the credentials and return the new token. |
isSessionExpired() | boolean | 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. |
off(event, handler) | void | A handler that will remove a listener from a given event. |
on(event, handler) | void | A handler that listens for an eventName and returns custom handler. |
once(event, handler) | void | A handler that listens for an event once and returns a custom handler. Events listened to with this method cannot be removed with |
refreshCredentials() | Promise<BaseSession> | Refreshes the session credentials by starting a new session. This will emit a "refreshed" event with the previous and current session details. |
startSession<T>(params, SessionClass) | Promise<T> | Starts a new session using the provided parameters and returns an instance of the session class. |
destroy
Class Methoddestroy(): voidRemoves 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.
Returns
voiddisableAutoRefresh
Class MethoddisableAutoRefresh(): voidDisables auto-refresh for the session. This will stop automatically refreshing the session when it expires.
This will not stop checking the expiration time of the session. If you want to stop automated expiration
checking, call BaseSession.disableCheckingExpirationTime after calling this method.
Returns
voiddisableCheckingExpirationTime
Class MethoddisableCheckingExpirationTime(): voidStops checking the expiration time of the session. This will clear the setInterval() that was started by BaseSession.enableCheckingExpirationTime .
Returns
voidenableAutoRefresh
Class MethodenableAutoRefresh(): voidEnables auto-refresh for the session. This will automatically refresh the session when it expires.
It will also start checking the expiration time of the session if it is not already started via BaseSession.enableCheckingExpirationTime .
Returns
voidenableCheckingExpirationTime
Class MethodenableCheckingExpirationTime(): anyStarts checking the expiration time of the session. This will check the expiration time immediately and then on an interval. If the session is expired, it will emit an "expired" event.
Returns
anygetToken
Class MethodgetToken(): Promise<string>Gets the session token. If the session is expired, it will refresh the credentials and return the new token.
Returns
Promise<string>A promise that resolves to the session token.
isSessionExpired
Class MethodisSessionExpired(): booleanChecks 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.
Returns
boolean- Returns true if the session is expired, otherwise false.
off
Class Methodoff(event: "refreshed", handler: (e: { current: { endTime: Date; expires: Date; startTime: Date; token: string }; previous: { endTime: Date; expires: Date; startTime: Date; token: string } }) => void): voidA handler that will remove a listener from a given event.
Parameters
| Parameter | Type | Notes |
|---|---|---|
event | "refreshed" | A string of what event to listen for. |
handler | (e: { current: { endTime: Date; expires: Date; startTime: Date; token: string }; previous: { endTime: Date; expires: Date; startTime: Date; token: string } }) => void | A function of what to do when event was called. |
Returns
voidoff(event: "expired", handler: (e: { endTime: Date; expires: Date; startTime: Date; token: string }) => void): voidA handler that will remove a listener from a given event.
Parameters
| Parameter | Type | Notes |
|---|---|---|
event | "expired" | A string of what event to listen for. |
handler | (e: { endTime: Date; expires: Date; startTime: Date; token: string }) => void | A function of what to do when event was called. |
Returns
voidoff(event: "error", handler: (e: Error) => void): voidA handler that will remove a listener from a given event.
Parameters
| Parameter | Type | Notes |
|---|---|---|
event | "error" | A string of what event to listen for. |
handler | (e: Error) => void | A function of what to do when event was called. |
Returns
voidon
Class Methodon(event: "refreshed", handler: (e: { current: { endTime: Date; expires: Date; startTime: Date; token: string }; previous: { endTime: Date; expires: Date; startTime: Date; token: string } }) => void): voidA handler that listens for an eventName and returns custom handler.
Parameters
| Parameter | Type | Notes |
|---|---|---|
event | "refreshed" | A string of what event to listen for. |
handler | (e: { current: { endTime: Date; expires: Date; startTime: Date; token: string }; previous: { endTime: Date; expires: Date; startTime: Date; token: string } }) => void | A function of what to do when eventName was called. |
Returns
voidon(event: "expired", handler: (e: { endTime: Date; expires: Date; startTime: Date; token: string }) => void): voidA handler that listens for an eventName and returns custom handler.
Parameters
| Parameter | Type | Notes |
|---|---|---|
event | "expired" | A string of what event to listen for. |
handler | (e: { endTime: Date; expires: Date; startTime: Date; token: string }) => void | A function of what to do when eventName was called. |
Returns
voidon(event: "error", handler: (e: Error) => void): voidA handler that listens for an eventName and returns custom handler.
Parameters
| Parameter | Type | Notes |
|---|---|---|
event | "error" | A string of what event to listen for. |
handler | (e: Error) => void | A function of what to do when eventName was called. |
Returns
voidonce
Class Methodonce(event: "refreshed", handler: (e: { current: { endTime: Date; expires: Date; startTime: Date; token: string }; previous: { endTime: Date; expires: Date; startTime: Date; token: string } }) => void): voidA handler that listens for an event once and returns a custom handler. Events listened to with this method cannot be removed with BaseSession.off .
Parameters
| Parameter | Type | Notes |
|---|---|---|
event | "refreshed" | A string of what event to listen for. |
handler | (e: { current: { endTime: Date; expires: Date; startTime: Date; token: string }; previous: { endTime: Date; expires: Date; startTime: Date; token: string } }) => void | A function of what to do when event was called. |
Returns
voidonce(event: "expired", handler: (e: { endTime: Date; expires: Date; startTime: Date; token: string }) => void): voidA handler that listens for an event once and returns a custom handler. Events listened to with this method cannot be removed with BaseSession.off .
Parameters
| Parameter | Type | Notes |
|---|---|---|
event | "expired" | A string of what event to listen for. |
handler | (e: { endTime: Date; expires: Date; startTime: Date; token: string }) => void | A function of what to do when event was called. |
Returns
voidonce(event: "error", handler: (e: Error) => void): voidA handler that listens for an event once and returns a custom handler. Events listened to with this method cannot be removed with BaseSession.off .
Parameters
| Parameter | Type | Notes |
|---|---|---|
event | "error" | A string of what event to listen for. |
handler | (e: Error) => void | A function of what to do when event was called. |
Returns
voidrefreshCredentials
Class MethodrefreshCredentials(): Promise<BaseSession>Refreshes the session credentials by starting a new session. This will emit a "refreshed" event with the previous and current session details.
Returns
Promise<BaseSession>A promise that resolves to the current instance of the session.
startSession
startSession<T>(params: { authentication: string | IAuthenticationManager; autoRefresh?: boolean; duration?: number; safetyMargin?: number; startSessionUrl?: string; styleFamily?: StyleFamily }, SessionClass: (params: IBasemapSessionParams) => T): Promise<T>Starts a new session using the provided parameters and returns an instance of the session class.
Type Parameters
| Parameter | Type |
|---|---|
T | BaseSession |
Parameters
| Parameter | Type | Notes |
|---|---|---|
params | { authentication: string | IAuthenticationManager; autoRefresh?: boolean; duration?: number; safetyMargin?: number; startSessionUrl?: string; styleFamily?: StyleFamily } | The parameters for starting the session. |
Session | (params: IBasemapSessionParams) => T | The class to use for the session. |
Returns
Promise<T>A promise that resolves to an instance of the session class.