Websocket-RPC-Protocol
Client and server libraries for handling RPC calls between the browser and a Cloudflare websocket interface. The client
library will automatically try to reconnect after being disconnected from the server. For details on the protocol see
PROTOCOL.md.
Installation
npm install websocket-rpc-protocol
Server Usage
import server from 'websocket-rpc-protocol/server';
createServer(websocket, ({ push }) => {
let userState = {};
function privateFunction() {
}
function sayHi(name?: string) {
return `Hello ${name || 'world'}!`;
}
return {
sayHi
};
});
Client Usage
import createClient from 'websocket-rpc-protocol/client';
interface API {
sayHi(name?: string): Promise<string>;
}
const client = createClient<API>('wss://url-to-server');
await client.sayHi();
await client.sayHi('everyone');
client.get()