@kyuuseiryuu/ws-invoker
v1.0.4
Published
Downloads
1
Readme
ws-invoker
How to use?
Server
router.ws('/', (ws, request) => {
const sInvoker = new Invoker(ws as any);
sInvoker.handle<{ a: number, b: number }, number>('add', (param) => {
if (!param) return 0;
const { a, b } = param;
return a + b;
});
});
Client
const invoker = new Invoker();
const ws = new w3cwebsocket('ws://127.0.0.1:3030/ws');
invoker.setWebSocket(ws as any);
ws.onopen = () => {
invoker.invoke('add', {a: 1, b: -2}, result => {
expect(result).toBe(-1);
ws.close();
});
}