StreamElements API

StreamElements socket.io

onEventReceived examples

StreamElements socket.io

What is it?

StreamElements socket.io (also known as realtime) is a socket implementation that allows you to connect to StreamElements to send and receive events in real time.

As the name suggests, it is based on the socket.io protocol. While somewhat outdated on the StreamElements side (in favor of Astro WebSockets), it is still in use and works well.


Unlike Astro (StreamElements WebSockets), realtime allows you to send events to StreamElements. So, if you have a highly customized widget, you can send events to StreamElements and have it respond accordingly.


For example, I have a custom widget that displays the Pokémon in my party from the Pokémon Yellow game (yeah, I like old games). Every time a Pokémon's status changes (like HP), I can send an event to update the widget (check Pikachu's HP in the gif).


pokemon gif

Initial information:

The StreamElements socket.io URL is https://realtime.streamelements.com.

You can authenticate using bearer token (JWT), apikey (overlay token), or oAuth2 token. It uses "websocket" transport.


It also appears possible to connect directly via Websockets (not socket.io) to wss://realtime.streamelements.com, but this document only covers the socket.io implementation (although most details apply to both).


Official StreamElements socket.io documentation is on Streamelements Developer Portal

How to connect:

It seems StreamElements still uses an old version of Socket.io, version 2. I was able to connect using newer client version, like 4.5.4, though. However, if you are having connection issues, try using an older client version to see if that works.

You need to use a socket.io library to connect to the StreamElements socket. It is originally a JavaScript library, but you can find other client implementations on the Socket.io website

Events

Every time a new event occurs, the socket emits a message (except for a chat messages). Some events are listed below:

Reference

            "event"                       // Standard events like follower, subscribers, channel points redemptions
            "event:test"                  // Test events and When the "Next Alert" button is clicked (useful for custom events)
            "event:update"                // Same as "event", but updates data
            "event:skip"                  // When alert is skipped
            "session:reset"               // When session data is reset
            "overlay:mute"                // When overlays are muted or unmuted
            "overlay:refresh"             // When overlays are refreshed
            "overlay:update"              // When an overlay is updated
            "overlay:action"              // When the "Reload overlays" is clicked on Activity feed
            "overlay:togglequeue"         // When overlays are paused or resumed
            "kvstore:update"              // When a kvstore data is updated (like overlay paused)
            "session:update"              // When an session update occurs (new bits, new follower, tips, etc)
            "bot:counter"                 // When a counter is updated
            "giveaway:state"              // When a giveaway is created or closed
            "contest:state"               // When a contest is created or closed
            "contest:winner"              // When a contest winner is picked
            "songrequest::mediashare"     // Information on media share
            "songrequest:play"            // When song request starts playing
            "songrequest:pause"           // When song request is paused
            "songrequest:song:next"       // When next song is chosen to be played
            "songrequest:song:previous"   // When previous song is chosen to be played
            "songrequest:queue:remove"    // When song is removed from queue (or declined from pending requests)
            "songrequest:queue:add"       // When song is added to the queue (or approved from pending requests)
            "songrequest:history:add"     // When song is added to the history
            "songrequest:volume"          // When volume is set for song
            "songrequest:settings:update" // When song request settings is changed
          

Receiving events

In order to receive events, add a socket.on function with the event name you want to receive:

If you want, you can listen to all the events listed above, just register each one in its own code block.

Alternatively, you can use socket.onAny() function to listen to all events:

Rooms

Some rooms are available to subscribe to via the StreamElements socket. Here are the ones I have found so far (replace ACCOUNT_ID with your actual StreamElements account id):

Reference

            "songrequest::ACCOUNT_ID"
            "contests::ACCOUNT_ID"
            "giveaways::ACCOUNT_ID"
            "store::ACCOUNT_ID"
            "obs::ACCOUNT_ID"
            "kvstore::ACCOUNT_ID"
            "plarium::ACCOUNT_ID"
            "appsflyer::ACCOUNT_ID"
            "partner-integrations::ACCOUNT_ID"
            "audience-queue::ACCOUNT_ID"
          

Before you ask, I also don't know exactly what the "plarium" and "appsflyer" rooms are used for. Plarium is the company behind the game “Raid - Shadow Legends” (a well-known StreamElements sponsorship) and AppsFlyer is a company that does analytics and campaigns management. The "partner-integrations" room is probably related to sponsorships, but I could not test it.

As for "obs", well... I believe it has something to do with OBS Studio, but I couldn't test it. If you know more about it, please let me know.

Subscribe to a room

To join a room, emit a subscribe event with the room name. In JavaScript, you also need to provide a third parameter: a callback function. So, it should look like this:

Alternatively, you can subscribe to multiple rooms at once:

Other info

If you have questions or want to share feedback, feel free to contact me here.

I believe there is much more data to document, but I can't recall what else to add right now. In the meantime, enjoy this randomly generated image below: