This commit is contained in:
2019-09-21 02:56:03 +02:00
parent 968885767a
commit 2b765eb2a2
11 changed files with 165 additions and 77 deletions
+29 -4
View File
@@ -1,11 +1,36 @@
import { Server } from '../src/Backend'
import { SubscriptionResponse } from '../src/Responses'
let subcallback
new Server(20000, [{
name: "HelloWorldRPCGroup",
publicRPCs: () => [],
localRPCs: () => [{
exportRPCs: () => [{
type: 'Call',
name: 'echo',
call: async (s:string) => s,
}]
}])
},
{
type: 'Hook',
name: 'subscribe',
hook: async (callback):Promise<any> => {
subcallback = callback
return new SubscriptionResponse(""+Math.random())
},
unhook: async (uid):Promise<any> => { subcallback = null }
},
function add(...args:number[]):number {return args.reduce((a,b)=>a+b, 0)},
function triggerCallback(message):number {return subcallback(message)},
]
}])
try{
new Server(20001, [{
name: "bad",
exportRPCs: () => [
(aaa,bbb,ccc) => { return aaa+bbb+ccc }
]
}])
}catch(badRPCError){
console.log("expected bad-RPC error happened: "+ !!badRPCError)
}
+22 -5
View File
@@ -1,7 +1,24 @@
import { Client } from '../src/Frontend'
console.log(Client)
const client = new Client(20000, 'localhost')
client.connect().then(_ => {
client.info().then(console.log)
client["HelloWorldRPCGroup"].echo("x").then(console.log)
})
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")
client["HelloWorldRPCGroup"].triggerCallback("test2")
client["HelloWorldRPCGroup"].triggerCallback("test3")
})
+1
View File
@@ -0,0 +1 @@
<script src="../lib/RPCaller.min.js"></script>