constellation-client

1.0.5 • Public • Published

Constellation

Build Status Coverage Status

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 = new Constellation();
constellation.on('user:1:update', data => {
    // { "sparks": 10000 }
});

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 = new Constellation({ autoConnect: false });
constellation.connect();

If you require authentication, you can pass either cookie (containing a Beam session cookie) or authorization (containing an OAuth Bearer token).

const constellation = new 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 = new Constellation();
constellation.on('connected', () => {
    constellation.send('divide', { numerator: 16, denominator: 4 }).then(res => {
        // 4
    }).catch(err => {
        // { "code": 1000, "message": "Cannot divide by zero" }
    });
});

All possible options are:

  • autoConnect - Whether the client should automatically connect to the server. Defaults to true.
  • autoReconnect - Whether the client should automatically reconnect on disconnection. Defaults to true.
  • reconnectTime - The number of milliseconds to wait before a reconnection attempt. Defaults to 8000.
  • serverAddress - The address that the client should connect to. Defaults to wss://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

Package Sidebar

Install

npm i constellation-client

Weekly Downloads

2

Version

1.0.5

License

MIT

Unpacked Size

17.8 kB

Total Files

10

Last publish

Collaborators

  • ethanwaite