WebPageTextureProvider
ClassWebPageTextureProvider is the associated texture control that can be accessed from the texture.control property.
- Snapchat: not supported
- SPECS: fully supported
- Camera Kit Web: not supported
- Camera Kit Mobile: not supported
- SnapchatNot supported — Available on SPECS only
- SPECSFully supported
- Experimental API; it may change or be removed.
- Camera Kit WebNot supported — Available on SPECS only
- Camera Kit MobileNot supported — Available on SPECS only
Experimental
WebPageTextureProvider is the associated texture control that can be accessed from the texture.control property. This allows you to call functions such as loadUrl(“https://snap.com”) or to pass input events to.
Note: Most functionality will require the onReady event to have been called. Any calls before this event may cause an exception.
Index
Properties
Methods
Example
// Create the options
var resolution = new vec2(512, 512);
var options = RemoteServiceModule.createWebViewOptions(resolution);
const resolution = new vec2(512, 512)
const options = RemoteServiceModule.createWebViewOptions(resolution)
this.remoteServiceModule.createWebView(
options,
(texture: Asset.Texutre) => {
this.image.mainPass.baseTex = texture
this.webViewControl = texture.control
this.webViewControl.onReady.add(() => {
print("onReady")
this.webViewControl.loadUrl("https://snap.com")
})
},
(msg: string) => {
print(`Error: ${msg}`)
}
)
Extends
Properties
canGoBack
readonlycanGoBack:boolean
ExperimentalSPECS
Check if there is any back history on the web stack.
canGoForward
readonlycanGoForward:boolean
ExperimentalSPECS
Check if there is any forward history on the web stack.
onReady
readonlyonReady:event0<void>
ExperimentalSPECS
This event signals that the webview is ready for performing actions such as loadUrl, etc. This also is when the WebView should be visible on the Texture that was originally provided.
Methods
ensureLoaded()
ensureLoaded():
Promise<void>
Experimental
Returns a Promise that resolves once this Provider has finished loading its resource.
Returns
Promise<void>
Remarks
If the Provider is already loaded when ensureLoaded() is called, the returned Promise
resolves immediately. Otherwise it resolves once loading completes.
Completion is determined by the Provider's load status (see Provider.getLoadStatus). Some Providers only become loaded once supporting runtime data is available — for example, a Provider whose resource depends on tracking will not report loaded until the relevant tracking data has arrived — so the returned Promise stays pending until that data is produced.
This method is useful when Lens script needs to await a Provider before reading its data — for example, waiting for a remote-asset Provider to finish downloading before sampling it.
Since
Lens Scripting Version 370
Example
Fetch a Texture at runtime via RemoteMediaModule and wait for its Provider to finish loading before using it:
const internetModule = require("LensStudio:InternetModule");
const remoteMediaModule = require("LensStudio:RemoteMediaModule");
function loadImageTexture(url) {
const resource = internetModule.makeResourceFromUrl(url);
return new Promise((resolve, reject) => {
remoteMediaModule.loadResourceAsImageTexture(resource, resolve, reject);
});
}
const texture = await loadImageTexture("https://example.com/image.png");
// Wait until the fetched Texture's Provider has finished loading before using it.
await texture.control.ensureLoaded();
print("Texture ready, loadStatus: " + texture.control.getLoadStatus());
Inherited from
getAspect()
getAspect():
number
Experimental
Returns the texture's aspect ratio, which is calculated as width / height.
Returns
number
Inherited from
getHeight()
getHeight():
number
Experimental
Returns the height of the texture in pixels.
Returns
number
Inherited from
getLoadStatus()
getLoadStatus():
LoadStatus
Experimental
Returns
Inherited from
getTypeName()
staticgetTypeName():TypeName<WebPageTextureProvider>
ExperimentalSPECS
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<WebPageTextureProvider>
Overrides
getTypeName()
getTypeName():
string
Experimental
Returns the name of this object's type.
Returns
string
Inherited from
getUserAgent()
getUserAgent():
string
ExperimentalSPECS
Get the current user-agent for the webview.
Returns
string
getWidth()
getWidth():
number
Experimental
Returns the width of the texture in pixels.
Returns
number
Inherited from
goBack()
goBack():
void
ExperimentalSPECS
Navigate back in the web history.
Returns
void
goForward()
goForward():
void
ExperimentalSPECS
Navigate forward in the web history.
Returns
void
isOfType()
isOfType(
type):boolean
Experimental
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
Experimental
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
loadUrl()
loadUrl(
url):void
ExperimentalSPECS
Request a url to be loaded.
Parameters
| Parameter | Type |
|---|---|
url | string |
Returns
void
reload()
reload():
void
ExperimentalSPECS
Request the current page to be reloaded.
Returns
void
setUserAgent()
setUserAgent(
userAgent):void
ExperimentalSPECS
Set a custom user-agent for the webview.
Note: By default all webview’s will have the same user-agent set by the platform. This can be used to target Spectacles specific websites.
Parameters
| Parameter | Type |
|---|---|
userAgent | string |
Returns
void
stop()
stop():
void
ExperimentalSPECS
Request the current page loading to stop.
Note: Has no effect if the page is already loaded.
Note: Does not stop scripts on the webpage.
Returns
void
touch()
touch(
id,state,x,y):void
ExperimentalSPECS
Touch will allow the lens creator to pass input events from the Lens to the WebView.
- id: of the touch (in the case of multi-finger, etc), for continuous interactions it is required they share the same id.
- state: What type of action is preformed.
- x: the x coordinate of the touch, in WebView space (2d).
- y: the Y coordinate of the touch, in WebView space (2d).
Note: Using the WebView from the Asset Library will have already implemented this logic with SIK and Hand Tracking and Mobile Controller and it is not expected for creators to re-implement this handling unless they wish to provide further customization and options.
Parameters
| Parameter | Type |
|---|---|
id | number |
state | TouchState |
x | number |
y | number |
Returns
void
See also
RemoteServiceModule#createWebView