Browse Source

fix: Drops the sys message handler after used or connected.

Drops the custom type breaking xmpp protocol.
dev1
damencho 4 years ago
parent
commit
3c9913ed61
2 changed files with 38 additions and 16 deletions
  1. 3
    0
      modules/xmpp/strophe.jingle.js
  2. 35
    16
      modules/xmpp/xmpp.js

+ 3
- 0
modules/xmpp/strophe.jingle.js View File

328
      * Parses response when querying for services using urn:xmpp:extdisco:1 or urn:xmpp:extdisco:2.
328
      * Parses response when querying for services using urn:xmpp:extdisco:1 or urn:xmpp:extdisco:2.
329
      * Stores results in jvbIceConfig and p2pIceConfig.
329
      * Stores results in jvbIceConfig and p2pIceConfig.
330
      * @param res The response iq.
330
      * @param res The response iq.
331
+     * @return {boolean} Whether something was processed from the supplied message.
331
      */
332
      */
332
     onReceiveStunAndTurnCredentials(res) {
333
     onReceiveStunAndTurnCredentials(res) {
333
         const iceservers = [];
334
         const iceservers = [];
392
 
393
 
393
         this.jvbIceConfig.iceServers = iceservers.filter(filter);
394
         this.jvbIceConfig.iceServers = iceservers.filter(filter);
394
         this.p2pIceConfig.iceServers = iceservers;
395
         this.p2pIceConfig.iceServers = iceservers;
396
+
397
+        return iceservers.length > 0;
395
     }
398
     }
396
 
399
 
397
     /**
400
     /**

+ 35
- 16
modules/xmpp/xmpp.js View File

278
 
278
 
279
         this.eventEmitter.emit(XMPPEvents.CONNECTION_STATUS_CHANGED, credentials, status, msg);
279
         this.eventEmitter.emit(XMPPEvents.CONNECTION_STATUS_CHANGED, credentials, status, msg);
280
         if (status === Strophe.Status.CONNECTED || status === Strophe.Status.ATTACHED) {
280
         if (status === Strophe.Status.CONNECTED || status === Strophe.Status.ATTACHED) {
281
+            // once connected or attached we no longer need this handle, drop it if it exist
282
+            if (this._sysMessageHandler) {
283
+                this.connection._stropheConn.deleteHandler(this._sysMessageHandler);
284
+            }
285
+
281
             this.sendDiscoInfo && this.connection.jingle.getStunAndTurnCredentials();
286
             this.sendDiscoInfo && this.connection.jingle.getStunAndTurnCredentials();
282
 
287
 
283
             logger.info(`My Jabber ID: ${this.connection.jid}`);
288
             logger.info(`My Jabber ID: ${this.connection.jid}`);
491
         this.sendDiscoInfo = true;
496
         this.sendDiscoInfo = true;
492
 
497
 
493
         if (this.connection._stropheConn && this.connection._stropheConn._addSysHandler) {
498
         if (this.connection._stropheConn && this.connection._stropheConn._addSysHandler) {
494
-            this.connection._stropheConn._addSysHandler(msg => {
495
-                this.sendDiscoInfo = false;
496
-
497
-                this.connection.jingle.onReceiveStunAndTurnCredentials(msg);
498
-
499
-                const { features, identities } = parseDiscoInfo(msg);
500
-
501
-                this._processDiscoInfoIdentities(identities, features);
502
-
503
-                // check for shard name in identities
504
-                identities.forEach(i => {
505
-                    if (i.type === 'shard') {
506
-                        this.options.deploymentInfo.shard = i.name;
507
-                    }
508
-                });
509
-            }, null, 'message', 'service-info', null);
499
+            this._sysMessageHandler = this._onSystemMessage.bind(this);
500
+            this.connection._stropheConn._addSysHandler(this._sysMessageHandler, null, 'message');
510
         } else {
501
         } else {
511
             logger.warn('Cannot attach strophe system handler, jiconop cannot operate');
502
             logger.warn('Cannot attach strophe system handler, jiconop cannot operate');
512
         }
503
         }
520
             }));
511
             }));
521
     }
512
     }
522
 
513
 
514
+    /**
515
+     * Receives system messages during the connect/login process and checks for services or
516
+     * @param msg The received message.
517
+     * @returns {void}
518
+     * @private
519
+     */
520
+    _onSystemMessage(msg) {
521
+        this.sendDiscoInfo = false;
522
+
523
+        const foundIceServers = this.connection.jingle.onReceiveStunAndTurnCredentials(msg);
524
+
525
+        const { features, identities } = parseDiscoInfo(msg);
526
+
527
+        this._processDiscoInfoIdentities(identities, features);
528
+
529
+        // check for shard name in identities
530
+        identities.forEach(i => {
531
+            if (i.type === 'shard') {
532
+                this.options.deploymentInfo.shard = i.name;
533
+            }
534
+        });
535
+
536
+        if (foundIceServers || identities.size > 0 || features.size > 0) {
537
+            this.connection._stropheConn.deleteHandler(this._sysMessageHandler);
538
+            this._sysMessageHandler = null;
539
+        }
540
+    }
541
+
523
     /**
542
     /**
524
      * Attach to existing connection. Can be used for optimizations. For
543
      * Attach to existing connection. Can be used for optimizations. For
525
      * example: if the connection is created on the server we can attach to it
544
      * example: if the connection is created on the server we can attach to it

Loading…
Cancel
Save