123456789101112131415161718192021222324252627282930313233343536 |
- import { RPCServer } from '../src/Backend'
- import { SubscriptionResponse } from '../src/Responses'
-
- let subcallback
-
- new RPCServer(20000, [{
- name: "HelloWorldRPCGroup",
- exportRPCs: () => [{
- type: 'Call',
- name: 'echo',
- call: async (s:string) => s,
- },
- {
- type: 'Hook',
- name: 'subscribe',
- hook: async (callback):Promise<any> => {
- subcallback = callback
- return new SubscriptionResponse(""+Math.random())
- },
- unhook: async (uid):Promise<any> => { subcallback = null }
- },
- function add(...args:number[]):number {return args.reduce((a,b)=>a+b, 0)},
- function triggerCallback(message):number {return subcallback(message)},
- ]
- }])
-
- try{
- new RPCServer(20001, [{
- name: "bad",
- exportRPCs: () => [
- (aaa,bbb,ccc) => { return aaa+bbb+ccc }
- ]
- }])
- }catch(badRPCError){
- console.log("expected bad-RPC error happened: "+ !!badRPCError)
- }
|