Skip to content

Module: session

Table of contents

Functions

Functions

gameplayStart

gameplayStart(): void

Tracks the start of a gameplay session, including resuming play after a break. Call whenever the player starts playing or resumes playing after a break (menu/loading/achievement screen, game paused, etc.).

Example

// Player closes in-game menu and resumes playing
Wortal.session.gameplayStart();

Returns

void


gameplayStop

gameplayStop(): void

Tracks the end of a gameplay session, including pausing play or opening a menu. Call on every game break (entering a menu, switching level, pausing the game, ...)

Example

// Player opens in-game menu
Wortal.session.gameplayStop();

Returns

void


getDevice

getDevice(): Device

Gets the device the player is using. This is useful for device specific code.

Example

const device = Wortal.session.getDevice();
console.log(device);

Returns

Device

Device the player is using.


getEntryPointAsync

getEntryPointAsync(): Promise<string>

Returns the entry point that the game was launched from.

Example

Wortal.session.getEntryPointAsync()
 .then(entryPoint => console.log(entryPoint));

Returns

Promise<string>

Promise that resolves with the name of the entry point from which the user started the game.

Throws

  • NOT_SUPPORTED
  • RETHROW_FROM_PLATFORM

getEntryPointData

getEntryPointData(): Record<string, unknown>

Returns any data object associated with the entry point that the game was launched from.

The contents of the object are developer-defined, and can occur from entry points on different platforms. This will return null for older mobile clients, as well as when there is no data associated with the particular entry point.

Example

const data = Wortal.session.getEntryPointData();
console.log(data.property);

Returns

Record<string, unknown>

Data about the entry point or an empty object if none exists.


getLocale

getLocale(): string

Gets the locale the player is using. This is useful for localizing your game.

Example

const lang = Wortal.session.getLocale();

Returns

string

Locale in BCP47 format.


getOrientation

getOrientation(): Orientation

Gets the orientation of the device the player is using. This is useful for determining how to display the game.

Example

const orientation = Wortal.session.getOrientation();
if (orientation === 'portrait') {
   // Render portrait mode.
}

Returns

Orientation

Orientation of the device the player is using.


getPlatform

getPlatform(): Platform

Gets the platform the game is running on. This is useful for platform specific code. For example, if you want to show a different social share asset on Facebook than on Link.

Example

const platform = Wortal.session.getPlatform();
console.log(platform);

Returns

Platform

Platform the game is running on.


getTrafficSource

getTrafficSource(): TrafficSource

Gets the traffic source info for the game. This is useful for tracking where players are coming from. For example, if you want to track where players are coming from for a specific campaign.

Example

const source = Wortal.session.getTrafficSource();
console.log(source['r_entrypoint']);
console.log(source['utm_source']);

Returns

TrafficSource

URL parameters attached to the game.


happyTime

happyTime(): void

The happyTimeAsync method can be called on various player achievements (beating a boss, reaching a high score, etc.). It makes the website celebrate (for example by launching some confetti). There is no need to call this when a level is completed, or an item is obtained.

Example

// Player defeats a boss
Wortal.session.happyTime();

Returns

void


onOrientationChange

onOrientationChange(callback): void

Assigns a callback to be invoked when the orientation of the device changes.

Example

Wortal.session.onOrientationChange(orientation => {
   if (orientation === 'portrait') {
     // Render portrait mode
   }
});

Parameters

Name Type Description
callback (orientation: Orientation) => void Callback to be invoked when the orientation of the device changes.

Returns

void


setSessionData

setSessionData(data): void

Sets the data associated with the individual gameplay session for the current context.

This function should be called whenever the game would like to update the current session data. This session data may be used to populate a variety of payloads, such as game play webhooks.

Example

Wortal.session.setSessionData({
    'high-score': 100,
    'current-level': 2,
});

Parameters

Name Type Description
data Record<string, unknown> An arbitrary data object, which must be less than or equal to 1000 characters when stringified.

Returns

void


switchGameAsync

switchGameAsync(gameID, data?): Promise<void>

Request to switch to another game. The API will reject if the switch fails - else, the client will load the new game.

Example

Wortal.session.switchGameAsync(
  '12345678',
  { referrer: 'game_switch', reward_coins: 30 });

Parameters

Name Type Description
gameID string ID of the game to switch to. The application must be a Wortal game.
data? object An optional data payload. This will be set as the entrypoint data for the game being switched to. Must be less than or equal to 1000 characters when stringified.

Returns

Promise<void>

Promise that resolves when the game has switched. If the game fails to switch, the promise will reject.

Throws

  • INVALID_PARAMS
  • USER_INPUT
  • PENDING_REQUEST
  • CLIENT_REQUIRES_UPDATE
  • NOT_SUPPORTED

isAudioEnabled

isAudioEnabled(): boolean

Returns whether the audio is enabled for the player.

Example

if(Wortal.session.isAudioEnabled()){
  // Do something
}

Returns

boolean

True if audio is enabled, false if it is disabled.


onAudioStatusChange

onAudioStatusChange(callback): void

Assigns a callback to be invoked when the audio status of the player changes.

Example

// Listen for changes in the audio status and adjust game audio accordingly
Wortal.session.onAudioStatusChange(isAudioEnabled => {
  // Example Scenario: 
  if (isAudioEnabled) {
    GameAudioManager.unmute();
  } 
  else {
    GameAudioManager.mute();
  }
});

Parameters

Name Type Description
callback (isAudioEnabled: boolean) => void Callback to be invoked when the audio status of the player changes.

Returns

void