1

I'm using the SDK client in React Native to add chat to my app using Twilio Programmable Chat. The code to send a message is below:

client.sendMessage(message.text)
    .catch(err => console.log(err));

I am getting an error back in my console which says:

Error: Can't add command: (status: 0, code: 0)
    at session.js:173
    at tryCallOne (core.js:37)
    at core.js:123
    at JSTimers.js:294
    at _callTimer (JSTimers.js:151)
    at _callImmediatesPass (JSTimers.js:199)
    at Object.callImmediates (JSTimers.js:463)
    at MessageQueue.__callImmediates (MessageQueue.js:316)
    at MessageQueue.js:136
    at MessageQueue.__guard (MessageQueue.js:291)

I'm catching it so it's not causing any problems in my actual app but it would be great to understand that's causing it and how to fix it.

Note: The message is sending and all functionality looks to be fine.

Thanks for any help

Matt Leach
  • 839
  • 3
  • 10
  • 15
  • Interestingly enough I have also been having this error since I did an update to the Twilio Chat SDK. However, the chat message still gets sent. I also have proper error handling, so I just did a yellow box ignore on the error. My guess was it has something to do with the WebSocket transforming when compiled or not being able to use a dependency in RN that it would otherwise have with Node. Not much of a help, but just wanted to let you know you are not alone with this in RN. If you do find a solution I would much appreciate a response. – JavanPoirier Jun 15 '19 at 21:54
  • Hi @JavanPoirier, I yellow box ignored as you suggested and everything seemed to be going well until I did a production build and put the app on an actual device. It seems to work but then the message gets sent multiple times until I navigate away. This only happens in production. I think it's some sort of timing issue so this promise rejection error may be the problem. Have you had anything like this? – Matt Leach Jul 14 '19 at 18:18

1 Answers1

1

I was able to get rid of this issue on my end. It was due to an improper Promise chain with my leaveChannel() method. Since resolving this I have not had any issues with the add command error, which I believe was caused by the room not properly disconnecting. Below is my method for disconnect if it helps. Let me know how you make out.

leaveChannel() {
return new Promise((resolve, reject) => {
  if (this.channel) {
    this.channel.removeAllListeners();
    this.channel
      .leave()
      .then((leftChannel: Channel) => {
        console.log("Left chat channel: " + leftChannel.uniqueName);
        store.dispatch(chatSetState(ConnectionStateEnum.DISCONNECTED));
        resolve();
      })
      .catch((error: any) => {
        console.log("leaveChannel(): ", error);
        this.channel = null;
        reject(error);
      });
  } else {
    console.log("Not currently in a channel.");
  }
});}
JavanPoirier
  • 442
  • 3
  • 9
  • Thanks for this. I realised I had an issue with my redux setup which was causing the issue. Once I fixed that the problem went away. – Matt Leach Jul 25 '19 at 14:47
  • On a slightly different note, have you managed to get push notifications working with your app? @JavanPoirier – Matt Leach Jul 25 '19 at 14:48