Skip to main content

ConnectedLensModule

Class

Enables the creation and management of networked Lens experiences, allowing for real-time communication and interaction between users through Connected Lenses.

  • 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

Remarks

Allows use of networked Lens communication capabilities such as real-time communication, co-located session creation and joining, and shared persistent storage. It's recommended to only use one ConnectedLensModule per Lens.

Example

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

Properties

name

name: string

The name of the Asset in Lens Studio.

Default Value

""

Inherited from

Asset.name


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

createSession()

createSession(sessionOptions): void

Create session with the provided options. Will also check if there is a session that can be created from a session sharetype received from other users.

Parameters

ParameterType
sessionOptionsConnectedLensSessionOptions

Returns

void

Since

Lens Scripting Version 146


getMultiplayerSupportInfo()

getMultiplayerSupportInfo(onMultiplayerSupportInfo): void

Asks the host application which multiplayer capabilities are available for this Lens launch, before any session exists. The answer is fetched once and reused for the lifetime of this ConnectedLensModule.

Currently it reports matchmaking availability, so call this before ConnectedLensModule#createSession to decide whether to set ConnectedLensSessionOptions#matchmakingConfig — attaching a config the host cannot honour fails session creation with a MatchmakingRejectedByClient error instead. Treat any ConnectedLensModule.MatchmakingAvailability other than Supported as "create a direct session".

Parameters

ParameterType
onMultiplayerSupportInfo(multiplayerSupportInfo) => void

Returns

void

Since

Lens Scripting Version 375

Example

// @input Asset.ConnectedLensModule connectedLensModule

script.connectedLensModule.getMultiplayerSupportInfo(function (multiplayerSupportInfo) {
var options = ConnectedLensSessionOptions.create();
if (multiplayerSupportInfo.matchmakingAvailability ===
ConnectedLensModule.MatchmakingAvailability.Supported) {
options.matchmakingConfig = ConnectedLensModule.MatchmakingConfig.create(1, 4);
}
options.onSessionCreated = onSessionCreated;
options.onError = onError;
script.connectedLensModule.createSession(options);
});

getTypeName()

static getTypeName(): TypeName<ConnectedLensModule>

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

Overrides

Asset.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

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

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

Asset.isSame


leaveSession()

leaveSession(session?): void

Leaves the active Connected Lenses session for the local user. The session's onDisconnected callback fires once for the local user. Other participants will remain in the session. After leaving, the MultiplayerSession object can no longer be used — create a new one with ConnectedLensModule#createSession, for example to start a fresh session when you are the last remaining participant.

Parameters

ParameterType
session?MultiplayerSession

Returns

void

Since

Lens Scripting Version 370

Example

script.connectedLensModule.leaveSession(session);

shareSession()

shareSession(sessionShareType, onSessionShared): void

Share the session with other users, specified by the SessionShareType. Note that if shared via Invitation, a new session will be created. Expect a new onConnected callback with the new session being passed in.

Parameters

ParameterType
sessionShareTypeSessionShareType
onSessionShared(session, snapcode) => void

Returns

void

Since

Lens Scripting Version 146

See also

Connected Lenses Overview.

Nested types

Namespaces

NamespaceDescription
TurnState-

Enumerations

EnumerationDescription
MatchmakingAvailabilityWhether matchmaking is available, and if not, why.
SessionShareTypeUsed by ConnectedLensModule to specify the session share type.

Classes

ClassDescription
ConnectionInfoInformation that is bootstrapped to the user who just connected to the session.
HostUpdateInfoInformation about the host update.
MatchmakingConfigConfiguration for matchmaking when creating a session. If not set on session options, no matchmaking occurs (direct session join).
MultiplayerSupportInfoWhich multiplayer capabilities are available for the current Lens launch, from ConnectedLensModule#getMultiplayerSupportInfo. Currently reports matchmaking availability.
RealtimeStoreCreationInfoProvides extra context about a RealtimeStore's creation.
RealtimeStoreDeleteInfoGives information about the Realtime Store delete operation.
RealtimeStoreKeyRemovalInfoProvides information about a key being removed from a RealtimeStore.
RealtimeStoreOwnershipUpdateInfoProvides information about a RealtimeStore's ownership being updated.
RealtimeStoreUpdateInfoGives information about the Realtime Store update operation.
UserInfoProvides information about a user in a Connected Lens session.