Introduction

In this tutorial we're going to connect to Constellation and subscribe to Live Loading updates of your channel. If your viewer count or channel title changes, you'll receive an update within your code that you can respond to.

Writing the Code

Prerequisites

Usage

We'll be using Carina for this tutorial. Carina is Mixer's Node Constellation client. It makes talking to Constellation super easy.

Let's start by importing and setting up all of the modules which we'll need and defining our channel id.

You can find your channel id by going to https://mixer.com/api/v1/channels/username?fields=id in your browser, replacing username with your Mixer username.

const Carina = require('carina').Carina;
const ws = require('ws');

Carina.WebSocket = ws;

const channelId = 1234;

Next we'll create an instance of Carina to use for our code. We pass an object of options to the constructor. isBot must be set to true if you're writing an automated bot.

const ca = new Carina({
    queryString: {
        'Client-ID': 'Click here to get your Client ID!',
    },
    isBot: true,
}).open();

To receive Live Loading events you need to subscribe to them. We'll just need channel:{id}:update. For a full list of events check our Constellation reference guide. You subscribe to events within Carina by using the subscribe method.

ca.subscribe(`channel:${channelId}:update`, data => {
    // ...
});

The second argument to the subscribe method is a function which will be called with the data when the event is sent. Inside the function you can do a lot with the data but for now we'll just log it to the console.

ca.subscribe(`channel:${channelId}:update`, data => {
    console.log(data);
});

That's it! Save the file as 'constellation.js' and run it with node constellation.js from your terminal. Try updating your channel details.

For example, if you update your channel title to 'test', you'll get an object from the event that looks like this:

{ name: "test" }

Try updating your channel description, age rating or selected game for more examples.

The final code can be found below:

const Carina = require('carina').Carina;
const ws = require('ws');

Carina.WebSocket = ws;

const channelId = 1234;

const ca = new Carina({
    queryString: {
        'Client-ID': 'Click here to get your Client ID!',
    },
    isBot: true,
}).open();

ca.subscribe(`channel:${channelId}:update`, data => {
    console.log(data);
});

Carina also works with TypeScript and your Browser. For more information, check out its GitHub page.

Further Ideas

  • Why not combine Constellation with our REST API and make something super cool?
  • Use some of the other Constellation events to get events about your stream.