瀏覽代碼

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 5 年之前
父節點
當前提交
4e940127ce
共有 3 個檔案被更改,包括 18 行新增31 行删除
  1. 9
    9
      modules/connectivity/IceFailedHandling.js
  2. 0
    1
      modules/connectivity/IceFailedHandling.spec.js
  3. 9
    21
      modules/xmpp/xmpp.js

+ 9
- 9
modules/connectivity/IceFailedHandling.js 查看文件

91
             }, 15000);
91
             }, 15000);
92
             this._delayedIceFailedEvent.start();
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
             return;
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
         this._conference.xmpp.ping(65000).then(
106
         this._conference.xmpp.ping(65000).then(
107
             () => {
107
             () => {
108
                 if (this._canceled) {
108
                 if (this._canceled) {

+ 0
- 1
modules/connectivity/IceFailedHandling.spec.js 查看文件

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

+ 9
- 21
modules/xmpp/xmpp.js 查看文件

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
             // FIXME no need to do it again on stream resume
224
             // FIXME no need to do it again on stream resume
234
             this.caps.getFeaturesAndIdentities(pingJid)
225
             this.caps.getFeaturesAndIdentities(pingJid)
235
                 .then(({ features, identities }) => {
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
                     // check for speakerstats
236
                     // check for speakerstats
244
                     identities.forEach(identity => {
237
                     identities.forEach(identity => {
245
                         if (identity.type === 'speakerstats') {
238
                         if (identity.type === 'speakerstats') {
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
      * @param timeout how many ms before a timeout should occur.
530
      * @param timeout how many ms before a timeout should occur.
539
      * @returns {Promise} resolved on ping success and reject on an error or
531
      * @returns {Promise} resolved on ping success and reject on an error or
540
      * a timeout.
532
      * a timeout.
541
      */
533
      */
542
     ping(timeout) {
534
     ping(timeout) {
543
         return new Promise((resolve, reject) => {
535
         return new Promise((resolve, reject) => {
544
-            if (this.isPingSupported()) {
545
-                this.connection.ping
536
+            this.connection.ping
546
                     .ping(this.connection.domain, resolve, reject, timeout);
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
 

Loading…
取消
儲存