Skip to main content

RemoteServiceModule

Class

Provides access to Snap authorized remote services.

  • 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

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

createAPIWebSocket()

createAPIWebSocket(endpoint, params): WebSocket

SPECS

The createWebAPISocket(endpoint, params) method initiates a WebSocket connection with the specified endpoint and the specified params to the Snap authorized remote services. Returns a WebSocket object that can be used to send and receive messages from the server.

Syntax

createAPIWebSocket(endpoint, params)
  • endpoint Defines the Snap authorized remote service endpoint to which to establish the WebSocket connection.
  • params Defines the parameters that will be used to establish the connection.

Example

//@input Asset.RemoteServiceModule remoteServiceModule
var remoteServiceModule = script.remoteServiceModule

// Create WebSocket connection.
let socket = script.remoteServiceModule.createAPIWebSocket("real_time", {"api-token" : "token", "api-example" : "realtime=v1", "model": "model"});

// Listen for the open event
socket.onopen = (event) => { print("Socket opened"); };

// Listen for messages
socket.onmessage = async (event) => { print("Socket message"); };

// Listen for the close event
socket.onclose = (event) => { print("Socket closed"); };

Parameters

ParameterType
endpointstring
paramsany

Returns

WebSocket


getTypeName()

static getTypeName(): TypeName<RemoteServiceModule>

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

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


performApiRequest()

performApiRequest(request, onApiResponse): void

Parameters

ParameterType
requestRemoteApiRequest
onApiResponse(response) => void

Returns

void

Since

Lens Scripting Version 164


subscribeApiRequest()

subscribeApiRequest(request, onApiResponse): string

Parameters

ParameterType
requestRemoteApiRequest
onApiResponse(response) => void

Returns

string

Since

Lens Scripting Version 288