Browse Source

fix(XmppConnection): use status instead of the connected field

The connected flag is flipped to true as soon as transport connection is
established by Strophe(such as WebSocket TCP), but it doesn't mean that
the connection is ready to send stanzas yet.
dev1
paweldomas 5 years ago
parent
commit
54076e4955
1 changed files with 19 additions and 4 deletions
  1. 19
    4
      modules/xmpp/XmppConnection.js

+ 19
- 4
modules/xmpp/XmppConnection.js View File

@@ -35,7 +35,7 @@ export default class XmppConnection {
35 35
      * @returns {boolean}
36 36
      */
37 37
     get connected() {
38
-        return this._stropheConn.connected === true;
38
+        return this._status === Strophe.Status.CONNECTED;
39 39
     }
40 40
 
41 41
     /**
@@ -119,6 +119,15 @@ export default class XmppConnection {
119 119
         return this._stropheConn.service;
120 120
     }
121 121
 
122
+    /**
123
+     * Returns the current connection status.
124
+     *
125
+     * @returns {Strophe.Status}
126
+     */
127
+    get status() {
128
+        return this._status;
129
+    }
130
+
122 131
     /**
123 132
      * FIXME.
124 133
      *
@@ -171,12 +180,18 @@ export default class XmppConnection {
171 180
     }
172 181
 
173 182
     /**
174
-     * FIXME.
183
+     * Wraps Strophe.Connection.connect method in order to intercept the connection status updates.
184
+     * See {@link Strophe.Connection.connect} for the params description.
175 185
      *
176 186
      * @returns {void}
177 187
      */
178
-    connect(...args) {
179
-        this._stropheConn.connect(...args);
188
+    connect(jid, pass, callback, ...args) {
189
+        const connectCb = (status, condition) => {
190
+            this._status = status;
191
+            callback(status, condition);
192
+        };
193
+
194
+        this._stropheConn.connect(jid, pass, connectCb, ...args);
180 195
     }
181 196
 
182 197
     /**

Loading…
Cancel
Save