ws-rpc-client

A Promise-based RPC subprotocol for WebSockets

This project has moved to `ws-promise`.
Last updated 4 years ago by kdex .
GPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ws-rpc-client 
SYNC missed versions from official npm registry.

Project moved

This project has moved here. This repository is deprecated.

ws-rpc-client

ws-rpc-client is a tiny WebSocket subprotocol that builds a request-response model onto HTML5 WebSockets using ES2015 Promises. You can use this with ES2017's await/async to simplify your WebSocket API. ws-rpc-client supports node.js and browsers. For more flexibility, please see kdex/ws-promise-server and kdex/ws-promise-client, the official server and client based on this subprotocol.

API reference

RPC.constructor(options)

Constructs a new RPC client. options is an optional object with the following properties:

  • options.timeout A global timeout (in milliseconds) after which the delivery of a message is considered to have failed. By default, a value of 1500 is assumed.

RPC.prototype.readMessage(text, fire = true)

Reads a serialized incoming message containing text and fires a specialized event if fire is truthy. Reading a message means that the RPCClient may automatically reply with MESSAGE_ACKNOWLEDGEMENT so that the Promise on the other side resolves.

  • text The serialized Message object to read
  • fire (optional) If truthy, fires an event of message.id

async RPC.prototype.send(payload)

Sends a message containing payload in order to execute a remote method. payload takes the following form:

  • payload.instruction The instruction name to invoke on the remote target
  • payload.args An array of arguments that should be provided. If you don't pass an array, the argument will be wrapped in one.
  • payload.timeout (optional) The timeout that should be used for declaring the message transmission as failed. If not provided, the default timeout is used.
  • payload.id (optional) A unique ID to tell messages apart; if not provided, a random UUID is used.

Current Tags

  • 2.1.10                                ...           latest (4 years ago)

20 Versions

  • 2.1.10 [deprecated]           ...           4 years ago
  • 2.1.9 [deprecated]           ...           4 years ago
  • 2.1.8 [deprecated]           ...           4 years ago
  • 2.1.7 [deprecated]           ...           4 years ago
  • 2.1.6 [deprecated]           ...           4 years ago
  • 2.1.5 [deprecated]           ...           4 years ago
  • 2.1.3 [deprecated]           ...           4 years ago
  • 2.1.2 [deprecated]           ...           4 years ago
  • 2.1.1 [deprecated]           ...           4 years ago
  • 2.1.0 [deprecated]           ...           4 years ago
  • 2.0.1 [deprecated]           ...           4 years ago
  • 2.0.0 [deprecated]           ...           4 years ago
  • 1.0.7 [deprecated]           ...           5 years ago
  • 1.0.6 [deprecated]           ...           5 years ago
  • 1.0.5 [deprecated]           ...           5 years ago
  • 1.0.4 [deprecated]           ...           5 years ago
  • 1.0.3 [deprecated]           ...           5 years ago
  • 1.0.2 [deprecated]           ...           5 years ago
  • 1.0.1 [deprecated]           ...           5 years ago
  • 1.0.0 [deprecated]           ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)

Copyright 2014 - 2016 © taobao.org |