Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

devtest.ts 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { RPCServer } from "../src/Backend";
  2. import { SubscriptionResponse, RPCInterface } from "../src/Types";
  3. import { RPCSocket } from "../src/Frontend";
  4. import { makeSubResponse } from "../src/Utils";
  5. type SubresExtension = {a:string}
  6. type MyInterface = {
  7. Group1: {
  8. triggerCallbacks: (...args:any[]) => Promise<void>,
  9. subscribe: (param:string, callback:Function) => Promise<SubscriptionResponse<SubresExtension>>,
  10. unsubscribe: (uuid:string) => Promise<void>
  11. },
  12. Group2: {
  13. echo: (x:string) => Promise<string>
  14. }
  15. }
  16. new RPCServer<SubresExtension, MyInterface>(20000,
  17. [{
  18. name: 'Group1',
  19. exportRPCs: () => [{
  20. name: 'triggerCallbacks',
  21. call: async () => { /*...*/ }
  22. },{
  23. name: 'subscribe',
  24. hook: async (param, callback) => { return makeSubResponse<SubresExtension>({a: "test"}) }
  25. },{
  26. name: 'unsubscribe',
  27. call: async(uuid) => { }
  28. }
  29. ]
  30. },{
  31. name: 'Group2',
  32. exportRPCs: () => [{
  33. name: 'echo',
  34. call: async (x) => "..."
  35. }]
  36. }]
  37. )
  38. RPCSocket.makeSocket<MyInterface>(20000, 'localhost').then((async (client) => {
  39. console.log(client)
  40. const res = await client.Group1.subscribe('test', async (...args:any) => {
  41. console.log.apply(console, args)
  42. /* close the callbacks once you're done */
  43. await client.Group1.unsubscribe(res.uuid)
  44. client.unhook(res.uuid)
  45. })
  46. await client.Group1.triggerCallbacks("Hello", "World", "Callbacks")
  47. }))