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.

TestFrontend.ts 1.4KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { RPCSocket } from '../src/Frontend'
  2. const client = new RPCSocket(20000, 'localhost')
  3. client.connect().then(async _ => {
  4. await client.info().then(console.log)
  5. await client["HelloWorldRPCGroup"].echo("x")
  6. .then(hopefullyX => console.log("echo('x') returned x: ", hopefullyX === "x", hopefullyX))
  7. await client["HelloWorldRPCGroup"].add(1,2,3)
  8. .then(hopefully6 => console.log("add(1,2,3) returned 6: ", hopefully6 === 6, hopefully6))
  9. let counter = 0
  10. const handler = (s) => {
  11. counter++
  12. if(counter === 3)
  13. console.log("subscribe call counter met", counter === 3)
  14. }
  15. await client["HelloWorldRPCGroup"].subscribe(handler)
  16. await Promise.all([
  17. client["HelloWorldRPCGroup"].triggerCallback("test1", "test1", "test1", ),
  18. client["HelloWorldRPCGroup"].triggerCallback("test2", "test2", "test2", ),
  19. client["HelloWorldRPCGroup"].triggerCallback("test3", "test3", "test3", ),
  20. ])
  21. counter = 0
  22. const simplehandler = (s) => {
  23. counter++
  24. if(counter === 3)
  25. console.log("simpleSubscribe call counter met", counter === 3)
  26. }
  27. await client["HelloWorldRPCGroup"].simpleSubscribe(simplehandler)
  28. client["HelloWorldRPCGroup"].triggerCallback("simple1", "simple1", "simple1", )
  29. client["HelloWorldRPCGroup"].triggerCallback("simple2", "simple2", "simple2", )
  30. client["HelloWorldRPCGroup"].triggerCallback("simple3", "simple3", "simple3", )
  31. })