TwitchWebSub

TwitchWebSub

TwitchWebSub The Twitch Webhooks implementation, as described in https://dev.twitch.tv/docs/api/webhooks-guide/ . The Webhook/WebSub requires a public endpoint on the running express server/application to receive the data from the hub. Without this, its impossible to make this work.

Constructor

new TwitchWebSub(config, logger)

Source:
Parameters:
Name Type Description
config object

The config object.

Name Type Description
client_id string

The client ID of the user to be passed to the Hub (un)subscribe requests.

callbackUrl string

The callback URL that will receive the Hub requests. These requests should be forwarded to the handleRequest method to properly handle these data.

logger object

The logger object.

Methods

destroy()

Destroy the WebSub, unsubscribing every active subscription.

Source:

subscribe(topic, eventName) → {string}

Subscribe to a specific topic that will fires an event when new data is received from the hub. The event handler will receive the data object and the subscription ID.

Source:
Parameters:
Name Type Description
topic string

The topic name/URL.

eventName string

The event name that will be fired when new data is received.

Returns:
Type:
string

The subscription ID, used to identify the active topic.

topicStreamUpDownSubscribe(streamUserId) → {string}

Notifies when a stream goes online or offline. The response mimics the Get Streams endpoint. (https://dev.twitch.tv/docs/api/reference/#get-streams)

Source:
Parameters:
Name Type Description
streamUserId number

The ID of the user whose stream is monitored.

Fires:
Returns:
Type:
string

The subscription ID, used to identify the active topic.

topicUserFollowsSubscribe(fromId, toId) → {string}

Notifies when a follows event occurs. The response mimics the Get Users Follows endpoint. (https://dev.twitch.tv/docs/api/reference/#get-users-follows)

Source:
Parameters:
Name Type Description
fromId number

The ID of the user who starts following someone.

toId number

The ID of the user who has a new follower.

Fires:
Returns:
Type:
string

The subscription ID, used to identify the active topic.

unsubscribe(id)

Unsubscribe from a topic by its ID.

Source:
Parameters:
Name Type Description
id string

The subscription ID.

Events

WebSub:stream_up_down

Stream Up/Down Event

Source:
Parameters:
Name Type Description
data object

The data object received from the Hub.

id string

The subscription ID.

WebSub:user_follows

Stream User Follows Event

Source:
Parameters:
Name Type Description
data object

The data object received from the Hub.

id string

The subscription ID.