twitcheasy-twitch-bottwitch-authtwitch-auth-tmitwitch-chat-clienttwitch-eventsubtwitch-pubsub-clienttwitch-webhooks

BasicPubSubClient

A client for the Twitch PubSub interface.

Overview

Constructor

new BasicPubSubClient(options)

Creates a new PubSub client.

ParameterTypeRequiredDefaultDescription
optionsBasicPubSubClientOptionsnone
options.loggerPartial<LoggerOptions>none

Options to pass to the logger.

options.wsOptionsClientOptionsnone

The client options to use for connecting to the WebSocket.

Events

onConnect(() => { /* ... */ })

Fires when the client finishes establishing a connection to the PubSub server.

onDisconnect((isError, reason) => { /* ... */ })

Fires when the client closes its connection to the PubSub server.

ParameterTypeDescription
isErrorboolean

Whether the cause of the disconnection was an error. A reconnect will be attempted if this is true.

reasonErrornone

onMessage((topic, message) => { /* ... */ })

Fires when a message that matches your listening topics is received.

ParameterTypeDescription
topicstring

The name of the topic.

messagePubSubMessageData

The message data.

onPong((latency, requestTimestamp) => { /* ... */ })

Fires when the client receives a pong message from the PubSub server.

ParameterTypeDescription
latencynumber

The current latency to the server, in milliseconds.

requestTimestampnumbernone

Properties

isConnected

Type: boolean

Checks whether the client is currently connected to the server.

isConnecting

Type: boolean

Checks whether the client is currently connecting to the server.

Methods

connect()

async

Connects to the PubSub interface.

Return type: void

disconnect()

async

Disconnects from the PubSub interface.

Return type: void

listen(topics, tokenResolvable, scope)

async

Listens to one or more topics.

ParameterTypeRequiredDefaultDescription
topicsstring | Array<string>none

A topic or a list of topics to listen to.

tokenResolvableResolvableValue<string> | AuthProvider | TokenResolvable | nullnone

An access token, an AuthProvider or a function that returns a token.

scopestringnone

The scope necessary for the topic(s).

Return type: void

reconnect()

async

Reconnects to the PubSub interface.

Return type: void

unlisten(topics)

async

Removes one or more topics from the listener.

ParameterTypeRequiredDefaultDescription
topicsstring | Array<string>none

A topic or a list of topics to not listen to anymore.

Return type: void