在twilio可编程聊天中,我使用了<script>
export default {
props: ['game_id', 'userId', 'this.rows'],
mounted() {
console.log('Component mounted.')
},
data() {
return {
timestamp: 0,
selectedGame: {},
gamesinfo: [],
zero:0,
one:0,
two:0,
Bettotal:0,
gamex: this.gameId,
rows: [],
count: 0,
fields: {},
errors: {},
success: false,
loaded: true,
};
},
doSum: function () {
this.Bettotal = parseInt(this.zero) + parseInt(this.one) + parseInt(this.two);
// if (isNaN(this.Bettotal)) this.Bettotal = 0;
return this.Bettotal;
},
};
事件来更新访问令牌。该事件完美触发。之后,我从API提取了新令牌,并使用tokenAboutToExpire
用新令牌更新了chatClient。
一旦我管理了chatClient,便更新了Inside令牌和fpaToken。即使有时我也可以在过期后发送/接收消息,而无需刷新页面。如果刷新页面,则会抛出错误,例如
updateToken
Uncaught (in promise) Error: Can't connect to twilsock
这是我的日志,
componentDidMount() {
const accessToken = this.props.chatUserData.chatAccessToken;
Chat.create(accessToken)
.then(this.setupChatClient)
.catch(this.handleError);
}
setupChatClient = client => {
...
...
...
this.client.on('tokenAboutToExpire', function () {
thisProps.dispatch(getUserAccessToken(clientEmail, logIn.token))
//api call => when response came, I make 'isChatAccessFetched' as true and update the 'chatAccessToken' in reducer and checking that in componentWillReceiveProps
});
}
componentWillReceiveProps(nextProps) {
...
...
...
if (nextProps.chatUserData.isChatAccessFetched) {
this.updateChatAccessToken(this.props.chatUserData.chatClient)
}
}
updateChatAccessToken = chatClient => {
let chatAccessToken = this.props.chatUserData.chatAccessToken;
chatClient.updateToken(chatAccessToken)
this.props.dispatch(updateChatClient(chatClient))
}
...
...
...
请帮助我解决此问题。预先感谢。