xmpp类库Strophe?
我使用了Strophe.js库,更改了里面的new Websocket为wx的websocket相关动作,本以为更换了套接字就ok,没想到strophe.js只能正常链接,缺没法登录验证,求解
2 回复
var me = this ; this .socket = { onopen: this ._onOpen, onmessage: this ._connect_cb_wrapper, onerror: this ._onError, onclose: this ._onClose, send: function (str) { wx.sendSocketMessage({ data: str }); }, }; function creatSocket() { if (_socketTask) { console.log( '有sockettask了。。。' ) _socketTask.close(); _socketTask = undefined; } setTimeout(() => { var SocketTask = wx.connectSocket({ url: me._conn.service, protocols: [ 'xmpp' ] // fail: function (e) { // console.log('连接失败', e) // me._conn._changeConnectStatus(Strophe.Status.CONNFAIL, null); // //部分机型从后台切回前台状态有延迟 // if (e.errMsg.indexOf('suspend') != -1) { // creatSocket() // } // }, // success: function (e) { // console.log('连接成功', e) // } }); _socketTask = SocketTask; _socketTask.onOpen( function (res) { console.log( "WebSocket 连接已打开!" ); isSocketConnnected = true // wx.sendSocketMessage({ // data: JSON.stringify({ id: '[email protected]' }), // }) me.socket.onopen.call(me); me._conn._changeConnectStatus(Strophe.Status.CONNECTED, null ); }); _socketTask.onMessage( function (msg) { //console.log("onSocketMessage", msg, JSON.stringify(msg)); me.socket.onmessage.call(me, msg); }); _socketTask.onClose( function (e) { console.log( "WebSocket 连接已经关闭!" ,e); isSocketConnnected = false me._conn.connected = true ; me.socket.onclose.call(me); // 外部回调,需要设计一个更合适的 me._onSocketClose && me._onSocketClose(e); me._conn._changeConnectStatus(Strophe.Status.DISCONNECTED, e); }); _socketTask.onError( function (e) { console.log( '出错了 出错了' ) me.socket.onclose.call(me); }) }, 1000) }
|
参照了一下环信的api。
正常情况下,会有5个消息。
现在只有一个。