Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 746 Bytes

README.md

File metadata and controls

40 lines (30 loc) · 746 Bytes

rpc-lib

Two-way RPC over websocket. The main goal is to expose entire interfaces not individual methods.

Usage:

import * as rpc from 'rpc-lib';

socket server

export class ServerApi {
  add(a: number, b: number) {
    return a + b;
  }

  sub(a: number, b: number) {
    return a - b;
  }
}
const rh = new rpc.Host(socket);
rh.addEndpoint('server-api', new ServerApi());

socket client

  const rh = new rpc.Host(socket);

  const serverApi = rh.getEndpoint<ServerApi>('server-api');
  console.log('1 + 2 =', await serverApi.add(1, 2));
  console.log('1 - 2 =', await serverApi.sub(1, 2));
});