Bläddra i källkod

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 år sedan
förälder
incheckning
54076e4955
1 ändrade filer med 19 tillägg och 4 borttagningar
  1. 19
    4
      modules/xmpp/XmppConnection.js

+ 19
- 4
modules/xmpp/XmppConnection.js Visa fil

35
      * @returns {boolean}
35
      * @returns {boolean}
36
      */
36
      */
37
     get connected() {
37
     get connected() {
38
-        return this._stropheConn.connected === true;
38
+        return this._status === Strophe.Status.CONNECTED;
39
     }
39
     }
40
 
40
 
41
     /**
41
     /**
119
         return this._stropheConn.service;
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
      * FIXME.
132
      * FIXME.
124
      *
133
      *
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
      * @returns {void}
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
     /**

Laddar…
Avbryt
Spara