base-easy-jsonrpc
v1.0.7
Published
基于promise封装的jsonrpc库 ## 使用范例 ``` const server = new RpcServer(); server.onNotify("success", (params, router) => { router.redirect("error"); }); server.onNotify("error", () => { console.log("notify---
Downloads
22
Maintainers
Readme
easy-jsonrpc
项目介绍
基于promise封装的jsonrpc库
使用范例
const server = new RpcServer();
server.onNotify("success", (params, router) => {
router.redirect("error");
});
server.onNotify("error", () => {
console.log("notify----error");
});
server.onCall("login", (params, router) => {
router.redirect("loginError");
//return true;
//return {token:"133"};
//throw error;
});
server.onCall("loginError", (params, router) => {
return true;
});
server.onCall(/^login/, () => {
return "login rexge";
});
const client = new RpcClient({timeout: 3000}, {
send: (data) => {
this.server.onClientMessage({
send: (data) => {
client.onServerMessage(data);
}
}, data)
}
});
const result = await client.call("login",{},1000);
console.log(result);
client.notify("success");