Open DrSensor opened 6 years ago
For your use case, this library supports WebSocket and HTTP. When talking to browsers it is best to use a WebSocket.
NodeJS runs just about anywhere and has no dependencies.
Here's an implementation which appears to support raw sockets/streams: https://github.com/Microsoft/vscode-languageserver-node/tree/master/jsonrpc
So you could problably do it like this: simulated firmware as rpc-client -> microsoft-jsonrpc-streams as server ->microsoft-jsonrpc-streams as client -> jsonrpc-bidirectional-as-server-and-client -> browser
Yes, language server in vscode are using stdio pipe to communicate but its not suitable in my use case since there is a scenario where bunch of simulated firmware talk to the bridge. Thats why I think unix domain socket is good alternative (because it can handle duplex communication more) since docker daemon communicate via this layer to. (I also found out that stdio pipe has buffer limitation so I can't send a data that's to large).
There is other reason that I consider unix socket because the simulated firmware are written in different language, writing it to send data in unix socket is easier than writing it to send data in stdio pipe (need to switch between stdin and stdout).
I actually plan to implement the bridge using vs-jsonrpcstream (in C#) |or| jayson-rpc (in Nodejs) [still not decided] and make the browser (web browser) and the simulated firmware both as a rpc-client. However, since I found this library, I wonder if in the future I can just simplified by making the browser as rpc-server and the bridge is just like a bridge with same dependency (jsonrpc-bidirectional). And maybe add some auth feature in the bridge.
About jayson-rpc, its json-rpc library with features almost same as jsonrpc-bidirectional but there are missing feature to create jsonrpc-server in the web browser.
You can still use jsonrpc-bidirectional as I have explained above, replacing the Microsoft thing with what you found. Additionally, you can write your authentication and authorization layers as jsonrpc-bidirectional plugins, on both the server and the browser.
In short, jsonrpc-bidirectional would be the centerpiece of your architecture and you would add all your server logic in it, allowing you to have a JSONRPC.Server in the browser. jayson-rpc would only be an adapter in the same application (proxying RPCs from that firmware thing).
Look at the authorization plugin in the tests directory for a login session example. Usage is in the tests.
If you want to write it from scratch see the plugins in src.
Any plan to support net.Socket class? I have some use case when I need to create some bridge that passes JSON-RPC data from Unix Domain Socket into WebSocket. Something like