Parcourir la source

ref: make XMPP ping feature mandatory

There's a plan for using ping to detect XMPP WebSocket
disconnected instead of waiting for timeouts on the network layer.

This also simplifies ICE failed handling logic.
master
paweldomas il y a 5 ans
Parent
révision
4e940127ce

+ 9
- 9
modules/connectivity/IceFailedHandling.js Voir le fichier

@@ -91,18 +91,18 @@ export default class IceFailedHandling {
91 91
             }, 15000);
92 92
             this._delayedIceFailedEvent.start();
93 93
 
94
-            return;
95
-        } else if (!this._conference.xmpp.isPingSupported()) {
96
-            // Let Jicofo know that the JVB's ICE connection has failed
97
-            logger.info('PING not supported - sending ICE failed notification immediately');
98
-            this._conference.jvbJingleSession.sendIceFailedNotification();
99
-
100 94
             return;
101 95
         }
102 96
 
103
-        // The 65 seconds are greater than the default Prosody's BOSH
104
-        // timeout of 60. This gives some time for the XMPP connection
105
-        // to recover.
97
+        //  Using xmpp.ping allows to handle both XMPP being disconnected and internet offline cases. The ping function
98
+        // uses sendIQ2 method which is resilient to XMPP connection disconnected state and will patiently wait until it
99
+        // gets reconnected.
100
+        //  This also handles the case about waiting for the internet to come back online, because ping
101
+        // will only succeed when the internet is online and then there's a chance for the ICE to recover from FAILED to
102
+        // CONNECTED which is the extra 2 second timeout after ping.
103
+        //  The 65 second timeout is given on purpose as there's no chance for XMPP to recover after 65 seconds of no
104
+        // communication with the server. Such resume attempt will result in unrecoverable conference failed event due
105
+        // to 'item-not-found' error returned by the server.
106 106
         this._conference.xmpp.ping(65000).then(
107 107
             () => {
108 108
                 if (this._canceled) {

+ 0
- 1
modules/connectivity/IceFailedHandling.spec.js Voir le fichier

@@ -82,7 +82,6 @@ describe('IceFailedHandling', () => {
82 82
         beforeEach(() => {
83 83
             mockConference.options.config.enableIceRestart = true;
84 84
             mockConference.xmpp = {
85
-                isPingSupported: () => true,
86 85
                 ping: () => Promise.resolve()
87 86
             };
88 87
             mockConference.jvbJingleSession = {

+ 9
- 21
modules/xmpp/xmpp.js Voir le fichier

@@ -178,15 +178,6 @@ export default class XMPP extends Listenable {
178 178
         }
179 179
     }
180 180
 
181
-    /**
182
-     * Returns {@code true} if the PING functionality is supported by the server
183
-     * or {@code false} otherwise.
184
-     * @returns {boolean}
185
-     */
186
-    isPingSupported() {
187
-        return this._pingSupported !== false;
188
-    }
189
-
190 181
     /**
191 182
      *
192 183
      */
@@ -233,13 +224,15 @@ export default class XMPP extends Listenable {
233 224
             // FIXME no need to do it again on stream resume
234 225
             this.caps.getFeaturesAndIdentities(pingJid)
235 226
                 .then(({ features, identities }) => {
236
-                    if (features.has(Strophe.NS.PING)) {
237
-                        this._pingSupported = true;
238
-                        this.connection.ping.startInterval(pingJid);
239
-                    } else {
240
-                        logger.warn(`Ping NOT supported by ${pingJid}`);
227
+                    if (!features.has(Strophe.NS.PING)) {
228
+                        logger.error(
229
+                            `Ping NOT supported by ${pingJid} - please enable ping in your XMPP server config`);
241 230
                     }
242 231
 
232
+                    // It counterintuitive to start ping task when it's not supported, but since PING is now mandatory
233
+                    // it's done on purpose in order to print error logs and bring more attention.
234
+                    this.connection.ping.startInterval(pingJid);
235
+
243 236
                     // check for speakerstats
244 237
                     identities.forEach(identity => {
245 238
                         if (identity.type === 'speakerstats') {
@@ -533,20 +526,15 @@ export default class XMPP extends Listenable {
533 526
     }
534 527
 
535 528
     /**
536
-     * Pings the server. Remember to check {@link isPingSupported} before using
537
-     * this method.
529
+     * Pings the server.
538 530
      * @param timeout how many ms before a timeout should occur.
539 531
      * @returns {Promise} resolved on ping success and reject on an error or
540 532
      * a timeout.
541 533
      */
542 534
     ping(timeout) {
543 535
         return new Promise((resolve, reject) => {
544
-            if (this.isPingSupported()) {
545
-                this.connection.ping
536
+            this.connection.ping
546 537
                     .ping(this.connection.domain, resolve, reject, timeout);
547
-            } else {
548
-                reject('PING operation is not supported by the server');
549
-            }
550 538
         });
551 539
     }
552 540
 

Chargement…
Annuler
Enregistrer