TwurpleAuthenticationGetting dataExamplesFAQMigration

PubSubClient

A high level PubSub client attachable to a multiple users.

Overview

Constructor

new PubSubClient(config)

Creates a new PubSub client.

ParameterTypeRequiredDefaultDescription
configPubSubClientConfignone

The client configuration.

Events

onListenError((handler, error, userInitiated) => { /* ... */ })

Fires when listening to a topic fails.

ParameterTypeDescription
handlerPubSubHandler<PubSubMessage>none
errorError

The error.

userInitiatedboolean

Whether the listen was directly initiated by a user.

The other case would happen in cases like re-sending listen packets after a reconnect.

Methods

onAutoModQueue(user, channel, callback)

Adds a handler to AutoMod queue events to the client.

ParameterTypeRequiredDefaultDescription
user
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The user the event will be subscribed for.

channel
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The channel to listen to.

callback(message: PubSubAutoModQueueMessage) => voidnone

A function to be called when an AutoMod queue event is sent to the user.

It receives a PubSubAutoModQueueMessage object.

Return type: PubSubHandler<never>

onBits(user, callback)

Adds a handler to bits events to the client.

ParameterTypeRequiredDefaultDescription
user
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The user the event will be subscribed for.

callback(message: PubSubBitsMessage) => voidnone

A function to be called when a bits event happens in the user's channel.

It receives a PubSubBitsMessage object.

Return type: PubSubHandler<never>

onBitsBadgeUnlock(user, callback)

Adds a handler to bits badge unlock events to the client.

ParameterTypeRequiredDefaultDescription
user
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The user the event will be subscribed for.

callback(message: PubSubBitsBadgeUnlockMessage) => voidnone

A function to be called when a bit badge is unlocked in the user's channel.

It receives a PubSubBitsBadgeUnlockMessage object.

Return type: PubSubHandler<never>

onCustomTopic(user, topic, callback, scope, channel)

Adds a handler for arbitrary/undocumented events to the client.

ParameterTypeRequiredDefaultDescription
user
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The user the event will be subscribed for.

topicstringnone

The topic to subscribe to.

callback(message: PubSubCustomMessage) => voidnone

A function to be called when a custom event is sent to the user.

It receives a PubSubCustomMessage object.

scopestringnone

An optional scope if the topic requires it.

channel
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

An optional second userId if the topic requires it, usually a channel.

Return type: PubSubHandler<never>

onLowTrustUser(channel, user, callback)

Adds a handler to low-trust users events to the client.

ParameterTypeRequiredDefaultDescription
channel
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The channel the event will be subscribed for.

user
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The user the event will be subscribed for.

callback(message:
PubSubLowTrustUserMessage
) => void
none

A function to be called when a low-trust user event is sent to the user.

Return type: PubSubHandler<never>

onModAction(user, channel, callback)

Adds a handler to mod action events to the client.

ParameterTypeRequiredDefaultDescription
user
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The user the event will be subscribed for.

channel
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The channel the event will be subscribed for.

callback(message: PubSubModActionMessage) => voidnone

A function to be called when a mod action event is sent to the user.

It can receive any kind of {@link PubSubModActionMessage} object.

Return type: PubSubHandler<never>

onRedemption(user, callback)

Adds a handler to redemption events to the client.

ParameterTypeRequiredDefaultDescription
user
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The user the event will be subscribed for.

callback(message: PubSubRedemptionMessage) => voidnone

A function to be called when a channel point reward is redeemed in the user's channel.

It receives a PubSubRedemptionMessage object.

Return type: PubSubHandler<never>

onSubscription(user, callback)

Adds a handler to subscription events to the client.

ParameterTypeRequiredDefaultDescription
user
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The user the event will be subscribed for.

callback(message: PubSubSubscriptionMessage) => voidnone

A function to be called when a subscription event happens in the user's channel.

It receives a PubSubSubscriptionMessage object.

Return type: PubSubHandler<never>

onUserModeration(user, channel, callback)

Adds a handler to user moderation events to the client.

ParameterTypeRequiredDefaultDescription
user
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The user the event will be subscribed for.

channel
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The channel to listen to.

callback(message: PubSubUserModerationNotificationMessage) => voidnone

A function to be called when a user moderation event is sent to the user.

It receives a PubSubUserModerationNotificationMessage object.

Return type: PubSubHandler<never>

onWhisper(user, callback)

Adds a handler to whisper events to the client.

ParameterTypeRequiredDefaultDescription
user
UserIdResolvable

A user ID or a user or channel object.

This is not a user name. Please use HelixUserApi#getUserByName to fetch a user object by name.

Aliased type: string | number | UserIdResolvableType

none

The user the event will be subscribed for.

callback(message: PubSubWhisperMessage) => voidnone

A function to be called when a whisper is sent to the user.

It receives a PubSubWhisperMessage object.

Return type: PubSubHandler<never>

removeAllHandlers()

Removes all handlers from the client.

Return type: void

removeHandler(handler)

Removes a handler from the client.

ParameterTypeRequiredDefaultDescription
handlerPubSubHandler<never>none

A handler returned by one of the on* methods.

Return type: void