RemoteServiceModule
ClassProvides access to Snap authorized remote services.
- Available on all platforms
Index
Properties
Methods
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
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)
endpointDefines the Snap authorized remote service endpoint to which to establish the WebSocket connection.paramsDefines 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
| Parameter | Type |
|---|---|
endpoint | string |
params | any |
Returns
getTypeName()
staticgetTypeName():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
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
performApiRequest()
performApiRequest(
request,onApiResponse):void
Parameters
| Parameter | Type |
|---|---|
request | RemoteApiRequest |
onApiResponse | (response) => void |
Returns
void
Since
Lens Scripting Version 164
subscribeApiRequest()
subscribeApiRequest(
request,onApiResponse):string
Parameters
| Parameter | Type |
|---|---|
request | RemoteApiRequest |
onApiResponse | (response) => void |
Returns
string
Since
Lens Scripting Version 288