请教一下各位大佬,我在cocos creator里使用leancloud做即时通讯,浏览器环境下可以正常收发信息,用模拟器或者打包成安卓、iOS就报错了,使用不了。
cocos creator的版本v1.9.3
leancloud-realtime的版本库v4.2.1
在cocos里面写的代码如下:
var { Realtime } = require('leancloud-realtime');
var realtime = new Realtime({
appId: '项目中使用真实的appid',
appKey: '项目中使用真实的appkey',
ssl: false,
});
cc.Class({
extends: cc.Component,
properties: {
},
start () {
var { TextMessage } = require('leancloud-realtime');
// Tom 用自己的名字作为 clientId,获取 IMClient 对象实例
realtime.createIMClient('Tom').then(function(tom) {
console.log('chattest,36--tom==---', tom);
// 创建与Jerry之间的对话
return tom.createConversation({
members: ['Jerry'],
name: 'Tom & Jerry',
});
}).then(function(conversation) {
console.log('chattest,42---conversation--', conversation);
// 发送消息
return conversation.send(new TextMessage('耗子,起床!'));
}).then(function(message) {
console.log('chattest,47---message--', message);
console.log('Tom & Jerry', '发送成功!');
}).catch(console.error);
},
});
控制台输出错误信息:
Simulator: ------------------------------------------------
Simulator: Initializing JavaScriptCore
Simulator: JS: Cocos2d-x-lite v1.8.2
Simulator: iShow!
Simulator: JS: InitScene: 0.9489999999999554ms
Simulator: JS: AutoRelease: 0.1410000000000764ms
Simulator: JS: Destroy: 0.09199999999998454ms
Simulator: JS: AttachPersist: 0.005999999999971806ms
Simulator: JS: Activate: 14.740999999999985ms
Simulator: In the constructor of HttpClient!
Simulator: JS: [ERROR]: Unhandled promise rejection [object Object]
Simulator: XMLHttpRequest_finalize, 0x7f98bcc13510 ...
Simulator: XMLHttpRequest_finalize, 0x7f98ba6f83c0 ...
Simulator: ERROR: event disconnect inappropriate because previous transition did not complete, location:
电脑环境是:MacOs