Git Product home page Git Product logo

noice-json-rpc's People

Contributors

alexdima avatar digeff avatar laino avatar nojvek avatar roblourens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

noice-json-rpc's Issues

A result of 'false' is converted to '{}'

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.

Pass a callback to WS.send(...)

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)

ts compile error

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'.

Working with devtools-protocol

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?

Console only logs Buffer, not object

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.