this.channel.on не является функцией twilio - PullRequest
0 голосов
/ 14 октября 2019

Я пытаюсь использовать twilio для создания функции чата, но у меня возникают проблемы с этим.

Вот 2 фрагмента кода, которые я использую

loadMessages = () => {        
    this.setState({ isLoading: false });
    this.channel.getMessages && this.channel.getMessages()
    .then((res)=>{
        console.log('res in get messages : ',res);
        this.messagesLoaded(res);
    }).catch((err)=>console.log('err in get messages : ',err));
    this.channel.on('messageAdded', this.messageAdded);        
  }


createChannel = (channelName1) => {
      this.props.client.createChannel({ uniqueName: channelName1, friendlyName: channelName1 })
      .then(channel => {
          this.channel = channel;
          return this.channel.join(()=>{
            this.setState({ isLoading: false });
            this.channel.invite(this.state.secondUserId).then(function() {
              console.log('Your friend has been invited!');
            });
            this.channel.getMessages()
            .then(this.messagesLoaded)
            .catch((err)=>console.log('error in getting messages : ',err));

            this.channel.on('messageAdded', this.messageAdded);
          }).catch((err)=>console.log('err in joining channel : ',err))
      })      
      .catch(this.handleError);
  }

По сути, происходит следующее:Я получаю сообщение об ошибке this.channel.on не является функцией

, а this.channel.getMessages () не является функцией.

У вас, ребята, есть идеи, как это исправить?

...