nojvek / noice-json-rpc Goto Github PK
View Code? Open in Web Editor NEWNoice Json RPC exposes a clean ES6 Proxy and Promise based interface for JSON-RPC2 Clients and Servers
License: MIT License
Noice Json RPC exposes a clean ES6 Proxy and Promise based interface for JSON-RPC2 Clients and Servers
License: MIT License
First of all, I must thank you for this project. As of this writing, I struggled to find a JSON-RPC implementation which is transport-agnostic, works out of the box with TypeScript, and makes use of ECMAScript 6 Proxy
objects in order to abstract from the actual communication.
Overall, I did not encounter any problems except for the following one. Let us assume that you have a remote object with a method isReadable
which returns true
if a document is readable and false
otherwise. Furthermore, let us assume that the method is executed on a document which is not readable. The remote call of this method would therefore return false
and the expected result for the local method call would therefore also be false
. However, instead one receives {}
as result.
The problem lies within the lines 261 and 267 of noice-json-rpc.ts
. The shortcut result || {}
used to give undefined
results a default value will also evaluate to {}
for false
as result and this might be unwanted behavior. Replacing this part with something like result === undefined ? {} : result
should fix this issue.
WS.send(...) will throw errors when there's no callback:
https://github.com/websockets/ws/blob/master/lib/WebSocket.js#L355
Resulting in stuff like:
Error: not opened
at WebSocket.send (/home/lain/git/final-pm/node_modules/ws/lib/WebSocket.js:355:18)
at Server._send (/home/lain/git/final-pm/node_modules/noice-json-rpc/lib/noice-json-rpc.js:235:16)
at Server._sendError (/home/lain/git/final-pm/node_modules/noice-json-rpc/lib/noice-json-rpc.js:238:14)
at result.then.catch (/home/lain/git/final-pm/node_modules/noice-json-rpc/lib/noice-json-rpc.js:193:38)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
const wssServer = new WebSocket.Server({ port });
const api = new rpc.Server(wssServer).api();
error TS2345: Argument of type 'Server' is not assignable to parameter of type 'LikeSocketServer'.
Types of property 'clients' are incompatible.
Type 'Set' is not assignable to type 'LikeSocket[] | undefined'.
Type 'Set' is not assignable to type 'LikeSocket[]'.
Property 'includes' is missing in type 'Set'.
I will have to connect to a server that uses https://github.com/joshmarshall/jsonrpclib api.
this is using http protocol.
My question may be silly from your viewpoint, but I need to know if it will work ?
Regards,
S.Ancelot
Congrats on getting the protocol generator into devtools-protocol! I am switching to that and want to keep using noice-json-rpc, but it doesn't work with the Debugger.on('scriptParsed, ...
style event handlers, it only expects Debugger.onScriptParsed(...
.
Are you planning on making the first type work? I could provide a PR? Or is there a way to make them work together that I don't see?
I am using this to call the Chrome devtools protocol like:
import WebSocket from 'ws';
import { Protocol } from 'devtools-protocol';
import type { ProtocolProxyApi } from 'devtools-protocol/types/protocol-proxy-api';
import { Client as RpcClient } from 'noice-json-rpc';
async function connect(websocketUrl: string) {
const rpcClient = new RpcClient(new WebSocket(websocketUrl), { logConsole: true });
const api: ProtocolProxyApi.ProtocolApi = rpcClient.api();
const targets = await api.Target.getTargets({});
}
In the console I see:
Client > {"id":1,"method":"Target.getTargets","params":{}}
Client < <Buffer 7b 22 69 64 22 3a 31 2c 22 72 65 73 75 6c 74 22 3a 7b 22 74 61 72 67 65 74 49 6e 66 6f 73 22 3a 5b 7b 22 74 61 72 67 65 74 49 64 22 3a 22 44 30 38 44 ... 467 more bytes>
This is using Node v16.16.
Note that the targets
value seems to be properly populated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.