Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

json-rpc-on-a-stream

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-rpc-on-a-stream

Get JSON RPC on a stream

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

json-rpc-on-a-stream

Get JSON RPC on a stream

npm install json-rpc-on-a-stream

Usage

const JRPC = require('json-rpc-on-a-stream')

// a stream to the other person
const rpc = new JRPC(stream)

// send a request
await rpc.request('hello', 'world')

// respond to requests
rpc.respond('hello', async function () {
  return 'sup'
})

// send a request without waiting for a reply
rpc.event('hello')

API

const rpc = new JRPC(stream, [options])

Make a new RPC instance. You should make one on each side of the stream.

Options include:

{
  binaryStream: true // set to false if you do not need message encoding, ie an object stream
}

const reply = await rpc.request(method, params)

Make a request.

rpc.respond(method, async function respond (params) { ... })

Respond to requests.

rpc.event(method, param)

Send a "fire and forget" request, ie an event.

rpc.unrespond(method)

Remove a responder.

License

MIT

FAQs

Package last updated on 07 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts