Skip to main content

Class: Session

Constructors

new Session()

new Session(options): Session

A Session contains one or more activities. The session manages the start and stop of activities, and advancement to next activity

Parameters

options: SessionOptions

Returns

Session

Source

session/src/Session.ts:41

Properties

_uuid?

private optional _uuid: string

Source

session/src/Session.ts:27


currentActivity?

optional currentActivity: Activity

Source

session/src/Session.ts:26


dataStores?

optional dataStores: IDataStore[]

Source

session/src/Session.ts:28


eventListeners

private eventListeners: M2EventListener<SessionEvent | ActivityEvent>[]

Source

session/src/Session.ts:29


initialized

private initialized: boolean = false

Source

session/src/Session.ts:33


options

options: SessionOptions

Source

session/src/Session.ts:25


sessionDictionary

private sessionDictionary: Map<string, SessionDictionaryValues>

Source

session/src/Session.ts:32

Accessors

nextActivity

get nextActivity(): undefined | Activity

Gets the next activity after the current one, or undefined if this is the last activity.

Returns

undefined | Activity

Source

session/src/Session.ts:672


uuid

get uuid(): string

set uuid(value): void

Parameters

value: string

Returns

string

Source

session/src/Session.ts:772

Methods

activityResultsEventHandler()

private activityResultsEventHandler(event): void

Parameters

event: ActivityResultsEvent

Returns

void

Source

session/src/Session.ts:229


activityUsesDeprecatedInit()

private activityUsesDeprecatedInit(activity): boolean

Check if the Activity uses the deprecated init() method.

Parameters

activity: Activity

Returns

boolean

true if the activity defines its own init() method, false otherwise.

Remarks

Activity.init() is deprecated and should be replaced with Activity.initialize().

Source

session/src/Session.ts:254


addDebuggingTools()

private addDebuggingTools(): void

Adds debugging tools to the session.

Returns

void

Remarks

These tools can be added by appending query parameters to the URL or by setting game parameters via the Game.SetParameters() method.

Source

session/src/Session.ts:57


addEventListener()

private addEventListener<T>(type, callback, options?): void

Type parameters

T extends SessionEvent | ActivityEvent

Parameters

type: SessionEventType | M2EventType

callback

options?: CallbackOptions

Returns

void

Source

session/src/Session.ts:134


advanceToNextActivity()

advanceToNextActivity(): Promise<void>

Stops the current activity and advances to next activity in the session. If there is no activity after the current activity, throws error.

Returns

Promise<void>

Deprecated

Use goToNextActivity() instead.

Source

session/src/Session.ts:664


dictionaryDeleteItem()

dictionaryDeleteItem(key): boolean

Deletes an item value from the session's key-value dictionary.

Parameters

key: string

item key

Returns

boolean

true if the item was deleted, false if it did not exist

Remarks

The session dictionary is not persisted. It is available only during the actively running session. It is useful for storing temporary data to coordinate between activities.

Source

session/src/Session.ts:724


dictionaryGetItem()

dictionaryGetItem<T>(key): T

Gets an item value from the session's key-value dictionary.

Type parameters

T extends SessionDictionaryValues

Parameters

key: string

item key

Returns

T

value of the item

Remarks

The session dictionary is not persisted. It is available only during the actively running session. It is useful for storing temporary data to coordinate between activities.

Source

session/src/Session.ts:710


dictionaryItemExists()

dictionaryItemExists(key): boolean

Determines if a key exists in the activity's key-value dictionary.

Parameters

key: string

item key

Returns

boolean

true if the key exists, false otherwise

Remarks

The session dictionary is not persisted. It is available only during the actively running session. It is useful for storing temporary data to coordinate between activities.

Source

session/src/Session.ts:738


dictionarySetItem()

dictionarySetItem(key, value): void

Saves an item to the session's key-value dictionary.

Parameters

key: string

item key

value: SessionDictionaryValues

item value

Returns

void

Remarks

The session dictionary is not persisted. It is available only during the actively running session. It is useful for storing temporary data to coordinate between activities.

Source

session/src/Session.ts:696


dispose()

private dispose(): void

Frees up resources that were allocated to run the session.

Returns

void

Remarks

This will be done automatically by the m2c2kit library; the end-user must not call this.

Source

session/src/Session.ts:545


end()

end(): void

Declares the session ended and sends callback.

Returns

void

Source

session/src/Session.ts:523


fetchSharedFontData()

private fetchSharedFontData(games): Promise<void>[]

Parameters

games: Game[]

Returns

Promise<void>[]

Source

session/src/Session.ts:428


getDuplicates()

private getDuplicates(s): string[]

Returns the duplicated strings in an array.

Parameters

s: string[]

array of strings

Returns

string[]

array of duplicated strings

Source

session/src/Session.ts:758


getFilenameFromUrl()

private getFilenameFromUrl(url): string

Returns the filename from a url.

Parameters

url: string

url to parse

Returns

string

filename

Source

session/src/Session.ts:748


getSharedAssets()

private getSharedAssets(activities): Promise<void>

Asynchronously loads fonts and wasm binaries that are common across two or more game activities and shares them with the games.

Parameters

activities: Activity[]

array of activities

Returns

Promise<void>

Source

session/src/Session.ts:374


goToActivity()

goToActivity(options): Promise<void>

Stops the current activity and goes to the activity with the provided id.

Parameters

options: GoToActivityOptions

Returns

Promise<void>

Source

session/src/Session.ts:554


goToNextActivity()

goToNextActivity(): Promise<void>

Stops the current activity and advances to next activity in the session. If there is no activity after the current activity, throws error.

Returns

Promise<void>

Source

session/src/Session.ts:644


init()

init(): Promise<void>

Asynchronously initializes the m2c2kit engine and loads assets

Returns

Promise<void>

Deprecated

Use Session.initialize() instead.

Source

session/src/Session.ts:238


initialize()

initialize(): Promise<void>

Asynchronously initializes the m2c2kit engine and loads assets

Returns

Promise<void>

Source

session/src/Session.ts:266


initializeSharedCanvasKit()

private initializeSharedCanvasKit(games): Promise<void>[]

Parameters

games: Game[]

Returns

Promise<void>[]

Source

session/src/Session.ts:393


onActivityData()

onActivityData(callback, options?): void

Executes a callback when any activity in the session generates data.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Source

session/src/Session.ts:127


onEnd()

onEnd(callback, options?): void

Executes a callback when the session ends.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Source

session/src/Session.ts:114


onInitialize()

onInitialize(callback, options?): void

Executes a callback when the session initializes.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Source

session/src/Session.ts:84


onStart()

onStart(callback, options?): void

Executes a callback when the session starts.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Source

session/src/Session.ts:101


raiseEventOnListeners()

private raiseEventOnListeners(event, extra?): void

Parameters

event: SessionEvent | ActivityEvent

extra?: unknown

Returns

void

Source

session/src/Session.ts:155


sessionActivityCancelHandler()

private sessionActivityCancelHandler(event): Promise<void>

Parameters

event: ActivityLifecycleEvent

Returns

Promise<void>

Source

session/src/Session.ts:179


sessionActivityEndHandler()

private sessionActivityEndHandler(event): Promise<void>

Parameters

event: ActivityLifecycleEvent

Returns

Promise<void>

Source

session/src/Session.ts:195


sessionActivityLifecycleHandler()

private sessionActivityLifecycleHandler(event): Promise<void>

Parameters

event: ActivityLifecycleEvent

Returns

Promise<void>

Source

session/src/Session.ts:210


sessionActivityStartHandler()

private sessionActivityStartHandler(event): Promise<void>

Parameters

event: ActivityLifecycleEvent

Returns

Promise<void>

Source

session/src/Session.ts:173


start()

start(): Promise<void>

Starts the session and starts the first activity.

Returns

Promise<void>

Source

session/src/Session.ts:500


stop()

private stop(): void

Returns

void

Source

session/src/Session.ts:535


waitForSessionInitialization()

private waitForSessionInitialization(): Promise<void>

Waits for the session to be initialized.

Returns

Promise<void>

Remarks

Session.initialize() is asynchronous, and it should be awaited so that the session is fully initialized before calling Session.start(). If it is not awaited (or it cannot be awaited because the target environment does not support top-level await), this function ensures that the session has been initialized.

Source

session/src/Session.ts:486