channel.on not recognized as a function in Twilio API

Ale*_*lex 1 ajax twilio reactjs twilio-programmable-chat

I have the following function in a ReactJS app that is supposed to initialize the Twilio services that I am using. However, it seems like the Twilio channels are not being accessed correctly. Here is my code:

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;
                    });
                });
            });
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

This function throws an error message saying TypeError: channel.on is not a function in the line channel.on('messageAdded', () => {}).

Any help is appreciated. Thanks.

小智 5

getUserChannelDescriptors()ChannelDescriptors不返回Channels。为了让Channel你必须调用getChannel描述符:https : //media.twiliocdn.com/sdk/js/chat/releases/1.0.0/docs/ChannelDescriptor.html#getChannel__anchor