我在 ReactJS 应用程序中有以下函数,它应该初始化我正在使用的 Twilio 服务。但是,似乎没有正确访问 Twilio 频道。这是我的代码:
componentDidMount() {
let chatClient = this;
$.ajax({
method: "GET",
url: 'get_twilio_token',
data: {device: chatClient.device},
success: (data) => {
let accessManager = new Twilio.AccessManager(data.token);
//let messagingClient = new Twilio.Chat.Client(data.token);
let messagingClient = new Twilio.Chat.Client.create(data.token).then(client => {
client.getUserChannelDescriptors().then(channels => {
let channelsHash = {};
console.log('inside callback of messagingClient2')
channels.items.map(channel => {
channel.on('messageAdded', () => {})
channelsHash[channel.uniqueName] = channel;
});
});
});
}
});
}
TypeError: channel.on is not a function
此函数在行中抛出一条错误消息channel.on('messageAdded', () => {})
。
任何帮助表示赞赏。谢谢。