我正在按照他们的示例在 React Native 0.46.4 中使用 Twilio 创建一个项目:https ://github.com/twilio/TwilioChatJsReactNative
虽然,在初始化 API 时会出现一个奇怪的错误:
import { Client as TwilioChatClient } from "twilio-chat";
import { AccessManager as TwilioAccessManager } from "twilio-common";
const client = new TwilioChatClient(TOKEN, { logLevel: "debug" });
const accessManager = new TwilioAccessManager(TOKEN);
client.initialize().then(() => (
client.getSubscribedChannels().then(() => {
// ...
})
));
这是结果: Neact Native 错误
最后是日志:
2.195 I: 'Twilsock D:', 'FSM: ', 'startup', ': ', 'none', '>>', 'disconnected'
2.197 I: 'Twilsock D:', 'try to connect to:', 'wss://tsock.twilio.com/v3/wsconnect'
2.199 I: 'Twilsock D:', 'FSM: ', 'userConnect', ': ', 'disconnected', '>>', 'connecting'
2.216 W: Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
2.216 W: (Saw setTimeout with duration 3419784ms)
2.217 W: Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
2.217 W: (Saw setTimeout with duration 3599783ms)
2.244 I: 'EMS D:', 'Token request', { fpa_token: 'xxxx',
2.244 I: continuation_token: undefined }
2.247 I: 'Chat I:', 'updateToken'
3.096 I: 'EMS D:', 'Token response:', { status: 200,
3.096 I: headers:
3.096 I: { 'content-type': 'application/json;charset=utf-8',
3.096 I: date: 'Wed, 20 Sep 2017 20:09:53 GMT',
3.096 I: server: 'nginx',
3.096 I: 'strict-transport-security': 'max-age=15768000',
3.096 I: 'x-shenanigans': 'none',
3.096 I: 'content-length': '1695',
3.096 I: connection: 'keep-alive' },
3.096 I: body:
3.096 I: { twilio_rtd_token: 'yyy',
3.096 I: continuation_token: 'zzz',
3.096 I: ttl: 3599,
3.096 I: endpoint_ids: { chat: 'twi1-qqq' },
3.096 I: status:
3.096 I: { status: 'NEW',
3.096 I: reason: 'continuation token has not been provided' },
3.096 I: identity: '-----',
3.096 I: account_sid: 'ACxxx',
3.096 I: instance_sids: { chat: 'ISxxx' } } }
3.100 I: 'Sync D:', 'POST', 'https://cds.twilio.com/v3/Lists', 'ID:', 'RQYYY'
3.103 I: 'Twilsock I:', 'socket opened'
3.103 I: 'Twilsock D:', 'send request:', 'TWILSOCK V3.0 557\r\n{"id":"511c7f9exxxx","method":"init","token":"yyy","payload_size":0}\r\n'
3.105 I: 'Twilsock D:', 'FSM: ', 'socketConnected', ': ', 'connecting', '>>', 'initialising'
3.299 E: 'Twilsock E:', 'unsupported protocol: Mb\u000bHà�\u0001]ÀÐ\r ver undefined'
3.302 W: 'Twilsock W:', 'FSM: unexpected transition', { '0': 'socketClosed',
3.302 W: '1': 'unsupported',
3.302 W: '2': 'unsupported',
3.302 W: '3': [],
3.302 W: '4': 100,
3.302 W: '5': 'event socketClosed inappropriate in current state unsupported' }
3.302 I: 'Twilsock D:', 'FSM: ', 'unsupportedProtocol', ': ', 'initialising', '>>', 'unsupported'
4.225 I: 'Sync D:', 'Establishing intent to subscribe to SHvvv'
4.226 I: 'Chat I:', 'Session created', 'SHnnn'
4.226 I: 'Sync D:', 'GET', 'https://cds.us1.twilio.com/v3/Services/ISzzz/Lists/SHxxx/Context', 'ID:', 'RQxxx'
4.357 I: 'Sync D:', 'Twilsock connection (required for subscription) not ready; waiting…'
包.json
"twilio-chat": "^1.2.0",
"twilio-common": "^0.1.7",
"twilio-ems-client": "^0.2.6",
"twilio-notifications": "^0.4.4",
"twilio-sync": "^0.5.10",
"twilio-transport": "^0.1.3",
"twilsock": "^0.3.5"
这来自安卓模拟器。有人知道可能发生的事情或我做错了什么吗?
编辑:在 iOS 上完美运行