在uniapp中使用环信sdk,安卓手机真机调试报Error: illegal buffer

可以登录成功,消息也能发送,但收不到消息,onTextMessage监听触发不了,编译器过几秒就报Error: illegal buffer
webIMConfig.js代码如下
/**
* git do not control webim.config.js
* everyone should copy webim.config.js to webim.config.js
* and have their own configs.
* In this way , others won't be influenced by this config while git pull.
*
*/

// for react native
let location = {
protocol: "https"
};

let config = {
/*
* XMPP server
*/
// xmppURL: "wss://im-api.easemob.com/ws/", //小程序2.0sdk线上环境
// xmppURL: "wss://im-api-hsb.easemob.com/ws/", //小程序2.0sdk沙箱环境
// xmppURL: 'wss://im-api-new-hsb.easemob.com/websocket', //小程序沙箱环境
xmppURL: 'wss://im-api-wechat.easemob.com/websocket', //小程序线上环境
/*
* Backend REST API URL
*/
// apiURL: (location.protocol === 'https:' ? 'https:' : 'http:') + '//a1.easemob.com',
apiURL: "https://a1.easemob.com", // 线上环境
// apiURL: "https://a1-hsb.easemob.com", // 沙箱环境
// apiURL: 'https://172.17.3.155:8080',
/*
* Application AppKey
*/
appkey: "1109200606157295#cyn",
/*
* Whether to use HTTPS '1177161227178308#xcx'
* @parameter {Boolean} true or false
*/
https: false,
/*
* isMultiLoginSessions
* true: A visitor can sign in to multiple webpages and receive messages at all the webpages.
* false: A visitor can sign in to only one webpage and receive messages at the webpage.
*/
isMultiLoginSessions: false,
/**
* Whether to use window.doQuery()
* @parameter {Boolean} true or false
*/
isWindowSDK: false,
/**
* isSandBox=true: xmppURL: 'im-api.sandbox.easemob.com', apiURL: '//a1.sdb.easemob.com',
* isSandBox=false: xmppURL: 'im-api.easemob.com', apiURL: '//a1.easemob.com',
* @parameter {Boolean} true or false
*/
isSandBox: false,
/**
* Whether to console.log in strophe.log()
* @parameter {Boolean} true or false
*/
isDebug: false,
/**
* will auto connect the xmpp server autoReconnectNumMax times in background when client is offline.
* won't auto connect if autoReconnectNumMax=0.
*/
autoReconnectNumMax: 15,
/**
* the interval secons between each atuo reconnectting.
* works only if autoReconnectMaxNum >= 2.
*/
autoReconnectInterval: 2,
/**
* webrtc supports WebKit and https only
*/
isWebRTC: false,
/*
* Set to auto sign-in
*/
isAutoLogin: true,
delivery: true,
};

export default config;
webIM.js代码如下
// import Strophe from "../sdk/libs/strophe";
//import xmldom from "../sdk/libs/xmldom/dom-parser";
// import websdk from "../sdk/sdk/src/connection";
import websdk from "../sdk/webimSDK3.1.2.js";
import config from "./WebIMConfig.js";

console.group = console.group || {};
console.groupEnd = console.groupEnd || {};

var window = {};
let WebIM = window.WebIM = websdk;
window.WebIM.config = config;
//var DOMParser = window.DOMParser = xmldom.DOMParser;
//let document = window.document = new DOMParser().parseFromString("<?xml version='1.0'?>\n", "text/xml");

WebIM.isDebug = function(option){
if (option) {
WebIM.config.isDebug = option.isDebug
openDebug(WebIM.config.isDebug)
}

function openDebug(value){
function ts(){
var d = new Date();
var Hours = d.getHours(); // 获取当前小时数(0-23)
var Minutes = d.getMinutes(); // 获取当前分钟数(0-59)
var Seconds = d.getSeconds(); // 获取当前秒数(0-59)
return (Hours < 10 ? "0" + Hours : Hours) + ":" + (Minutes < 10 ? "0" + Minutes : Minutes) + ":" + (Seconds < 10 ? "0" + Seconds : Seconds) + " ";
}


// if (value) {
// Strophe.Strophe.Connection.prototype.rawOutput = function(data){
// try{
// console.group("%csend # " + ts(), "color: blue; font-size: large");
// console.log("%c" + data, "color: blue");
// console.groupEnd();
// }
// catch(e){
// console.log(e);
// }
// };
// }else{
// Strophe.Strophe.Connection.prototype.rawOutput = function(){};
// }

}
}

/**
* Set autoSignIn as true (autoSignInName and autoSignInPwd are configured below),
* You can auto signed in each time when you refresh the page in dev model.
*/
WebIM.config.autoSignIn = false;
if(WebIM.config.autoSignIn){
WebIM.config.autoSignInName = "lwz2";
WebIM.config.autoSignInPwd = "1";
}


// var stropheConn = new window.Strophe.Connection("ws://im-api.easemob.com/ws/", {
// inactivity: 30,
// maxRetries: 5,
// pollingTime: 4500
// });
//
// stropheConn.connect(
// '$t$' + 'YWMtmbQEBKKIEeaGmMtXyg5n1wAAAVlkQvGO2WOJGlMCEJKM4VV9GCMnb_XLCXU',
// function() {
// console.log(arguments, 'ggogogo');
// }, stropheConn.wait, stropheConn.hold);
WebIM.parseEmoji = function(msg){
if(typeof WebIM.Emoji === "undefined" || typeof WebIM.Emoji.map === "undefined"){
return msg;
}
var emoji = WebIM.Emoji,
reg = null;
var msgList = [];
var objList = [];
for(var face in emoji.map){
if(emoji.map.hasOwnProperty(face)){
while(msg.indexOf(face) > -1){
msg = msg.replace(face, "^" + emoji.map[face] + "^");
}
}
}
var ary = msg.split("^");
var reg = /^e.*g$/;
for(var i = 0; i < ary.length; i++){
if(ary[i] != ""){
msgList.push(ary[i]);
}
}
for(var i = 0; i < msgList.length; i++){
if(reg.test(msgList[i])){
var obj = {};
obj.data = msgList[i];
obj.type = "emoji";
objList.push(obj);
}
else{
var obj = {};
obj.data = msgList[i];
obj.type = "txt";
objList.push(obj);
}
}
return objList;
};

WebIM.time = function(){
var date = new Date();
var Hours = date.getHours();
var Minutes = date.getMinutes();
var Seconds = date.getSeconds();
var time = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " "
+ (Hours < 10 ? "0" + Hours : Hours) + ":" + (Minutes < 10 ? "0" + Minutes : Minutes) + ":" + (Seconds < 10 ? "0" + Seconds : Seconds);
return time;
};

WebIM.Emoji = {
path: "../../../../../images/faces/",
map: {
"[):]": "ee_1.png",
"[:D]": "ee_2.png",
"[;)]": "ee_3.png",
"[:-o]": "ee_4.png",
"[:p]": "ee_5.png",
"[(H)]": "ee_6.png",
"[:@]": "ee_7.png",
"[:s]": "ee_8.png",
"[:$]": "ee_9.png",
"[:(]": "ee_10.png",
"[:'(]": "ee_11.png",
"[<o)]": "ee_12.png",
"[(a)]": "ee_13.png",
"[8o|]": "ee_14.png",
"[|]": "ee_15.png",
"[+o(]": "ee_16.png",
"[|-)]": "ee_17.png",
"[:|]": "ee_18.png",
"[*-)]": "ee_19.png",
"[:-#]": "ee_20.png",
"[^o)]": "ee_21.png",
"[:-*]": "ee_22.png",
"[8-)]": "ee_23.png",
"[del]": "btn_del.png",
"[(|)]": "ee_24.png",
"[(u)]": "ee_25.png",
"[(S)]": "ee_26.png",
"[(*)]": "ee_27.png",
"[(#)]": "ee_28.png",
"[(R)]": "ee_29.png",
"[({)]": "ee_30.png",
"[(})]": "ee_31.png",
"[(k)]": "ee_32.png",
"[(F)]": "ee_33.png",
"[(W)]": "ee_34.png",
"[(D)]": "ee_35.png"
}
};

WebIM.EmojiObj = {
// 相对 emoji.js 路径
path: "../../../../../images/faces/",
map1: {
"[):]": "ee_1.png",
"[:D]": "ee_2.png",
"[;)]": "ee_3.png",
"[:-o]": "ee_4.png",
"[:p]": "ee_5.png",
"[(H)]": "ee_6.png",
"[:@]": "ee_7.png"
},
map2: {
"[:s]": "ee_8.png",
"[:$]": "ee_9.png",
"[:(]": "ee_10.png",
"[:'(]": "ee_11.png",
"[<o)]": "ee_12.png",
"[(a)]": "ee_13.png",
"[8o|]": "ee_14.png"
},
map3: {
"[|]": "ee_15.png",
"[+o(]": "ee_16.png",
"[|-)]": "ee_17.png",
"[:|]": "ee_18.png",
"[*-)]": "ee_19.png",
"[:-#]": "ee_20.png",
"[del]": "del.png"
},
map4: {
"[^o)]": "ee_21.png",
"[:-*]": "ee_22.png",
"[8-)]": "ee_23.png",
"[(|)]": "ee_24.png",
"[(u)]": "ee_25.png",
"[(S)]": "ee_26.png",
"[(*)]": "ee_27.png"
},
map5: {
"[(#)]": "ee_28.png",
"[(R)]": "ee_29.png",
"[({)]": "ee_30.png",
"[(})]": "ee_31.png",
"[(k)]": "ee_32.png",
"[(F)]": "ee_33.png",
"[(W)]": "ee_34.png",
"[(D)]": "ee_35.png"
},
map6: {
"[del]": "del.png"
}
};

// wx.connectSocket({url: WebIM.config.xmppURL, method: "GET"})

WebIM.conn = new WebIM.connection({
appKey: WebIM.config.appkey,
isMultiLoginSessions: WebIM.config.isMultiLoginSessions,
https: typeof WebIM.config.https === "boolean" ? WebIM.config.https : location.protocol === "https:",
url: WebIM.config.xmppURL,
apiUrl: WebIM.config.apiURL,
isAutoLogin: true,
heartBeatWait: WebIM.config.heartBeatWait,
autoReconnectNumMax: WebIM.config.autoReconnectNumMax,
autoReconnectInterval: WebIM.config.autoReconnectInterval,
delivery: WebIM.config.delivery
});

// async response
// WebIM.conn.listen({
// onOpened: () => dispatch({type: Types.ON_OPEND})
// })

export default WebIM;
// module.exports = {
// "default": WebIM
// };
已邀请:

HuangLeo

赞同来自:

现在这个uni-app主要面向的是小程序使用,测试了像web端以及appSDK兼容并不是很好。

vkcyan

赞同来自:

在uniapp,引入了小程序demo的sdk,但是在小程序和浏览器环境里面都出现了
illegal buffer;at App onError function;at socketTask.onmessage callback function
Error: illegal buffer
这样的报错,也不知道怎么解决

HuangLeo

赞同来自:

这个报错需要从webConfig.js的配置里面解决,
看下xmppURL对应的的线上环境与SDK的版本是否一致,2.xSDK应对应2.x的线上环境;
如:
xmppURL: "wss://im-api.easemob.com/ws/", //小程序2.0sdk线上环境

xmppURL: 'wss://im-api-wechat.easemob.com/websocket', //3.0SDK对应的小程序线上环境

要回复问题请先登录注册

知识价值的认可,源自您的赞赏

扫描二维码,你的支付将由imGeek代收后转给对方

×