Twilio 可编程聊天与 React Native
Twilio Programmable Chat with React Native
我正在尝试将 Twilio Chat 添加到我的 React Native 项目中。我收到名称 SyncError
和代码 0 的错误。此时我只是想确认它已连接。这是我的基本设置。
在顶部导入
import {Client as Chat} from 'twilio-chat'
在我的class
里面
componentDidMount = async () => {
console.log(Chat);
const token = await AsyncStorage.getItem('auth-token');
axios.get(config.apiUrl + '/chat/details', { headers: { Authorization: token } })
.then(res => {
console.log(res);
Chat.create(res.data.twilioToken)
.then(client => {
console.log('client', client);
this.subscribeToAllChatClientEvents(client);
})
.catch(error => {
console.log('There was an error', error);
});
})
.catch(err => {
console.log(err);
})
}
该错误还提到了 "Unhandled promise rejection",但我在需要的地方包含了任何 catch
块。
感谢您的帮助。
对于遇到同样问题的任何人。我意识到问题出在我的服务器代码中,因为我没有正确创建 twilio jwt 令牌。
令牌可能有问题。
根据我的经验,我从后端服务器获得了一个很好的令牌并将其保存在 AsyncStorage 上。但是,一段时间后令牌不再起作用。
我通过每次需要实例化 SDK 客户端时向服务器请求一个新的 twilio 令牌来解决这个问题。
我正在尝试将 Twilio Chat 添加到我的 React Native 项目中。我收到名称 SyncError
和代码 0 的错误。此时我只是想确认它已连接。这是我的基本设置。
在顶部导入
import {Client as Chat} from 'twilio-chat'
在我的class
里面componentDidMount = async () => {
console.log(Chat);
const token = await AsyncStorage.getItem('auth-token');
axios.get(config.apiUrl + '/chat/details', { headers: { Authorization: token } })
.then(res => {
console.log(res);
Chat.create(res.data.twilioToken)
.then(client => {
console.log('client', client);
this.subscribeToAllChatClientEvents(client);
})
.catch(error => {
console.log('There was an error', error);
});
})
.catch(err => {
console.log(err);
})
}
该错误还提到了 "Unhandled promise rejection",但我在需要的地方包含了任何 catch
块。
感谢您的帮助。
对于遇到同样问题的任何人。我意识到问题出在我的服务器代码中,因为我没有正确创建 twilio jwt 令牌。
令牌可能有问题。
根据我的经验,我从后端服务器获得了一个很好的令牌并将其保存在 AsyncStorage 上。但是,一段时间后令牌不再起作用。
我通过每次需要实例化 SDK 客户端时向服务器请求一个新的 twilio 令牌来解决这个问题。