Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 628 Bytes

README.md

File metadata and controls

25 lines (22 loc) · 628 Bytes

jsonrpc.js

Provides RPC functionality over WebSockets using the JSON-RPC protocol.

Example

const socket = new WebSocket('wss://www.example.com/rpc');
const rpc = new JSONRPC(socket);
// ...
rpc.call('greet', { name: 'Alice' }).then(function(response) {
    console.log("Success!", response);
}).catch(function(error) {
    console.log("Failed!", error);
});

Send a RPC notification (does not get a response).

rpc.notify('greet', { name: 'Alice' });

Error listeners

rpc.onerror = (error) => console.error(error);
rpc.onResponseError = (error) => console.warn(error);