错误调用“ UpdateToken”在客户拒绝国家变更上,使用Twilio对话JS SDK
我正在使用Twilio对话JS SDK,如果它过期或无效,我需要刷新连接令牌。问题是,如果我调用 updateToken()
函数时,当连接状态更改为“拒绝”时,我会收到以下错误:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'updateToken')
我是这样的:
let conversationsClient = new Twilio.Conversations.Client('SOME_EXPIRED_OR_INVALID_TOKEN')
conversationsClient.on("connectionStateChanged", (state) => {
switch (state) {
case "denied":
conversationsClient.updateToken(getConversationsToken());
break
}
});
出于某种原因,我的>对话clionclient
对象进入拒绝状态时,它是不确定的。
根据SDK文档(),我可以在更改状态更改以否认状态时更新令牌。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是您的
getConversationStoken
函数是异步的,因为它可能向您的服务器提出了请求。但是您正在传递该功能的结果,而不是异步作用的结果。我假设
getConversationStoken
返回承诺,因此您可以通过在然后在
callback中更新令牌来解决此问题:或者,您可以使用
async/等待
这样:My guess here is that your
getConversationsToken
function is asynchronous as it presumably makes a request to your server. But you are passing the result of the function, not the result of the asynchronous action.I assume that
getConversationsToken
returns a promise, so you might be able to fix this by updating the token in thethen
callback:Or, you could use
async/await
like this: