Two-way RPC over websocket. The main goal is to expose entire interfaces not individual methods.
Usage:
import * as rpc from 'rpc-lib';
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());
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));
});