Skip to main content

ConnectedLensSessionOptions

Class

Settings for configuring a Connected Lens session.

  • 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.

Index

Example

// @input Asset.ConnectedLensModule connectedLensModule
function createSession() {
var options = ConnectedLensSessionOptions.create();

options.onSessionCreated = onSessionCreated;
options.onConnected = onConnected;
options.onDisconnected = onDisconnected;
options.onMessageReceived = onMessageReceived;
options.onUserJoinedSession = onUserJoinedSession;
options.onUserLeftSession = onUserLeftSession;
options.onError = onError;

script.connectedLensModule.createSession(options);
}```

## Extends

- [`DirectMultiplayerSessionOptions`](./DirectMultiplayerSessionOptions.mdx)

## Properties

<a id="hostmanagementenabled" className="api-member api-member--property"></a>

### hostManagementEnabled

> **hostManagementEnabled**: `boolean`

Provides a single host for every session. Useful when an experience has a single authority. This should not be used in latency sensitive situations. The creator of the session will by default be the host. If the host leaves, thee server will determine a new host and transfer all ownership of entities owned by the original host. Use with `onHostUpdated` API to get a callback.

#### Default Value

```ts
false

Inherited from

DirectMultiplayerSessionOptions.hostManagementEnabled


matchmakingConfig

matchmakingConfig: MatchmakingConfig

Optional matchmaking configuration. If set, matchmaking will be enabled when creating a session.

Since

Lens Scripting Version 375

Default Value

null

Inherited from

DirectMultiplayerSessionOptions.matchmakingConfig


maxNumberOfInvitations

maxNumberOfInvitations: number

Defines maximum number of receipients that a user of connected lens can select while sharing a connected lens session via Invitation flow.

Since

Lens Scripting Version 158

Default Value

64

onConnected

onConnected: (session, connectionInfo) => void

Function to be called when a connection to the realtime backend is established. All realtime requests can be called after this callback. When you invite others to join, a new session will be created, hence you should update your session handler with the argument passed in this callback.

Parameters

ParameterType
sessionMultiplayerSession
connectionInfoConnectionInfo

Returns

void

Since

Lens Scripting Version 148

Inherited from

DirectMultiplayerSessionOptions.onConnected


onDisconnected

onDisconnected: (session, disconnectInfo) => void

Function to be called when the connection to the realtime backend is lost, either via successful disconnect or passive disconnect due to error.

Parameters

ParameterType
sessionMultiplayerSession
disconnectInfostring

Returns

void

Since

Lens Scripting Version 148

Inherited from

DirectMultiplayerSessionOptions.onDisconnected


onError

onError: (session, code, description) => void

Function to be called when an error occurs in the session life cycle.

Parameters

ParameterType
sessionMultiplayerSession
codestring
descriptionstring

Returns

void

Since

Lens Scripting Version 148

Inherited from

DirectMultiplayerSessionOptions.onError


onHostUpdated

onHostUpdated: (session, removalInfo) => void

Parameters

ParameterType
sessionMultiplayerSession
removalInfoHostUpdateInfo

Returns

void

Since

Lens Scripting Version 184

Default Value

null

Inherited from

DirectMultiplayerSessionOptions.onHostUpdated


onLobbyStateChanged

onLobbyStateChanged: (session, lobbyState) => void

Camera Kit

Function called on every participant when the server confirms the gate of an open-lobby session. The first confirmation can repeat the current state. A player who joins after the confirmation gets no call; read MultiplayerSession#getLobbyState in onConnected instead. Handling this is optional.

Parameters

ParameterType
sessionMultiplayerSession
lobbyStateLobbyState

Returns

void

Since

Lens Scripting Version 387

Example

options.onLobbyStateChanged = function (session, lobbyState) {
print("lobby state: " + lobbyState);
};

Inherited from

DirectMultiplayerSessionOptions.onLobbyStateChanged


onMessageReceived

onMessageReceived: (session, userId, message, senderInfo) => void

Function to be called when a string-based message sent by sendMessage() is received from another user via the realtime backend.

Parameters

ParameterType
sessionMultiplayerSession
userIdstring
messagestring
senderInfoUserInfo

Returns

void

Since

Lens Scripting Version 148

Inherited from

DirectMultiplayerSessionOptions.onMessageReceived


onRealtimeStoreCreated

onRealtimeStoreCreated: (session, store, ownerInfo, creationInfo) => void

Callback function that will be executed when a realtime store is created.

Parameters

ParameterType
sessionMultiplayerSession
storeGeneralDataStore
ownerInfoUserInfo
creationInfoRealtimeStoreCreationInfo

Returns

void

Since

Lens Scripting Version 173

Default Value

null

Inherited from

DirectMultiplayerSessionOptions.onRealtimeStoreCreated


onRealtimeStoreDeleted

onRealtimeStoreDeleted: (session, store, deleteInfo) => void

Callback function that will be executed when a realtime store is deleted.

Parameters

Returns

void

Since

Lens Scripting Version 173

Default Value

null

Inherited from

DirectMultiplayerSessionOptions.onRealtimeStoreDeleted


onRealtimeStoreKeyRemoved

onRealtimeStoreKeyRemoved: (session, removalInfo) => void

Function to be called when a key is removed from a RealtimeStore.

Parameters

ParameterType
sessionMultiplayerSession
removalInfoRealtimeStoreKeyRemovalInfo

Returns

void

Since

Lens Scripting Version 181

Default Value

null

Inherited from

DirectMultiplayerSessionOptions.onRealtimeStoreKeyRemoved


onRealtimeStoreOwnershipUpdated

onRealtimeStoreOwnershipUpdated: (session, store, ownerInfo, ownershipUpdateInfo) => void

Callback function that will be executed when ownership of a realtime store is updated.

Parameters

ParameterType
sessionMultiplayerSession
storeGeneralDataStore
ownerInfoUserInfo
ownershipUpdateInfoRealtimeStoreOwnershipUpdateInfo

Returns

void

Since

Lens Scripting Version 173

Default Value

null

Inherited from

DirectMultiplayerSessionOptions.onRealtimeStoreOwnershipUpdated


onRealtimeStoreUpdated

onRealtimeStoreUpdated: (session, store, key, updateInfo) => void

Callback function that will be executed when a realtime store is updated.

Parameters

ParameterType
sessionMultiplayerSession
storeGeneralDataStore
keystring
updateInfoRealtimeStoreUpdateInfo

Returns

void

Since

Lens Scripting Version 173

Default Value

null

Inherited from

DirectMultiplayerSessionOptions.onRealtimeStoreUpdated


onSessionCreated

onSessionCreated: (session, sessionCreationType) => void

Function called when the session is created. The session creation type in this callback can be used to tell if the session is being created from scratch, or is being received from another user.

Parameters

ParameterType
sessionMultiplayerSession
sessionCreationTypeSessionCreationType

Returns

void

Since

Lens Scripting Version 148

Default Value

null

onUserJoinedSession

onUserJoinedSession: (session, userInfo) => void

Function to be called when another user joins the session. When joining a session, the current user will get a callback for each of the existing active users in the current session. This way you can build a list of existing players in game.

Parameters

ParameterType
sessionMultiplayerSession
userInfoUserInfo

Returns

void

Since

Lens Scripting Version 148

Inherited from

DirectMultiplayerSessionOptions.onUserJoinedSession


onUserLeftSession

onUserLeftSession: (session, userInfo) => void

Function to be called when another user leaves the session, either deliberately or via passive disconnect due to error.

Parameters

ParameterType
sessionMultiplayerSession
userInfoUserInfo

Returns

void

Since

Lens Scripting Version 148

Inherited from

DirectMultiplayerSessionOptions.onUserLeftSession

Methods

create()

static create(): ConnectedLensSessionOptions

Create a new ConnectedLensesOptions object.

Returns

ConnectedLensSessionOptions

Since

Lens Scripting Version 148


getTypeName()

static getTypeName(): TypeName<ConnectedLensSessionOptions>

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<ConnectedLensSessionOptions>

Overrides

DirectMultiplayerSessionOptions.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

DirectMultiplayerSessionOptions.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

DirectMultiplayerSessionOptions.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

DirectMultiplayerSessionOptions.isSame

Nested types

Enumerations

EnumerationDescription
SessionCreationTypeType of the created Connected Lens session.