Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

devtest.ts 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. }))
  48. const srv = new RPCServer(30000, [{
  49. name: 'Group2',
  50. exportRPCs: () => [{
  51. name: 'echo',
  52. call: async (x) => x
  53. }]
  54. }], {
  55. sesame: 'open'
  56. })
  57. const s = new RPCSocket(30000, 'localhost')
  58. s.connect("open").then(async() => {
  59. s['Group2']['echo']('open', 'dfgfg').then(console.log)
  60. s['Group2']['echo']('dfgfg').then(console.log)
  61. s['Group2']['echo']('dfgfg').then(console.log)
  62. })