Selaa lähdekoodia

fix(XmppConnection.connected): check the underlying websocket

..readyState to tell if the connection is connected.
master
paweldomas 4 vuotta sitten
vanhempi
commit
d0f0e98714
2 muutettua tiedostoa jossa 14 lisäystä ja 1 poistoa
  1. 10
    0
      modules/xmpp/MockClasses.js
  2. 4
    1
      modules/xmpp/XmppConnection.js

+ 10
- 0
modules/xmpp/MockClasses.js Näytä tiedosto

@@ -25,6 +25,9 @@ export class MockStropheConnection extends Listenable {
25 25
     constructor() {
26 26
         super();
27 27
         this.sentIQs = [];
28
+        this._proto = {
29
+            socket: undefined
30
+        };
28 31
     }
29 32
 
30 33
     /**
@@ -58,6 +61,13 @@ export class MockStropheConnection extends Listenable {
58 61
      * @returns {void}
59 62
      */
60 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 71
         this._connectCb(newState);
62 72
     }
63 73
 

+ 4
- 1
modules/xmpp/XmppConnection.js Näytä tiedosto

@@ -88,7 +88,10 @@ export default class XmppConnection extends Listenable {
88 88
      * @returns {boolean}
89 89
      */
90 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
     /**

Loading…
Peruuta
Tallenna