Protected
constructorThe name of the Asset in Lens Studio.
Readonly
uniqueWearable Only
The createWebSocket() method initiates a WebSocket connection with the given wss
URL and returns a WebSocket object that can be used to send and receive messages from the server.
Syntax
createWebSocket(url)
url
Defines the wss
URL to which to establish the WebSocket connection.
Example
//@input Asset.RemoteServiceModule remoteServiceModule
var remoteServiceModule = script.remoteServiceModule;
// Create WebSocket connection.
let socket = script.remoteServiceModule.createWebSocket("wss://<some-url>");
socket.binaryType = "blob";
// Listen for the open event
socket.onopen = (event) => {
// Socket has opened, send a message back to the server
socket.send("Message 1");
// Try sending a binary message
// (the bytes below spell 'Message 2')
const message = [77, 101, 115, 115, 97, 103, 101, 32, 50];
const bytes = new Uint8Array(message);
socket.send(bytes);
};
// Listen for messages
socket.onmessage = async (event) => {
if (event.data instanceof Blob) {
// Binary frame, can be retrieved as either Uint8Array or string
let bytes = await event.data.bytes();
let text = await event.data.text();
print("Received binary message, printing as text: " + text);
} else {
// Text frame
let text = event.data;
print("Received text message: " + text);
}
});
socket.onclose = (event) => {
if (event.wasClean) {
print("Socket closed cleanly");
} else {
print("Socket closed with error, code: " + event.code);
}
};
socket.onerror = (event) => {
print("Socket error");
};
Experimental
Wearable Only
This function will create a new instance of a webview with the specified options. Once it has been created onSuccess will be invoked which returns the Texture instance of the WebView for rendering which contains a reference to WebPageTextureProvider through the Control
property. WebPageTextureProvider can be used for sending events and actions to the WebView. In the event of an error, the onError
callback is invoked with the error message.
Note: Only 1 callback will be invoked, and only once. Note: After creation, the webview will later invoke onReady on the WebPageTextureProvider.control object to indicate it is ready for handling events and actions.
Static
createExperimental
Wearable Only
This function creates a WebViewOptions instance that allows you to configure your webview.
Resolution:* vec2
type representing the desired webpage resolution.
Note: This is capped at 2048x2048. Note: Once a webview has been created this can not be changed.
Wearable Only
The fetch() method starts the process of fetching a resource from the internet, returning a promise that is fulfilled once the response is available.
The promise resolves to a Response object representing the response to your request.
A fetch() promise only rejects in cases of malformed URLs or network errors. A fetch() promise does not reject if the server responds with HTTP status codes that indicate errors. These errors can be checked manually via the Response status properties.
Syntax
fetch(resource)
fetch(resource, options)
resource
Defines the URL you wish to fetch, or a Request object.
options
Object containing any custom settings you want to apply to the request. Available options are body
, method
, headers
, redirect
, and keepalive
. For more information on these properties see the Request class. If a Request was given for resource
, then these options will entry-wise override the options specified in the Request object.
Example
//@input Asset.RemoteServiceModule remoteServiceModule
var remoteServiceModule = script.remoteServiceModule;
// For this example assume this URL simply responds with the same body
// that it receives.
let request = new Request("https://<Your URL>.com", {
method: "POST",
body: JSON.stringify({ user: { name: "user", career: "developer" }}),
headers: {
"Content-Type": "application/json",
},
});
let response = await remoteServiceModule.fetch(request, {
body: JSON.stringify({ user: { name: "user", career: "salesman" }})
});
if (response.status != 200) {
print("Failure: response not successful");
return;
}
let contentTypeHeader = response.headers.get("content-type");
if (!contentTypeHeader.includes("application/json")) {
print("Failure: wrong content type in response");
return;
}
let responseJson = await response.json();
let username = responseJson.json["user"]["name"];
let career = responseJson.json["user"]["career"];
print(career); // will print "salesman"
Optional
options: anyReturns the name of this object's type.
Returns true if the object matches or derives from the passed in type.
Returns true if this object is the same as other
. Useful for checking if two references point to the same thing.
Wearable Only
Camera Kit
Get a DynamicResource
to be used with RemoteMediaModule
from mediaUrl
.
Wearable Only
Camera Kit
Perform an http request described by RemoteServiceHttpRequest
.
Provides access to the remote services. For Spectacles, this module process access to the open internet.
Example
Loading an image:
Webview texture:
Webview texture in TypeScript: