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

Defined in​

m2c2kit/packages/session/src/Session.ts:45

Properties​

currentActivity?​

optional currentActivity: Activity

Defined in​

m2c2kit/packages/session/src/Session.ts:29


dataStores?​

optional dataStores: IDataStore[]

Defined in​

m2c2kit/packages/session/src/Session.ts:31


options​

options: SessionOptions

Defined in​

m2c2kit/packages/session/src/Session.ts:28

Accessors​

nextActivity​

Get Signature​

get nextActivity(): undefined | Activity

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

Returns​

undefined | Activity

Defined in​

m2c2kit/packages/session/src/Session.ts:750


uuid​

Get Signature​

get uuid(): string

Returns​

string

Set Signature​

set uuid(value): void

Parameters​

• value: string

Returns​

void

Defined in​

m2c2kit/packages/session/src/Session.ts:850

Methods​

addStaticDiagnosticData()​

addStaticDiagnosticData(key, value): void

Sets the value of a variable that will be the same for all diagnostic data.

Parameters​

• key: string

key (variable name) for the static diagnostic data

• value: undefined | null | string | number | boolean | object

value for the data

Returns​

void

Remarks​

This is useful for custom variables to appear in the diagnostic data. For example, you might save the subject's participant ID, or some other identifier that is not typically part of the diagnostic data. In the example below, if an exception occurs, the participant_id variable will be saved with the value 12345 within the diagnostic data.

Example​

session.addStaticDiagnosticData("participant_id", "12345");

Defined in​

m2c2kit/packages/session/src/Session.ts:884


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.

Defined in​

m2c2kit/packages/session/src/Session.ts:742


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.

Defined in​

m2c2kit/packages/session/src/Session.ts:802


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.

Defined in​

m2c2kit/packages/session/src/Session.ts:788


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.

Defined in​

m2c2kit/packages/session/src/Session.ts:816


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.

Defined in​

m2c2kit/packages/session/src/Session.ts:774


end()​

end(): void

Declares the session ended and sends callback.

Returns​

void

Defined in​

m2c2kit/packages/session/src/Session.ts:594


goToActivity()​

goToActivity(options): Promise<void>

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

Parameters​

• options: GoToActivityOptions

Returns​

Promise<void>

Defined in​

m2c2kit/packages/session/src/Session.ts:630


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>

Defined in​

m2c2kit/packages/session/src/Session.ts:720


init()​

init(): Promise<void>

Asynchronously initializes the m2c2kit engine and loads assets

Returns​

Promise<void>

Deprecated​

Use Session.initialize() instead.

Defined in​

m2c2kit/packages/session/src/Session.ts:307


initialize()​

initialize(): Promise<void>

Asynchronously initializes the m2c2kit engine and loads assets

Returns​

Promise<void>

Defined in​

m2c2kit/packages/session/src/Session.ts:335


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

Defined in​

m2c2kit/packages/session/src/Session.ts:178


onData()​

onData(callback, options?): void

Executes a callback when the session generates data.

Parameters​

• callback

function to execute.

• options?: CallbackOptions

options for the callback.

Returns​

void

Remarks​

Currently, this is used only for capturing diagnostics data on exceptions.

Defined in​

m2c2kit/packages/session/src/Session.ts:165


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

Defined in​

m2c2kit/packages/session/src/Session.ts:149


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

Defined in​

m2c2kit/packages/session/src/Session.ts:119


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

Defined in​

m2c2kit/packages/session/src/Session.ts:136


start()​

start(): Promise<void>

Starts the session and starts the first activity.

Returns​

Promise<void>

Defined in​

m2c2kit/packages/session/src/Session.ts:571