Overview
Properties
Constructor
new BasicPubSubClient(options)
Creates a new PubSub client.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| options | BasicPubSubClientOptions | none | see below | |
| options.logger | Partial<LoggerOptions> | none | Options to pass to the logger. | |
| options.wsOptions | WebSocketClientOptions | none | 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 | Description |
|---|---|---|
| isError | boolean | Whether the cause of the disconnection was an error. A reconnect will be attempted if this is true. |
| reason | Error | The error object. |
onListenError((topic, error, userInitiated) => { /* ... */ })
Fires when listening to a topic fails.
| Parameter | Type | Description |
|---|---|---|
| topic | string | The name of the topic. |
| error | Error | The error. |
| userInitiated | boolean | Whether the listen was directly initiated by a user. The other case would happen in cases like re-sending listen packets after a reconnect. |
onMessage((topic, message) => { /* ... */ })
Fires when a message that matches your listening topics is received.
| Parameter | Type | Description |
|---|---|---|
| topic | string | The name of the topic. |
| message | unknown | The message data. |
onPong((latency, requestTimestamp) => { /* ... */ })
Fires when the client receives a pong message from the PubSub server.
| Parameter | Type | Description |
|---|---|---|
| latency | number | The current latency to the server, in milliseconds. |
| requestTimestamp | number | none |
Properties
Methods
listen(topics, tokenResolvable)
Listens to one or more topics.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| topics | string | string[] | none | A topic or a list of topics to listen to. | |
| tokenResolvable | ResolvableValue<string> | TokenResolvable | none | An access token, an AuthProvider or a function that returns a token. |