123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { RPCServer } from '../src/Backend'
- import { SubscriptionResponse, ErrorResponse, SuccessResponse } from '../src/Responses'
- import { HookRPC } from '../src/Types'
-
- let subcallback
-
- new RPCServer(20000, [{
- name: "HelloWorldRPCGroup",
- exportRPCs: () => [
- {
- name: 'echo',
- call: async (s:string) => s,
- },{
- name: 'simpleSubscribe',
- hook: async(callback) => {
- subcallback = callback
- return new SubscriptionResponse(""+Math.random())
- }
- },{
- name: 'subscribe',
- hook: async (callback):Promise<any> => {
- subcallback = callback
- return new SubscriptionResponse(""+Math.random())
- },
- onClose: (res:SubscriptionResponse, rpc:HookRPC) => {
- console.log("Specific close handler for", rpc.name, res)
- subcallback = null
- },
- onCallback: (...args) => { console.log.apply(console, args) }
- },
- function add(...args:number[]):number {return args.reduce((a,b)=>a+b, 0)},
- function triggerCallback(...messages:any[]):number {return subcallback.apply({}, messages)},
- ]
- }])
-
- try{
- new RPCServer(20001, [{
- name: "bad",
- exportRPCs: () => [
- (aaa,bbb,ccc) => { return aaa+bbb+ccc }
- ]
- }])
- }catch(badRPCError){
- console.log("expected bad-RPC error happened: "+ !!badRPCError, String(badRPCError))
- }
|