react-native - Twilio 聊天 React Native SDK 错误:无法添加命令
问题描述
我正在使用 React Native 中的 SDK 客户端使用 Twilio 可编程聊天将聊天添加到我的应用程序中。发送消息的代码如下:
client.sendMessage(message.text)
.catch(err => console.log(err));
我在控制台中收到一个错误,上面写着:
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)
我正在抓住它,所以它不会在我的实际应用程序中造成任何问题,但很高兴了解导致它的原因以及如何修复它。
注意:消息正在发送,所有功能看起来都很好。
谢谢你的帮助
解决方案
我最终能够摆脱这个问题。这是由于我的 leaveChannel() 方法使用了不正确的 Promise 链。自从解决了这个问题后,我对 add 命令错误没有任何问题,我认为这是由于房间没有正确断开连接造成的。如果有帮助,以下是我的断开连接方法。让我知道你是怎么做出来的。
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.");
}
});}
推荐阅读
- python - 从 git 提交、删除和获取后文件更改的 MD5 哈希
- c - memset 中 `void*` 返回的目的是什么?
- python - 为什么我的 setuptools 在 Python 3.9 中不起作用?
- angular - Angular 10 - 如何在没有 StompJS 的情况下实现 WebSocket
- android - DJI 将 SDK 集成到应用程序中冻结并且不执行任何操作
- docker - 无法使用 Rider 调试使用 docker 容器和 docker-compose 构建的 .net 核心应用程序。容器退出代码 139
- android - 我的代码在模拟器上运行,但在真实设备上遇到错误
- linux - 查找具有特定权限的文件
- python - Pandas - 用最少的步骤替换/合并行的方法
- reactjs - 如何让 Django 在 Ubuntu 18.04 上使用 Apache2 服务 React?