Constellation
This is a client for the Beam Constellation service, which replaces the Beam Liveloading system. You can use it to easily listen for Beam events from Node.
This library is based on a public specification of the protocol.
Installation
npm install --save constellation-client
Usage
After creating a Constellation client, simply listening for an event allows you to start receiving data immediately. The library will automatically connect, subscribe to events you are listening for, and it will reconnect automatically if it loses connection.
const constellation = ;constellation;
However, if you don't want to connect automatically, you can pass an options object, and then run constellation.connect()
function when required.
const constellation = autoConnect: false ;constellation;
If you require authentication, you can pass either cookie
(containing a Beam session cookie) or authorization
(containing an OAuth Bearer token).
const constellation = authorization: '...' ;
You can manually send a message to the Constellation server by using constellation.send(method, params)
. A promise is returned once the Constellation server replies. The promise is rejected if Constellation responds with an error
, or if the client is not currently connected to Constellation.
const constellation = ;constellation;
All possible options are:
autoConnect
- Whether the client should automatically connect to the server. Defaults totrue
.autoReconnect
- Whether the client should automatically reconnect on disconnection. Defaults totrue
.reconnectTime
- The number of milliseconds to wait before a reconnection attempt. Defaults to8000
.serverAddress
- The address that the client should connect to. Defaults towss://constellation.mixer.com
authorization
- The OAuth Bearer token to authenticate with, if necessary.cookie
- The Beam session cookie to authenticate with, if necessary.
Reserved events (that will not get passed through to Constellation when listening for them) include:
connected
disconnected
reconnecting
error