1***@qq.com
1***@qq.com
  • 发布:2021-11-04 15:55
  • 更新:2021-11-05 12:02
  • 阅读:570

对接环信报on socket error

分类:uni-app
// #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
当把new WebIM.connection中的url改成wss://im-api-wechat.easemob.com后

type: 40, message: "on socket error",
type: 16, message: "websocket has been disconnected"

请问这个要怎么解决?

2021-11-04 15:55 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com (作者)

解决

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

该问题目前已经被锁定, 无法添加新回复