uniapp对接环信报on socket error

// #ifdef H5  
import websdk from "@/utils/lib/WebIM/Easemob-chat-3.6.3.js";  
// #endif  
// #ifndef H5  
import websdk from "@/utils/lib/WebIM/uni_sdk3.6.3.js";  
// #endif  

var WebIM = {};  
WebIM = (window||wx).WebIM = websdk;  

WebIM.conn = new WebIM.connection({  
        appKey: .........,  
        isHttpDNS: false,  
        isMultiLoginSessions: true,  
        https: true,  
        url: 'http://im-api-v2.easemob.com/ws',  
        apiUrl: 'http://a1.easemob.com',  
        isAutoLogin: true,  
        heartBeatWait: 30000,  
        autoReconnectNumMax: 5,  
        autoReconnectInterval: 2,  
        isStropheLog: false,  
        delivery: true,  
        useOwnUploadFun: false  
})  
WebIM.conn.listen({  
        //连接成功回调  
        onOpened: function(message) {  
                console.log('连接成功', message)  
        },  
        //失败回调  
        onError: function(message) {  
                console.log("失败回调", message);  
        })  
})  

WebIM.conn.open({  
        apiUrl: ....,  
        user: ....,  
        pwd: ....,  
        appKey: ....  
})

大概流程就是这样子

在H5中连接成功

app中报
失败回调,{"type":40,"message":"on socket error","data":{},"failMsgs":{}}

小程序报
VM221:1 MiniProgramError
Cannot read property 'onOpen' of undefined
TypeError: Cannot read property 'onOpen' of undefined

请问这个要怎么解决?

阅读 3.2k
1 个回答

解决

new WebIM.connection中的url配置

// #ifdef H5

xmppURL: "http://im-api-v2.easemob.com/ws",
// #endif
// #ifndef H5
xmppURL: "wss://im-api-wechat.easemob.com/websocket",
// #endif
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题