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
Source
Properties
_uuid?
private
optional
_uuid:string
Source
currentActivity?
optional
currentActivity:Activity
Source
dataStores?
optional
dataStores:IDataStore
[]
Source
eventListeners
private
eventListeners:M2EventListener
<SessionEvent
|ActivityEvent
>[]
Source
initialized
private
initialized:boolean
=false
Source
options
options:
SessionOptions
Source
sessionDictionary
private
sessionDictionary:Map
<string
,SessionDictionaryValues
>
Source
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
uuid
get
uuid():string
set
uuid(value
):void
Parameters
• value: string
Returns
string
Source
Methods
activityResultsEventHandler()
private
activityResultsEventHandler(event
):void
Parameters
• event: ActivityResultsEvent
Returns
void
Source
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
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
addEventListener()
private
addEventListener<T
>(type
,callback
,options
?):void
Type parameters
• T extends SessionEvent
| ActivityEvent
Parameters
• type: SessionEventType
| M2EventType
• callback
• options?: CallbackOptions
Returns
void
Source
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
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
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
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
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
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
end()
end():
void
Declares the session ended and sends callback.
Returns
void
Source
fetchSharedFontData()
private
fetchSharedFontData(games
):Promise
<void
>[]
Parameters
• games: Game
[]
Returns
Promise
<void
>[]
Source
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
getFilenameFromUrl()
private
getFilenameFromUrl(url
):string
Returns the filename from a url.
Parameters
• url: string
url to parse
Returns
string
filename
Source
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
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
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
init()
init():
Promise
<void
>
Asynchronously initializes the m2c2kit engine and loads assets
Returns
Promise
<void
>
Deprecated
Use Session.initialize() instead.
Source
initialize()
initialize():
Promise
<void
>
Asynchronously initializes the m2c2kit engine and loads assets
Returns
Promise
<void
>
Source
initializeSharedCanvasKit()
private
initializeSharedCanvasKit(games
):Promise
<void
>[]
Parameters
• games: Game
[]
Returns
Promise
<void
>[]
Source
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
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
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
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
raiseEventOnListeners()
private
raiseEventOnListeners(event
,extra
?):void
Parameters
• event: SessionEvent
| ActivityEvent
• extra?: unknown
Returns
void
Source
sessionActivityCancelHandler()
private
sessionActivityCancelHandler(event
):Promise
<void
>
Parameters
• event: ActivityLifecycleEvent
Returns
Promise
<void
>
Source
sessionActivityEndHandler()
private
sessionActivityEndHandler(event
):Promise
<void
>
Parameters
• event: ActivityLifecycleEvent
Returns
Promise
<void
>
Source
sessionActivityLifecycleHandler()
private
sessionActivityLifecycleHandler(event
):Promise
<void
>
Parameters
• event: ActivityLifecycleEvent
Returns
Promise
<void
>
Source
sessionActivityStartHandler()
private
sessionActivityStartHandler(event
):Promise
<void
>
Parameters
• event: ActivityLifecycleEvent
Returns
Promise
<void
>
Source
start()
start():
Promise
<void
>
Starts the session and starts the first activity.
Returns
Promise
<void
>
Source
stop()
private
stop():void
Returns
void
Source
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.