ConnectedLensModule
ClassEnables the creation and management of networked Lens experiences, allowing for real-time communication and interaction between users through Connected Lenses.
- Available on all platforms
Index
Properties
Methods
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
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
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
| Parameter | Type |
|---|---|
sessionOptions | ConnectedLensSessionOptions |
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
| Parameter | Type |
|---|---|
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()
staticgetTypeName():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
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
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
| Parameter | Type |
|---|---|
sessionShareType | SessionShareType |
onSessionShared | (session, snapcode) => void |
Returns
void
Since
Lens Scripting Version 146
See also
Nested types
Namespaces
| Namespace | Description |
|---|---|
| TurnState | - |
Enumerations
| Enumeration | Description |
|---|---|
| MatchmakingAvailability | Whether matchmaking is available, and if not, why. |
| SessionShareType | Used by ConnectedLensModule to specify the session share type. |
Classes
| Class | Description |
|---|---|
| ConnectionInfo | Information that is bootstrapped to the user who just connected to the session. |
| HostUpdateInfo | Information about the host update. |
| MatchmakingConfig | Configuration for matchmaking when creating a session. If not set on session options, no matchmaking occurs (direct session join). |
| MultiplayerSupportInfo | Which multiplayer capabilities are available for the current Lens launch, from ConnectedLensModule#getMultiplayerSupportInfo. Currently reports matchmaking availability. |
| RealtimeStoreCreationInfo | Provides extra context about a RealtimeStore's creation. |
| RealtimeStoreDeleteInfo | Gives information about the Realtime Store delete operation. |
| RealtimeStoreKeyRemovalInfo | Provides information about a key being removed from a RealtimeStore. |
| RealtimeStoreOwnershipUpdateInfo | Provides information about a RealtimeStore's ownership being updated. |
| RealtimeStoreUpdateInfo | Gives information about the Realtime Store update operation. |
| UserInfo | Provides information about a user in a Connected Lens session. |