updateToken

View as Markdown
  • updateToken(token): Promise<void>

Replaces the token used by the client with a new one. You can use this method to replace the token when, for example, it is expiring, in order to keep the session alive.

The new token can contain different channels from the previous one. In that case, you will need to subscribe to the new channels if you want to receive messages for those. Channels that were in the previous token but are not in the new one will get unsubscribed automatically.

Parameters

token
stringRequired

The new token.

Returns

Promise<void>

Example

1const chatClient = new Chat.Client({
2 token: '<your chat token>'
3})
4
5chatClient.on('session.expiring', async () => {
6 const newToken = await fetchNewToken(..)
7
8 await chatClient.updateToken(newToken)
9})