node hpfeeds3 client
Native hpfeeds3 client for node.js
hpfeeds is a lightweight authenticated publish-subscribe protocol that supports arbitrary binary payloads.
Installation
$ npm install --save node-hpfeeds-client
Example
const Client = ; const hpfeeds = 'test.example.com' 10000 'user' 'abcd'; hpfeeds; hpfeeds; hpfeeds;
API
Instantiating
Instantiate the hpfeeds client by passing the host to connect to, the port, the user and the secret to the constructor as arguments:
const Client = const hpfeeds = 'testhost.example.com' 10000 'user' 'secret';
Connecting
To connect call connect([cb]) with an optional callback
const Client = const hpfeeds = 'testhost.example.com' 10000 'user' 'secret'; hpfeeds;
The callback is also called when an error occurs while connecting.
Subscribing
Use subscribe(channel, [cb]) to subscribe to a channel with hpfeeds server:
hpfeeds;
Once subscribed, the incoming messages can be collected via 'data' event.
Publishing
Use publish(channel, payload, [cb]) to publish data to a channel at hpfeeds server:
hpfeeds;
payload can be a string, a buffer or an object. In the latter case it is automatically converted to JSON first.
Disconnecting
Use close([cb]) to disconnect from hpfeeds server
hpfeeds;
Events
'connected'
Emitted when the connection is established and a server info message is received.
callback(err, server_name)
hpfeeds;
'data'
Emitted when new data is available in one of the subscribed channels.
callback(channel, data)
hpfeeds;
'end'
Emitted when the remote gracefully closes the connection
callback()
hpfeeds;
'close'
Emitted when the hpfeeds socket is closed.
callback()
hpfeeds;
'error'
Emitted when an error occurs (including authentication errors)
callback(err)
hpfeeds;
'timeout'
Emitted when the client socket times out because of inactivity
callback(err)
hpfeeds;
License
Licensed under MIT License. Copyright 2019 Coldrift Technologies B.V. All rights reserved.