Overview
Properties
Methods
Constructor
new BasicPubSubClient(options)
Creates a new PubSub client.
Parameter | Type | Description |
---|---|---|
options | BasicPubSubClientOptions | |
options.logger | Partial<LoggerOptions> | Options to pass to the logger. |
options.wsOptions | ClientOptions | 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.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
isError | boolean | none | Whether the cause of the disconnection was an error. A reconnect will be attempted if this is true. | |
reason | Error | none | none |
onMessage((topic, message) => { /* ... */ })
Fires when a message that matches your listening topics is received.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
topic | string | none | The name of the topic. | |
message | PubSubMessageData | none | The message data. |
onPong((latency, requestTimestamp) => { /* ... */ })
Fires when the client receives a pong message from the PubSub server.
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
latency | number | none | The current latency to the server, in milliseconds. | |
requestTimestamp | number | none | none |
Properties
Methods
listen(topics, tokenResolvable, scope)
asyncListens to one or more topics.
Parameter | Type | Description |
---|---|---|
topics | string | Array<string> | A topic or a list of topics to listen to. |
tokenResolvable | ResolvableValue<string> | AuthProvider | TokenResolvable | null | An access token, an AuthProvider or a function that returns a token. |
scope | string | The scope necessary for the topic(s). |
unlisten(topics)
asyncRemoves one or more topics from the listener.
Parameter | Type | Description |
---|---|---|
topics | string | Array<string> | A topic or a list of topics to not listen to anymore. |