RPCs

WebView

Listen RPC Requests

Name Description
onRequest Listens to local RPCs.
onServerRequest Listens to server RPCs.
onPlayerRequest Listens to client RPCs.

Mango provides a set of methods to listen to RPC requests. These methods are available in the window.mango.rpc object after the mango object is initialized in the WebView.

onRequest

window.mango.rpc.onRequest('iWantDeliciousMango', (body: unknown) => {
    // ...
    return "Here's your mango from the webview!";
});
ts

onServerRequest

window.mango.rpc.onServerRequest('iWantDeliciousMango', (body: unknown) => {
    // ...
    return "Here's your mango from the webview!";
});
ts

onPlayerRequest

window.mango.rpc.onPlayerRequest('iWantDeliciousMango', (body: unknown) => {
    // ...
    return "Here's your mango from the webview!";
});
ts

Call RPC Requests

Name Description
call Calls local RPC handler and waits for response.
callServer Calls server RPC handler and waits for response.
callPlayer Calls client RPC handler and waits for response.

Mango provides a set of methods to send RPC requests. These methods are available in the window.mango.rpc object after the mango object is initialized in the WebView.

const body = { color: 'yellow', ripe: true };
ts

call

const result = await window.mango.rpc.call('iWantDeliciousMango', body);
ts

callServer

const result = await window.mango.rpc.callServer('iWantDeliciousMango', body);
ts

callPlayer

const result = await window.mango.rpc.callPlayer('iWantDeliciousMango', body);
ts
Last update at: 2024/06/18 19:03:08