Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

multi-rpc

znetstar40Apache-2.02.5.0TypeScript support: included

A JSON-RPC 2 compliant client/server implementation designed with multiple transports in mind

rpc, jsonrpc, json, websocket, json-rpc, tcp, http

readme

multi-rpc

NPM

Build Status FOSSA Status

Multi-RPC is a JSON RPC 2 client/server implementation designed with multiple transports and serialization methods in mind. It works both in Node and the browser.

Out of the box it supports serialization with JSON and MessagePack over TCP, HTTP and WebSocket. Writing new serializers and transports is pretty straightforward.

A server can listen on multiple transports which allows for listening using multiple protcols or on multiple interfaces.

Connections via persistent transports like WebSocket or TCP are kept alive and the server can send notifications to clients (a feature which is not offically in the standard).

Example

(async () => {
    const { 
        Server, 
        Client,
        JSONSerializer,
        TCPTransport
    } = require('multi-rpc');

    const serializer = new JSONSerializer();

    const serverTransport = new TCPTransport(serializer, 1234);
    const clientTransport = new TCPTransport(serializer, 1234);

    const server = new Server(serverTransport);
    const client = new Client(clientTransport);

    server.methods.foo = (arg1, arg2, arg3) => {
        console.log(arg1, arg2, arg3);
        return arg1 + arg2 + arg3;
    };

    await server.listen();

    const result1 = await client.invoke("foo", [1,2,3]);
    const result2 = await client.invoke("foo", {
        arg1: 1,
        arg2: 2,
        arg3: 3
    });

    console.log(result1 + result2);

    process.exit();
})();

More examples are available in the wiki.

Projects layout

The Multi-RPC package is comprised of several modules which can be installed individually.

Name Description Browser compatible
multi-rpc-browser Excludes server-side transports
multi-rpc-common Common classes used throughout the project.
multi-rpc-core Server/Client implementation
multi-rpc-http-client-side-transport A HTTP client-side transport
multi-rpc-http-transport A HTTP transport with client/server functionality
multi-rpc-json-serializer A JSON serializer
multi-rpc-msgpack-serializer A MSGPack Serializer
multi-rpc-tcp-transport A TCP transport with client/server functionality
multi-rpc-websocket-client-side-transport A WebSocket client-side transport
multi-rpc-websocket-transport A WebSocket transport with client/server functionality

Tests & Documentation

For mocha tests and documention refer to the individual package (e.g. multi-rpc-common).

Building

Multi-RPC is written in TypeScript. To compile JavaScript run npm run build.

changelog

Changelog

[2.5.0] - 2022-02-02

Adds

  • JSON5 as a serialization/deserialization method via @znetstar/encode-tools@1.4.0

[2.1.0] - 2021-12-23

Changes

  • Upgrades multi-rpc-common

[1.9.0] - 2021-11-12

Changes

  • Upgrades multi-rpc-common

[1.8.2] - 2021-09-13

Changes

  • Upgrades multi-rpc-core

[1.8.1] - 2021-09-13

Changes

  • Upgrades multi-rpc-core

[1.8.0] - 2021-09-13

Changes

  • Upgrades multi-rpc-core

[1.7.7] - 2021-08-29

Changes

  • Upgrades multi-rpc-common

[1.7.6] - 2021-08-23

Changes

  • UUpgrades multi-rpc-common

[1.7.3] - 2021-07-20

Changes

  • UUpgrades multi-rpc-common

[1.7.1] - 2021-07-20

Changes

  • Adds a new serializer based on @etomon/encode-tools.
  • Upgrades most packages.

[1.5.6] - 2019-01-16

Changed

  • Updates multi-rpc-core.

[1.5.5] - 2019-01-15

Changed

  • Updates tcp transport.

[1.5.4] - 2019-01-03

Changed

  • Updates websocket transport.

[1.5.3] - 2019-01-02

Changed

  • Updates multi-rpc-common.

[1.5.1] - 2018-12-24

Changed

  • Fixes a bug with reconnection.

[1.4.1] - 2018-12-24

Changed

  • Update websocket transport.

[1.4.0] - 2018-12-23

Added

  • WebSocket and TCP clients attempt to reconnect to server upon disconnect.

[1.3.0] - 2018-12-23

Added

  • WebSocket and TCP clients attempt to reconnect to server upon disconnect.

[1.2.5] - 2018-12-22

Changed

  • Updates multi-rpc-common.

[1.2.4] - 2018-12-22

Changed

  • Update websocket transport.

[1.2.3] - 2018-12-21

Changed

  • Fixes serveral bugs that occur when the message response is undefined.

[1.2.2] - 2018-12-21

Changed

  • Adds ServerSideTransport interface.

[1.2.1] - 2018-12-21

Changed

  • Breaks the project up into separate modules.

[1.1.9] - 2018-12-16

Changed

  • Removes callback from the sendConnection function on WebSocketTransport.

[1.1.8] - 2018-12-16

Added

  • Adds a proper return type to the client-side invoke function.

[1.1.7] - 2018-12-15

Added

  • Adds serialization function to messages and errors.

[1.1.2] - 2018-12-15

Changes

  • Non-object errors are passed directly to the consturctor of InternalError.

[1.1.1] - 2018-12-14

Added

  • Returns HTTP 204 when a notification is sent over HTTP.

[1.1.0] - 2018-09-26

Added

  • Can now set all rpc methods by passing an object with function values to Server.methods or any child properties (e.g. Server.methods.foo = { bar: () => {} };).

[1.0.5] - 2018-09-25

Changed

  • Adds missing dependency.

[1.0.4] - 2018-09-25

Changed

  • Bug fixes.

[1.0.3] - 2018-09-25

Changed

  • Bug fixes.

Added

  • Will not return errors as the "innerError" field of "data" in the "error" objects.

[1.0.1] - 2018-09-24

Added

  • Transports can be added/removed from the server dynamically.

[1.0.0] - 2018-09-24

Added

  • Inital release. Includes TCP, HTTP and WebSocket transports, and JSON and MessagePack serializers.