浏览代码

fix(XmppConnection.connected): check the underlying websocket

..readyState to tell if the connection is connected.
dev1
paweldomas 5 年前
父节点
当前提交
d0f0e98714
共有 2 个文件被更改,包括 14 次插入1 次删除
  1. 10
    0
      modules/xmpp/MockClasses.js
  2. 4
    1
      modules/xmpp/XmppConnection.js

+ 10
- 0
modules/xmpp/MockClasses.js 查看文件

25
     constructor() {
25
     constructor() {
26
         super();
26
         super();
27
         this.sentIQs = [];
27
         this.sentIQs = [];
28
+        this._proto = {
29
+            socket: undefined
30
+        };
28
     }
31
     }
29
 
32
 
30
     /**
33
     /**
58
      * @returns {void}
61
      * @returns {void}
59
      */
62
      */
60
     simulateConnectionState(newState) {
63
     simulateConnectionState(newState) {
64
+        if (newState === Strophe.Status.CONNECTED) {
65
+            this._proto.socket = {
66
+                readyState: WebSocket.OPEN
67
+            };
68
+        } else {
69
+            this._proto.socket = undefined;
70
+        }
61
         this._connectCb(newState);
71
         this._connectCb(newState);
62
     }
72
     }
63
 
73
 

+ 4
- 1
modules/xmpp/XmppConnection.js 查看文件

88
      * @returns {boolean}
88
      * @returns {boolean}
89
      */
89
      */
90
     get connected() {
90
     get connected() {
91
-        return this._status === Strophe.Status.CONNECTED || this._status === Strophe.Status.ATTACHED;
91
+        const websocket = this._stropheConn && this._stropheConn._proto && this._stropheConn._proto.socket;
92
+
93
+        return (this._status === Strophe.Status.CONNECTED || this._status === Strophe.Status.ATTACHED)
94
+            && (!this.isUsingWebSocket || (websocket && websocket.readyState === WebSocket.OPEN));
92
     }
95
     }
93
 
96
 
94
     /**
97
     /**

正在加载...
取消
保存