Api

Configuration

Reference of all configuration options available when initializing a Streamer.bot client
If you've modified your WebSocket Server settings in Streamer.bot, make sure to match those settings when initializing a StreamerbotClient instance

Connection Settings

host
String

Change the host to match your Streamer.bot WebSocket Server settings

  • Default: '127.0.0.1'
const client = new StreamerbotClient({ host: '192.168.1.90' });
port
Number

Change the port to match your Streamer.bot WebSocket Server settings

  • Default: 8080
const client = new StreamerbotClient({ port: 9001 });
endpoint
String

Change the endpoint to match your Streamer.bot WebSocket Server settings

  • Default: '/'
const client = new StreamerbotClient({ endpoint: '/custom' });
password
String

Change the password to match your Streamer.bot WebSocket Server authentication settings, if enabled.

const client = new StreamerbotClient({ password: 'LyfeSaverSeventyFourIsMyDaddy' });
scheme
`ws` | `wss`

Only change this if you are using a secure tunnel or otherwise know what you are doing.

  • Default: ws
const client = new StreamerbotClient({ scheme: 'wss', host: 'sb-tunnel.my-tailnet.ts.net' });
immediate
Boolean

Automatically attempt to connect to the Streamer.bot WebSocket Server?

  • Default: true
// Disable immediate connection, and manually connect later
const client = new StreamerbotClient({ immediate: false });
await client.connect();
autoReconnect
Boolean

Automatically attempt to reconnect when the connection is closed?

  • Default: true
// Prevent auto reconnecting by default
const client = new StreamerbotClient({ autoReconnect: false });
retries
Number

Number of times to attempt to reconnect automatically. Set to -1 for infinite attempts.

  • Default: -1
// Attempt to reconnect a maximum of 10 times
const client = new StreamerbotClient({ retries: 10 });
subscribe
StreamerbotEventsSubscription | '*'

On connect, subscribe to specific Streamer.bot events

const client = new StreamerbotClient({
  subscribe: {
    'Twitch': ['ChatMessage']
  }
});

Event Handlers

onConnect
(data: StreamerbotInfo) => void

Callback when the client connects or reconnects to the WebSocket Server

Connected Streamer.bot instance information will be provided as the first argument.

const client = new StreamerbotClient({
  onConnect: (data) => {
    console.log('My Streamer.bot Instance', data);
    /**
     * {
     *    "instanceId": string,
     *    "name": string,
     *    "os": "windows" | "linux" | "macosx" | string,
     *    "version": string
     * }
     */
  }
});
onDisconnect
() => void

Callback when the client disconnects from the WebSocket Server

const client = new StreamerbotClient({
  onDisconnect: () => {
    console.warn('Streamer.bot Client Disconected!');
  }
});
onError
(error: Error) => void

Global callback when the client encounters an error

const client = new StreamerbotClient({
  onError: (err) => {
    console.error('Streamer.bot Client Error', err);
  }
});
onData
(data: Object) => void

Global callback when the client receives JSON data from the WebSocket Server

Data could be any Event payload or Method response.

const client = new StreamerbotClient({
  onData: (data) => {
    console.log('Streamer.bot Data Received', data);
  }
})