Class: ContextApi

context.ContextApi

Context api wrapper class. Handles context ID and context players as well as sharing context specific messages.

Constructors

constructor

new ContextApi(client): ContextApi

Parameters

Name Type
client Client

Returns

ContextApi

Properties

client

Private client: Client


id

Private Optional id: string

Pre-initialized context ID for platforms that would require an async call to fetch the ID.


isImportantUpdateBuffered

Private isImportantUpdateBuffered: boolean


isSubGroupSupported

Private isSubGroupSupported: boolean

Indicates wether the user can start Zoom breakout rooms or not.


parentId

Private Optional parentId: string

Used by Zoom breakout rooms, where the parentId will be the parent meeting id.


type

Private Optional type: ContextApiType

Pre-initialized context type for platforms that would require an async call to fetch the type.

Methods

addToSubgroup

addToSubgroup(subGroupId): Promise<boolean>

Adds the calling player to the specified sub group. Only supports the Zoom platform at the moment.

Parameters

Name Type Description
subGroupId string The sub group id

Returns

Promise<boolean>


choose

choose(options?, analyticsId?): Promise<boolean>

Opens a context selection dialog for the player. If the player selects an available context, the client will attempt to switch into that context. If the context switch is succesful, or if the player is already in the specified context, the promise resolves with true. If the player cancels the operation the promise resolves with false.

Parameters

Name Type Description
options? ChooseOptions Optional conditions on the contexts that should be offered
analyticsId? string -

Returns

Promise<boolean>


closeAllSubGroups

closeAllSubGroups(): Promise<boolean>

Closes all open sub groups (Zoom meetings). Only supported by the Zoom platform at the moment.

Returns

Promise<boolean>


configureSubGroups

configureSubGroups(config): Promise<ConfigureSubGroupsConfig>

Configure sub groups, currently only supported by the Zoom platform.

Parameters

Name Type Description
config ConfigureSubGroupsConfig Allows you to specify the settings for the sub groups.

Returns

Promise<ConfigureSubGroupsConfig>


create

create(playerID, analyticsId?, message?): Promise<boolean>

Attempts to create or switch into a context between a specified player and the current player. If the context switch is succesful, or if the player is already in the specified context, the promise resolves with true. If the player cancels the operation the promise resolves with false.

Parameters

Name Type Default value Description
playerID string undefined The platform specific ID of the player
analyticsId? string undefined -
message string 'PLAY' to be sent to the target player (VK)

Returns

Promise<boolean>


createSubGroups

createSubGroups(subGroupsCount, subGroupNames?): Promise<SubGroups>

Create sub groups, currently only supported by the Zoom platform where creating a subgroup correspons to creating a breakout room. NOTE that only players that have the player.type as HOST can create sub groups.

Parameters

Name Type Description
subGroupsCount number The number of sub groups, 1-50 sub groups supported for Zoom
subGroupNames? string[] The sub groups names, must match the sub group count

Returns

Promise<SubGroups>


deleteSubGroup

deleteSubGroup(subGroupId): Promise<boolean>

Deletes the specified sub group. You can only delete a closed sub group. Only supports the Zoom platform at the moment.

Parameters

Name Type Description
subGroupId string The sub group id to delete. For Zoom it is the breakout room UUID.

Returns

Promise<boolean>


getID

getID(): null | string

A unique identifier for the current game context. This represents a specific context that the game is being played in, ie. a particular messenger conversation or facebook post or a Zoom meeting. The identifier will be null if game is being played in a solo context.

Returns

null | string


getIsSubGroupSupported

getIsSubGroupSupported(): boolean

Wether the current game context supports SUBGROUP or not. For Zoom it means that you can start breakout rooms.

Only supports the Zoom platform.

Returns

boolean


getParentID

getParentID(): null | string

The parent context unique identifier. Currently only supports the Zoom platform and is only available for the SUBGROUP type, that is when you are in a breakout room. Then returned parentID value will be the parent Zoom meeting unique identifier.

Returns

null | string


getPlayers

getPlayers(): Promise<Player[]>

Get a list of other players that are associated with the current context. This will never include the current player.

Returns

Promise<Player[]>


getType

getType(): "POST" | "THREAD" | ContextApiType

Get the type of the current game context.

For Zoom the SOLO context is used when the app is started from the main Zoom client whereas GROUP is used for the “in meeting” context. SUBGROUP is used if you are in a breakout room meeting.

Returns

"POST" | "THREAD" | ContextApiType


init

init(«destructured»): void

Parameters

Name Type
«destructured» ContextApiInitConfig

Returns

void


isSizeBetween

isSizeBetween(minSize, maxSize): null | ContextSizeResponse

Determine whether the number of participants in the current game context is between a given minimum and maximum, inclusive. If one of the bounds is null only the other bound will be checked against. It will always return the original result for the first call made in a context in a given game play session. Subsequent calls, regardless of arguments, will return the answer to the original query until a context change occurs and the query result is reset.

Parameters

Name Type Description
minSize number The minimum bound of the context size query
maxSize number The maximum bound of the context size query

Returns

null | ContextSizeResponse


isSupported

isSupported(): boolean

Check whether contexts are supported by the target platform.

Returns

boolean


listenToGroupConfigChanges

listenToGroupConfigChanges(eventHandler): void

Notifies about group config changes like BreakoutRoomsCreated, breakoutRoomOpened etc. Useful for the game to know when sub groups have been created for instance. Only supports the Zoom platform at the moment.

Parameters

Name Type Description
eventHandler (groupConfigChangeEvent: GroupConfigChangeEvent) => void The group config change event handler

Returns

void


listenToSubGroupsChanges

listenToSubGroupsChanges(eventHandler): void

Notifies about sub group changes when this player leaves or joins a sub group. Only supports the Zoom platform at the moment.

Parameters

Name Type Description
eventHandler (subGroupChangeEvent: SubGroupChangeEvent) => void The SubGroupChange event handler

Returns

void


log

log(event, parameters): void

Parameters

Name Type
event string
parameters Object

Returns

void


openSubGroups

openSubGroups(): Promise<void>

Opens any created sub groups (breakout rooms in Zoom). Only supports the Zoom platform at the moment.

Returns

Promise<void>


sendUpdate

sendUpdate(payload, priority?): Promise<void>

Send a context update to the active context.

If payload.strategy = ‘LAST’ then priority.important updates will override non-important updates. On FB ios only send priority.important = true messages as workaround to FB platform bug https://developers.facebook.com/support/bugs/1102036566983248/

Parameters

Name Type Description
payload UpdatePayload Contents of the update message
priority Object Message priority for choosing which message to send (only used in the LAST strategy)
priority.important boolean -

Returns

Promise<void>


switch

switch(id, analyticsId?, message?): Promise<boolean>

Request a switch into a specific context. If the switch is succesful, or if the player already is in the specified context, the promise resolves with true. If the player cancels the operation the promise resolves with false.

Parameters

Name Type Default value Description
id string undefined The ID of the desired context
analyticsId? string undefined -
message string 'PLAY' to be sent to the target player (VK)

Returns

Promise<boolean>