Skip to main content

MultiplayerSession

Class

An instance of a Connected Lens session among a group of participants who were successfully invited into the experience.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v148

Index

Extends

Properties

activeUserCount

readonly activeUserCount: number

Get the number of active users in the Session.

Since

Lens Scripting Version 176


activeUsersInfo

readonly activeUsersInfo: UserInfo[]

Since

Lens Scripting Version 148


allRealtimeStores

readonly allRealtimeStores: GeneralDataStore[]

Get all the Realtime Stores in the current session.

Since

Lens Scripting Version 148

Methods

clearRealtimeStoreOwnership()

clearRealtimeStoreOwnership(store, onSuccess, onError): void

Sets the realtime store to unowned.

Parameters

ParameterType
storeGeneralDataStore
onSuccess(store) => void
onError(message) => void

Returns

void

Since

Lens Scripting Version 173


createRealtimeStore()

createRealtimeStore(options, onSuccess, onError): void

Creates a realtime store to share data within a multiplayer session. The realtime store will allow you to pass data between multiple connected users in the same experience, such as: syncing the position of objects in the scene, syncing the current game score, etc.

Parameters

ParameterType
optionsRealtimeStoreCreateOptions
onSuccess(store) => void
onError(message) => void

Returns

void

Since

Lens Scripting Version 173


deleteRealtimeStore()

deleteRealtimeStore(store, onSuccess, onError): void

Deletes a realtime store.

Parameters

ParameterType
storeGeneralDataStore
onSuccess(store) => void
onError(message) => void

Returns

void

Since

Lens Scripting Version 173


getLobbyState()

getLobbyState(): LobbyState

Camera Kit

Returns the confirmed gate of an open-lobby session. It is Unset until the server confirms the gate.

Returns

LobbyState

Since

Lens Scripting Version 387

Example

var lobbyState = session.getLobbyState();

getLocalUserId()

getLocalUserId(localUserIdCallback): void

Parameters

ParameterType
localUserIdCallback(userId) => void

Returns

void

Since

Lens Scripting Version 148


getLocalUserInfo()

getLocalUserInfo(localUserInfoCallback): void

Gets information about the current user, which includes their display name and unique userID which can be used to identify them in session.

Parameters

ParameterType
localUserInfoCallback(userInfo) => void

Returns

void

Since

Lens Scripting Version 173


getRealtimeStoreInfo()

getRealtimeStoreInfo(store): RealtimeStoreCreationInfo

Returns information about the passed in RealtimeStore.

Parameters

ParameterType
storeGeneralDataStore

Returns

RealtimeStoreCreationInfo

Since

Lens Scripting Version 181


getSafeSnapchatUser()

getSafeSnapchatUser(userInfo, safeSnapchatUserCallback): void

Get the SafeUser for a user in the session. This returns only non-sensitive user info (userId, bitmojiInfo, name) suitable for Bitmoji rendering.

Parameters

ParameterType
userInfoUserInfo
safeSnapchatUserCallback(safeSnapchatUser) => void

Returns

void

Since

Lens Scripting Version 349


getServerTimestamp()

getServerTimestamp(): number

Returns a unix timestamp in milliseconds of the current time according to the server. Useful for synchronizing time-based game events across devices. -1 will be returned if session is not connected to the server.

Returns

number

Since

Lens Scripting Version 148


getSnapchatUser()

getSnapchatUser(userInfo, userCallback): void

SPECS

Get the User for a participant in the session.

Parameters

ParameterType
userInfoUserInfo
userCallback(user) => void

Returns

void

Since

Lens Scripting Version 148


getTypeName()

static getTypeName(): TypeName<MultiplayerSession>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<MultiplayerSession>

Since

Lens Scripting Version 148

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


requestRealtimeStoreOwnership()

requestRealtimeStoreOwnership(store, onSuccess, onError): void

Requests for ownership of the realtime store.

Parameters

ParameterType
storeGeneralDataStore
onSuccess(store) => void
onError(message) => void

Returns

void

Since

Lens Scripting Version 173


sendMessage()

sendMessage(message): void

Sends a string message via the realtime backend.

Parameters

ParameterType
messagestring

Returns

void

Since

Lens Scripting Version 148


sendMessageWithTimeout()

sendMessageWithTimeout(message, timeoutMs): void

Sends a string message with a timeout in milliseconds. Allows messages to be dropped from the outgoing message queue when they become too old. Useful to ensure the quick delivery of subsequent messages.

Parameters

ParameterType
messagestring
timeoutMsnumber

Returns

void

Since

Lens Scripting Version 148


setLobbyState()

setLobbyState(lobbyState): void

Camera Kit

Requests a gate state for an open-lobby session. The session needs host management (ConnectedLensSessionOptions#hostManagementEnabled), and only the current session host can call this; the server ignores requests from other players. The session must be an open lobby; in any other session nothing is sent. Every participant receives the confirmed state through ConnectedLensSessionOptions#onLobbyStateChanged.

Parameters

ParameterType
lobbyStateLobbyState

Returns

void

Since

Lens Scripting Version 387

Example

session.setLobbyState(ConnectedLensModule.MatchmakingConfig.LobbyState.Closed);