I am using the Twilio conversations JS SDK, and I need to refresh my connection token if it is expired or invalid. The issue is that, if I call the updateToken()
function when the connection state change to "denied", I get the following error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'updateToken')
I am using it like this:
let conversationsClient = new Twilio.Conversations.Client('SOME_EXPIRED_OR_INVALID_TOKEN')
conversationsClient.on("connectionStateChanged", (state) => {
switch (state) {
case "denied":
conversationsClient.updateToken(getConversationsToken());
break
}
});
For some reason my conversationsClient
object is undefined when it enters the denied state.
According the SDK documentation (https://media.twiliocdn.com/sdk/js/conversations/releases/2.0.0/docs/modules.html#ConnectionState), I can update the token when the state is changed to denied.