Skip to content

BaseSession

Class

The base class for all basemap sessions. This class implements the 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 and StaticBasemapTilesSession.

Implements

Constructors

constructor

Class Constructor
new BaseSession(paramsIBasemapSessionParams): BaseSession

Creates 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
ParameterTypeNotes
paramsIBasemapSessionParams

The parameters for the session.

Returns 
BaseSession

Events

Properties

PropertyTypeNotes
authenticationstring | IAuthenticationManager

The authentication manager or token used for the session. This can be an instance of ApiKeyManager, ArcGISIdentityManager, ApplicationCredentialsManager or a string token.

durationnumber

The duration of the session in seconds. This is used to determine how long the session will last when the session is refreshed.

endTimeDate

The end time of the session. This is the time returned from the API when the session will end.

expiresDate

The 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.

portalstring

The portal URL that the session is associated with. This generally is not used but exists to implement the IAuthenticationManager interface.

safetyMarginnumber

The safety margin in milliseconds. This subtracted from the BaseSession.endTime to get the BaseSession.expiration.

startSessionUrlstring

The URL used to start the session.

startTimeDate

The start time of the session. This is the time returned from the API when the session war started.

styleFamilyStyleFamily

The style family of the session. This is used to determine the type of basemap styles that are available.

tokenstring

The token for the session.

error(eError) => void

Event handler for when an error occurs during session management.

authentication

Class Property
authentication: string | IAuthenticationManager

The authentication manager or token used for the session. This can be an instance of ApiKeyManager, ArcGISIdentityManager, ApplicationCredentialsManager or a string token.

duration

Class Property
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

Class Property
endTime: Date

The end time of the session. This is the time returned from the API when the session will end.

expires

Class Property
expires: Date

The 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 Property
portal: string

The portal URL that the session is associated with. This generally is not used but exists to implement the IAuthenticationManager interface.

safetyMargin

Class Property
safetyMargin: number

The safety margin in milliseconds. This subtracted from the BaseSession.endTime to get the BaseSession.expiration.

startSessionUrl

Class Property
startSessionUrl: string

The URL used to start the session.

startTime

Class Property
startTime: Date

The start time of the session. This is the time returned from the API when the session war started.

styleFamily

Class Property
styleFamily: StyleFamily

The style family of the session. This is used to determine the type of basemap styles that are available.

token

Class Property
token: string

The token for the session.

error

static
Class Property
error: (eError) => void = ...

Event handler for when an error occurs during session management.

Type declaration
    function(eError): void

    Event handler for when an error occurs during session management.

    Parameters
    ParameterType
    eError
    Returns 
    void

Accessors

AccessorReturnsNotes
get autoRefresh()boolean

Indicates if the session is set to automatically refresh when it expires.

get canRefresh()boolean

Indicates if the session can be refreshed. This is always true for this basemap sessions.

get checkingExpirationTime()boolean

Indicates if the session is currently checking for expiration time.

get isExpired()boolean

Checks if the session is expired.

get millisecondsUntilExpiration()number

Returns the number of milliseconds until the session token is no longer valid. If the session is expired, it will return 0.

get secondsUntilExpiration()number

Returns the number of seconds until the session is no longer valid rounded down. If the session is expired, it will return 0.

autoRefresh

Class Accessor
get autoRefresh(): boolean

Indicates if the session is set to automatically refresh when it expires.

Returns 
boolean
  • Returns true if auto-refresh is enabled, otherwise false.

canRefresh

Class Accessor
get canRefresh(): boolean

Indicates if the session can be refreshed. This is always true for this basemap sessions.

Returns 
boolean
  • Always returns true.

checkingExpirationTime

Class Accessor
get checkingExpirationTime(): boolean

Indicates if the session is currently checking for expiration time.

Returns 
boolean
  • Returns true if the session is checking for expiration time, otherwise false.

isExpired

Class Accessor
get isExpired(): boolean

Checks if the session is expired.

Returns 
boolean

millisecondsUntilExpiration

Class Accessor
get millisecondsUntilExpiration(): number

Returns the number of milliseconds until the session token is no longer valid. If the session is expired, it will return 0.

Returns 
number

secondsUntilExpiration

Class Accessor
get secondsUntilExpiration(): number

Returns the number of seconds until the session is no longer valid rounded down. If the session is expired, it will return 0.

Returns 
number

Methods

MethodReturnsNotes
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 BaseSession.disableCheckingExpirationTime after calling this method.

disableCheckingExpirationTime()void

Stops checking the expiration time of the session. This will clear the interval that was set by BaseSession.startCheckingExpirationTime.

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 BaseSession.enableCheckingExpirationTime.

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 BasemapSession.off.

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(__namedParameters, SessionClass)Promise<T>

Starts a new session using the provided parameters and returns an instance of the session class.

destroy

Class Method
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.

Returns 
void

disableAutoRefresh

Class Method
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 BaseSession.disableCheckingExpirationTime after calling this method.

Returns 
void

disableCheckingExpirationTime

Class Method
disableCheckingExpirationTime(): void

Stops checking the expiration time of the session. This will clear the interval that was set by BaseSession.startCheckingExpirationTime.

Returns 
void

enableAutoRefresh

Class Method
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 BaseSession.enableCheckingExpirationTime.

Returns 
void

enableCheckingExpirationTime

Class Method
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.

Returns 
any

getToken

Class Method
getToken(): 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 Method
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.

Returns 
boolean
  • Returns true if the session is expired, otherwise false.

off

Class Method
off(event"refreshed", handler(e{ current: { endTime: Date; expires: Date; startTime: Date; token: string }; previous: { endTime: Date; expires: Date; startTime: Date; token: string } }) => void): void

A handler that will remove a listener from a given event.

Parameters
ParameterTypeNotes
event"refreshed"
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 
voidoff(event"expired", handler(e{ endTime: Date; expires: Date; startTime: Date; token: string }) => void): void
Parameters
ParameterType
event"expired"
handler(e{ endTime: Date; expires: Date; startTime: Date; token: string }) => void
Returns 
voidoff(event"error", handler(eError) => void): void
Parameters
ParameterType
event"error"
handler(eError) => void
Returns 
void

on

Class Method
on(event"refreshed", handler(e{ current: { endTime: Date; expires: Date; startTime: Date; token: string }; previous: { endTime: Date; expires: Date; startTime: Date; token: string } }) => void): void

A handler that listens for an eventName and returns custom handler.

Parameters
ParameterTypeNotes
event"refreshed"
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): void
Parameters
ParameterType
event"expired"
handler(e{ endTime: Date; expires: Date; startTime: Date; token: string }) => void
Returns 
voidon(event"error", handler(eError) => void): void
Parameters
ParameterType
event"error"
handler(eError) => void
Returns 
void

once

Class Method
once(event"refreshed", handler(e{ current: { endTime: Date; expires: Date; startTime: Date; token: string }; previous: { endTime: Date; expires: Date; startTime: Date; token: string } }) => void): void

A handler that listens for an event once and returns a custom handler. Events listened to with this method cannot be removed with BasemapSession.off.

Parameters
ParameterTypeNotes
event"refreshed"
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 
voidonce(event"expired", handler(e{ endTime: Date; expires: Date; startTime: Date; token: string }) => void): void
Parameters
ParameterType
event"expired"
handler(e{ endTime: Date; expires: Date; startTime: Date; token: string }) => void
Returns 
voidonce(event"error", handler(eError) => void): void
Parameters
ParameterType
event"error"
handler(eError) => void
Returns 
void

refreshCredentials

Class Method
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.

Returns 
Promise<BaseSession>

A promise that resolves to the current instance of the session.

startSession

static
Class Method
startSession(__namedParameters{ authentication: string | IAuthenticationManager; autoRefresh?: boolean; duration?: number; safetyMargin?: number; startSessionUrl?: string; styleFamily?: StyleFamily }, SessionClass(paramsIBasemapSessionParams) => T): Promise<T>

Starts a new session using the provided parameters and returns an instance of the session class.

Parameters
ParameterTypeNotes
__namedParameters{ authentication: string | IAuthenticationManager; autoRefresh?: boolean; duration?: number; safetyMargin?: number; startSessionUrl?: string; styleFamily?: StyleFamily }
SessionClass(paramsIBasemapSessionParams) => T

The class to use for the session.

Returns 
Promise<T>

A promise that resolves to an instance of the session class.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.