Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TestBackend.ts 977B

123456789101112131415161718192021222324252627282930313233343536
  1. import { RPCServer } from '../src/Backend'
  2. import { SubscriptionResponse } from '../src/Responses'
  3. let subcallback
  4. new RPCServer(20000, [{
  5. name: "HelloWorldRPCGroup",
  6. exportRPCs: () => [{
  7. type: 'Call',
  8. name: 'echo',
  9. call: async (s:string) => s,
  10. },
  11. {
  12. type: 'Hook',
  13. name: 'subscribe',
  14. hook: async (callback):Promise<any> => {
  15. subcallback = callback
  16. return new SubscriptionResponse(""+Math.random())
  17. },
  18. unhook: async (uid):Promise<any> => { subcallback = null }
  19. },
  20. function add(...args:number[]):number {return args.reduce((a,b)=>a+b, 0)},
  21. function triggerCallback(message):number {return subcallback(message)},
  22. ]
  23. }])
  24. try{
  25. new RPCServer(20001, [{
  26. name: "bad",
  27. exportRPCs: () => [
  28. (aaa,bbb,ccc) => { return aaa+bbb+ccc }
  29. ]
  30. }])
  31. }catch(badRPCError){
  32. console.log("expected bad-RPC error happened: "+ !!badRPCError)
  33. }