ws-bi-rpc
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

WS-BI-RPC

Bidirectional RPC based on WebSocket.

Easy to use

import { WebSocketServer,WebSocket ,WebSocketRPC } from "..";

class ServerHander {
    say(message: string) {
        console.log('message from client:', message)
    }
}
class ClientHander {
    test(message: string) {
        console.log('message from server :', message)
    }
}
const server = new WebSocketServer({ host: 'localhost', port: 8899 });
server.on('connection', async (socket) => {
    const rpc = new WebSocketRPC<ClientHander>(socket, new ServerHander);
    await rpc.call('test', 'hello');
});


const ws = new WebSocket('ws://localhost:8899');

ws.on('open', async () => {
    const client = new WebSocketRPC<ServerHander>(ws, new ClientHander);
    await client.call('say', 'say message');
})


// message from server : hello
// message from client: say message

Package Sidebar

Install

npm i ws-bi-rpc

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

23.8 kB

Total Files

10

Last publish

Collaborators

  • system233