rpc

The Remote Procedure Call module for communicating with other WebViews. You can perform these operations as part of a WebView object.

Members

enable


Indicates whether to allow RPC events on the WebView. A value of true indicates to allow RPC events to be used in the WebView, false indicates otherwise.

Example

webview.rpc.enable = true;

Methods

emit(eventName, args, options)


Emits a RPC event for the WebView.

Parameters:

Name Type Description
eventName String The name of the event to emit.
args Object An array of arguments to pass to the event listeners.
options Object The options to pass.

Example

webview.rpc.emit("message", ["Hello", "World"], {sync:true});

on(eventName, callback)


Listens for RPC events on the specified WebView

Parameters:

Name Type Description
eventName String The event name to start listening for.
callback callback The callback function to call when the eventName is received.

Example

webview.rpc.on("message", function (options, message) ) {
    if (options.webviewId === 3) {
        console.log(message);
    }
});

once(eventName, callback)


Listens for a certain RPC event on the WebView only once.

Parameters:

Name Type Description
eventName String The event name to start listening for.
callback callback The callback function to call when the eventName is received.

Example

webview.rpc.once("message", function (options, message) {
    if (options.webviewId === 3) {
        console.log(message);
    }
});

postMessage(messageType, message, optionsopt) → {Object}


Sends a message to the JavaScript context of the specified WebView.

Parameters:

Name Type Attributes Description
messageType String The type of message to send.
message Object The message to send as a string or JSON-formatted object.
options Object <optional>
The RPC options.

Returns:

Error An object containing error information if an error occurrs.
Type
Object

Example

webview.rpc.postMessage("message", "Hello");
webview.rpc.postMessage("error", "Error message");

un(eventName, callback)


Indicates to stop listening for certain RPC events on the WebView.

Parameters:

Name Type Description
eventName String The event name to stop listening for.
callback callback The callback function to stop calling when the eventName is received.

Example

// Start listening for the event called message
webview.rpc.on("message", myCallbackFunction);
// Stop listening for the event called message
webview.rpc.un("message", myCallbackFunction);