nydus-client
TypeScript icon, indicating that this package has built-in type declarations

4.0.2 • Public • Published

nydus-client

WebSocket client library for the nydus protocol, a simple RPC/PubSub protocol.

NPM

NPM

Usage

import nydusClient from 'nydus-client'

const socket = nydusClient(host[, options])

Create a nydus client and connect it to a particular host. An optional options object can be passed as the second argument. For the list of acceptable options, check the constructor method of engine.io-client.

API

socket.connect()

Connect to the server. If already connected, this will be a no-op.

socket.registerRoute(pathPattern, handler)

Register a handler function to respond to PUBLISH messages on a path matching the specified pattern. Handler function is a normal function of the form: function({ route, params, splats }, data)

PUBLISH messages that don't match a route will be emitted as an 'unhandled' event on this object, which can be useful to track in development mode.

socket.invoke(path[, data])

Invoke a remote method on the server, specified via a path. Optionally, data can be specified to send along with the call (will be JSON encoded). A Promise will be returned; resolved or rejected with the result or error, respectively, from the server.

socket.disconnect()

Disconnect from the server. If not already connected, this will be a no-op.

License

MIT

Package Sidebar

Install

npm i nydus-client

Weekly Downloads

9

Version

4.0.2

License

MIT

Unpacked Size

43.1 kB

Total Files

17

Last publish

Collaborators

  • tec27