1234567891011121314151617181920212223 |
- import { RPCSocket } from '../src/Frontend'
- const client = new RPCSocket(20000, 'localhost')
- client.connect().then(async _ => {
- await client.info().then(console.log)
-
- await client["HelloWorldRPCGroup"].echo("x")
- .then(hopefullyX => console.log("echo('x') returned x: ", hopefullyX === "x", hopefullyX))
-
- await client["HelloWorldRPCGroup"].add(1,2,3)
- .then(hopefully6 => console.log("add(1,2,3) returned 6: ", hopefully6 === 6, hopefully6))
-
- let counter = 0
- const handler = (s) => {
- counter++
- if(counter === 3)
- console.log("callback was called 3 times", counter === 3)
- }
-
- await client["HelloWorldRPCGroup"].subscribe(handler)
- client["HelloWorldRPCGroup"].triggerCallback("test1", "test1", "test1", )
- client["HelloWorldRPCGroup"].triggerCallback("test2", "test2", "test2", )
- client["HelloWorldRPCGroup"].triggerCallback("test3", "test3", "test3", )
- })
|