The API allows real-time, bidirectional communication between your application and the Social Stream Ninja extension/app, the dock page, and the overlay pages.
There is an easy to use sandbox to play with some of the common API commands and options over here.
Table of Contents
The WebSocket API allows real-time, bidirectional communication between your application and the Social Stream Ninja server.
Connect to the WebSocket server at wss://io.socialstream.ninja
.
There are two methods to connect and join a session:
ws = new WebSocket("wss://io.socialstream.ninja/join/SESSION_ID/IN_CHANNEL/OUT_CHANNEL");
ws = new WebSocket("wss://io.socialstream.ninja");
ws.onopen = function() {
ws.send(JSON.stringify({ join: "SESSION_ID", in: IN_CHANNEL, out: OUT_CHANNEL }));
};
Parameters:
SESSION_ID
: Your unique session identifier (same as used in dock.html or featured.html URL)IN_CHANNEL
: Channel number to receive messages (optional)OUT_CHANNEL
: Channel number to send messages (optional)The default channel value is used if not specified
The channel system allows for more granular control over message routing:
When specifying channels, you’re defining which channels to receive messages from (IN_CHANNEL) and which to send messages to (OUT_CHANNEL). This allows different components of your setup to communicate on separate channels, reducing noise and improving organization.
When a message is sent, it goes to the specified output channel. Those who have that channel set as their input channel will recieve the message.
sendChat
{"action": "sendChat", "value": "Hello, world!"}
sendEncodedChat
{"action": "sendEncodedChat", "value": "Hello%2C%20world%21"}
blockUser
{"action": "blockUser", "value": {"chatname": "username", "type": "twitch"}}
extContent
{"action": "extContent", "value": "{\"chatname\":\"User\",\"chatmessage\":\"Hello\"}"}
{"action": "removefromwaitlist", "value": 1}
{"action": "highlightwaitlist", "value": 2}
{"action": "resetwaitlist"}
{"action": "downloadwaitlist"}
{"action": "selectwinner", "value": 1}
{"action": "clear"}
or {"action": "clearAll"}
{"action": "clearOverlay"}
{"action": "nextInQueue"}
{"action": "getQueueSize"}
{"action": "autoShow", "value": "toggle"}
{"action": "feature"}
{"action": "getChatSources"}
{"action": "toggleVIPUser", "value": {"chatname": "username", "type": "twitch"}}
{"action": "getUserHistory", "value": {"chatname": "username", "type": "twitch"}}
{"action": "waitlistmessage", "value": "Your custom message"}
{"action": "drawmode", "value": true}
You can send messages to specific channels using the content
action with a channel number:
{"action": "content", ...}
{"action": "content2", ...}
{"action": "content3", ...}
{"action": "content4", ...}
{"action": "content5", ...}
{"action": "content6", ...}
{"action": "content7", ...}
The server also supports HTTP GET, POST, and PUT requests for the same actions. Replace SESSION_ID
with your actual session ID.
https://io.socialstream.ninja/SESSION_ID/ACTION/TARGET/VALUE
https://io.socialstream.ninja/SESSION_ID
(with JSON body)https://io.socialstream.ninja/SESSION_ID/ACTION
(with JSON body)You can specify the output channel for HTTP requests using the channel
query parameter:
https://io.socialstream.ninja/SESSION_ID/ACTION/TARGET/VALUE?channel=2
This will send the message to channel 2. If not specified, it defaults to channel 1.
Connect to the SSE endpoint to receive real-time updates:
const eventSource = new EventSource(`https://io.socialstream.ninja/sse/SESSION_ID`);
Include a get
parameter in your request for actions that require a response:
{
"action": "yourAction",
"value": "yourValue",
"get": "uniqueIdentifier"
}
The server will respond with:
{
"callback": {
"get": "uniqueIdentifier",
"result": true
}
}
Note: Not all commands support or require this callback mechanism.
content
action on channel 1custom.js
fileauto1
trigger responds “1” to any message that is “1”Social Stream Ninja implements a targeting system that allows messages to be directed to specific instances of the dock or featured pages if multiple of either are open.
URL Parameter: Each instance (featured/dock) can be given a unique label using the label
URL parameter.
Example: featured.html?label=stream1
or dock.html?label=controlpanel1
Message Structure: When sending a message through the API, include a target
field with the label of the intended recipient.
Example:
{
"action": "someAction",
"target": "stream1",
"value": "someValue"
}
Message Processing: The application checks each incoming message for a target. If the message has a target that doesn’t match the instance’s label, the message is ignored.
This targeting system allows for more flexible and powerful setups, especially in complex streaming environments.
The featured.html page is designed to display featured content, typically used for showcasing selected messages or donations in a stream overlay. It communicates primarily on channel 3 for output and channels 1 and 2 for input, depending on the configuration.
The featured.html page can be configured to connect to the WebSocket server in three different ways:
wss://io.socialstream.ninja
, joins the room, and sets output to channel 3 and input to channel 2.In all cases, channel 3 is reserved for output from the featured.html page.
These can be set using URL parameters:
?server
: Default connection?server2
: Server2 connection?server3
: Server3 connectionThe featured page offers several filtering options that can be controlled via the API:
onlyshowdonos
: Only show messages with donationshideDonations
: Hide donation informationhideTwitch
: Hide messages from TwitchonlyTwitch
: Only show messages from TwitchonlyFrom
: Only show messages from a specific sourcehideFrom
: Hide messages from specific sourcesfilterfeaturedusers
: Only show messages from whitelisted usersThe featured page responds to the following API actions:
content
: Display new content
{"action": "content", "value": {...contentObject...}}
clear
: Clear the currently displayed content
{"action": "clear"}
toggleTTS
or tts
: Toggle or set Text-to-Speech
{"action": "toggleTTS", "value": "toggle"}
or {"action": "tts", "value": "on"}
When sending content to be displayed, the content object should have the following structure:
{
"chatname": "Username",
"chatmessage": "Message content",
"chatimg": "URL to user avatar",
"contentimg": "URL to content image",
"subtitle": "Subtitle text",
"membership": "Membership information",
"hasDonation": "Donation information",
"type": "Source type (e.g., twitch, youtube)",
"id": "Unique message ID"
}
queuetime
is set, messages are added to a queue and displayed sequentially.To display a new featured message:
socketserver.send(JSON.stringify({
action: "content",
value: {
chatname: "ExampleUser",
chatmessage: "Hello, featured chat!",
type: "twitch",
hasDonation: "$5.00"
}
}));
To clear the current featured message:
socketserver.send(JSON.stringify({ action: "clear" }));
To toggle Text-to-Speech:
socketserver.send(JSON.stringify({ action: "toggleTTS", value: "toggle" }));
The dock.html page serves as a control center for managing chat messages and interactions. It connects to multiple WebSocket servers and processes incoming messages.
The dock page can be configured to connect to different WebSocket servers:
wss://io.socialstream.ninja/api
server
URL parameterout: 2, in: 1
wss://io.socialstream.ninja/extension
server2
or server3
URL parametersout: 3, in: 4
server
: Sets the main server URLserver2
: Enables connection to the extension server and sets its URLserver3
: Enables connection to both main and extension serversThe dock page processes incoming WebSocket messages using the processInput
function. This function handles various types of messages and actions, including:
The dock page responds to various API actions, including:
clear
or clearAll
: Clears all messages except pinned onesclearOverlay
: Clears the overlay without affecting the docknextInQueue
: Moves to the next message in the queuegetQueueSize
: Returns the current queue sizeautoShow
: Controls automatic message displaycontent
: Processes and displays new contentfeature
: Features the next unfeatured messagetoggleTTS
or tts
: Controls Text-to-Speech functionalityTo clear all messages:
socketserver.send(JSON.stringify({ action: "clear" }));
To feature the next message:
socketserver.send(JSON.stringify({ action: "feature" }));
To toggle Text-to-Speech:
socketserver.send(JSON.stringify({ action: "toggleTTS", value: "toggle" }));
processInput
function into smaller, more manageable functions for easier maintenance.[Previous content remains the same]
The extension is a critical component of the Social Stream Ninja system, acting as the primary source of messages and managing communication between different parts of the system.
The extension maintains two WebSocket connections:
wss://io.socialstream.ninja/dock
out: 4, in: 3
settings.server2
or settings.server3
wss://io.socialstream.ninja/api
out: 2, in: 1
settings.socketserver
applyBotActions()
.sendToDestinations()
.processResponse()
.The extension processes various API actions, including:
sendChat
: Sends a chat message to the specified destination.sendEncodedChat
: Sends an encoded chat message to the specified destination.blockUser
: Blocks a user from a specific source or all sources.extContent
: Processes external content, applying bot actions before sending.removefromwaitlist
: Removes an entry from the waitlist.highlightwaitlist
: Highlights an entry in the waitlist.resetwaitlist
: Resets the entire waitlist.stopentries
: Stops accepting new entries.downloadwaitlist
: Initiates a download of the waitlist.selectwinner
: Selects a random winner from the waitlist.To send a chat message:
socketserver.send(JSON.stringify({
action: "sendChat",
value: "Hello, world!",
target: "twitch" // optional, specifies the destination platform
}));
To block a user:
socketserver.send(JSON.stringify({
action: "blockUser",
value: "username",
target: "youtube" // optional, "*" for all platforms
}));
To process external content:
socketserver.send(JSON.stringify({
action: "extContent",
value: JSON.stringify({
chatname: "User",
chatmessage: "Hello from an external source!",
type: "external"
})
}));
The extension plays a central role in the Social Stream Ninja system:
This central position allows the extension to act as a powerful intermediary, enabling features like chat moderation, custom bot actions, and cross-platform interactions.
The waitlist.html page is designed to manage and display waitlists or giveaways within the Social Stream Ninja system. It connects to a WebSocket server and processes incoming messages to update the waitlist display.
wss://io.socialstream.ninja/extension
out: 5, in: 6
setupSocket()
: Establishes and manages the WebSocket connection.processInput(data)
: Processes incoming WebSocket messages and updates the waitlist display.The waitlist page processes various types of messages:
waitlistmessage
: Updates the waitlist title.drawmode
: Toggles draw mode and displays winners.drawPoolSize
: Updates the number of entries in the draw.waitlist
: Updates the entire waitlist display..winner
: Applied to winning entries..loser
: Applied to non-winning entries in draw mode..selected
: Applied to highlighted entries..guestListHolder
: Container for each waitlist entry.The waitlist page responds to various API actions, including:
waitlistmessage
: Sets a custom message for the waitlist.
{
"waitlistmessage": "Welcome to the giveaway!"
}
drawmode
: Toggles draw mode and can display winners.
{
"drawmode": true,
"winlist": [
{"chatname": "Winner1", "type": "twitch", "chatimg": "URL"},
{"chatname": "Winner2", "type": "youtube", "chatimg": "URL"}
]
}
drawPoolSize
: Updates the number of entries in the draw.
{
"drawPoolSize": 100
}
waitlist
: Updates the entire waitlist.
{
"waitlist": [
{"chatname": "User1", "type": "twitch", "chatimg": "URL", "waitStatus": 0},
{"chatname": "User2", "type": "youtube", "chatimg": "URL", "waitStatus": 2}
]
}
The waitlist page integrates with the Social Stream Ninja system by:
This integration allows streamers or moderators to manage waitlists or giveaways efficiently while providing an engaging visual display for viewers.
These pages may lack API support directly, however in some cases they can be controlled via the extension’s API.
For example the waitlist has some functions that can be controlled via the extensiion:
removefromwaitlist
highlightwaitlist
resetwaitlist
stopentries
downloadwaitlist
selectwinner
Just to touch on the Battle Royal game though,
The battle.html page is an interactive game-like features. Currently it doesn’t use a WebSocket connection but instead communicates directly with the extension via WebRTC.
!join
command!say
commandstartgame
: Initiates the gameWhile the battle page doesn’t directly connect to the API server, it can receive actions through the extension:
startgame
: Starts the game
sendDataP2P({startgame: true});
processData({
chatname: "PlayerName",
chatmessage: "!join sword",
chatimg: "URL",
type: "twitch",
nameColor: "#FFFFFF"
});
processData({
chatname: "PlayerName",
chatmessage: "!say Hello, everyone!"
});
The battle page relies on the extension for receiving data:
sendDataP2P()
to send data to the battle pageI’ll create a guide focused on integrating Social Stream Ninja with StreamDeck, specifically for sending custom messages.
https://io.socialstream.ninja/YOUR_SESSION_ID/sendEncodedChat/null/YOUR_URL_ENCODED_MESSAGE_HERE
Replace:
YOUR_SESSION_ID
with your Social Stream Ninja session IDYOUR_MESSAGE
with your URL-encoded messageFor example, to send “Hello Stream!”:
https://io.socialstream.ninja/abc123/sendEncodedChat/null/Hello%20Stream!
You can use this page to test and generate the correct URL here, if having problems doing it manually: https://socialstream.ninja/sampleapi.html. Note that we want to generate a GET request with this method.
For more flexibility, you can use Multi Actions to send different messages:
WebSocket (WSS)
https://io.socialstream.ninja/YOUR_SESSION_ID/sendChat/null/YOUR_MESSAGE
HTTPS POST
https://io.socialstream.ninja/YOUR_SESSION_ID
With body:
{
"action": "sendChat",
"value": "YOUR_MESSAGE",
"apiid": "YOUR_SESSION_ID"
}
To send to specific channels, add the channel parameter:
https://io.socialstream.ninja/YOUR_SESSION_ID/sendChat/null/YOUR_MESSAGE?channel=2
Channels:
I’ll add a section about Bitfocus Companion integration with what we can confirm from the provided information:
Bitfocus Companion enables the reasonably priced Elgato Streamdeck to be a professional shotbox surface for a huge amount of different presentation switchers, video playback software and broadcast equipment. It supports Social Stream Ninja and VDO.Ninja!
https://bitfocus.io/companion https://bitfocus.io/connections/socialstream-ninja
Global settings and tools
> Mechanics
Enable remote API control of extension
Global settings and tools
> Session Options
?session=
The following commands are confirmed available in Companion:
Companion can access:
queue_size
: Shows the current queue sizeAdvantages of using Companion:
This makes Companion a simpler alternative to the StreamDeck HTTP method described above, especially for basic Social Stream Ninja control.