Install the package via your preferred package manager:
pnpm install @streamerbot/client
npm install @streamerbot/client
yarn add @streamerbot/client
Or import it directly in the browser via a CDN:
<script src="https://cdn.jsdelivr.net/npm/@streamerbot/client/dist/streamerbot-client.js"></script>
Or with ESM modules:
<script type="module" src="index.js"></script>
import { StreamerbotClient } from 'https://cdn.skypack.dev/@streamerbot/client';
To connect to the WebSocket Server using the Streamer.bot Client
const client = new StreamerbotClient();
You can also specify custom connection options, if you have changed the default settings outlined above.
const client = new StreamerbotClient({
  host: '127.0.0.1',
  port: 8080,
  endpoint: '/',
  password: 'my-secret-password' // Only needed if authentication is enabled
});
Streamer.bot Client makes it extremely easy to execute your actions:
// Execute an action with actionId "9c6203fd-363f-4834-983e-b10423c568ea"
client.doAction("9c6203fd-363f-4834-983e-b10423c568ea");
// Execute an action by name
client.doAction({ name: "My Action" })
To add an event handler, you can use the on() method.
Listening to specific events is easy, simply specify the event name, which is a combination of the event source and type.
For example, below we subscribe to Twitch Chat Message events:
// Subscribe to Twitch Chat messages and register an event handler
client.on('Twitch.ChatMessage', ({ event, data }) => {
  // Do something with Twitch Chat data...
  console.log('Twitch Chat:', data);
});
You can also subscribe to all events from a specific source by using wildcards:
// Subscribe to *All* Twitch events
client.on('Twitch.*', ({ event, data }) => {
  // Do something with Twitch data...
  console.log('Twitch Event:', event.type, data);
});
If you want to listen to all events, you can use the * wildcard:
// Subscribe to *All events*
client.on('*', ({ event, data }) => {
  // Do something with all events...
  console.log(`[${event.source}.${event.type}]`, data);
});