Browse Source

fix: Checks presence editing and make sure we send only on change.

tags/v0.0.2
damencho 4 years ago
parent
commit
e83fb93d2d
4 changed files with 29 additions and 26 deletions
  1. 5
    9
      JitsiConference.js
  2. 2
    2
      modules/xmpp/Caps.js
  3. 19
    10
      modules/xmpp/ChatRoom.js
  4. 3
    5
      modules/xmpp/Lobby.js

+ 5
- 9
JitsiConference.js View File

881
  **/
881
  **/
882
 JitsiConference.prototype.sendCommand = function(name, values) {
882
 JitsiConference.prototype.sendCommand = function(name, values) {
883
     if (this.room) {
883
     if (this.room) {
884
-        this.room.addToPresence(name, values);
885
-        this.room.sendPresence();
884
+        this.room.addOrReplaceInPresence(name, values) && this.room.sendPresence();
886
     } else {
885
     } else {
887
         logger.warn('Not sending a command, room not initialized.');
886
         logger.warn('Not sending a command, room not initialized.');
888
     }
887
     }
915
  */
914
  */
916
 JitsiConference.prototype.setDisplayName = function(name) {
915
 JitsiConference.prototype.setDisplayName = function(name) {
917
     if (this.room) {
916
     if (this.room) {
918
-        this.room.addToPresence('nick', {
917
+        this.room.addOrReplaceInPresence('nick', {
919
             attributes: { xmlns: 'http://jabber.org/protocol/nick' },
918
             attributes: { xmlns: 'http://jabber.org/protocol/nick' },
920
             value: name
919
             value: name
921
-        });
922
-        this.room.sendPresence();
920
+        }) && this.room.sendPresence();
923
     }
921
     }
924
 };
922
 };
925
 
923
 
1172
         }
1170
         }
1173
     }
1171
     }
1174
     if (newTrack.isVideoTrack()) {
1172
     if (newTrack.isVideoTrack()) {
1175
-        this.removeCommand('videoType');
1176
         this.sendCommand('videoType', {
1173
         this.sendCommand('videoType', {
1177
             value: newTrack.videoType,
1174
             value: newTrack.videoType,
1178
             attributes: {
1175
             attributes: {
2370
         return;
2367
         return;
2371
     }
2368
     }
2372
     this.startMutedPolicy = policy;
2369
     this.startMutedPolicy = policy;
2373
-    this.room.addToPresence('startmuted', {
2370
+    this.room.addOrReplaceInPresence('startmuted', {
2374
         attributes: {
2371
         attributes: {
2375
             audio: policy.audio,
2372
             audio: policy.audio,
2376
             video: policy.video,
2373
             video: policy.video,
2377
             xmlns: 'http://jitsi.org/jitmeet/start-muted'
2374
             xmlns: 'http://jitsi.org/jitmeet/start-muted'
2378
         }
2375
         }
2379
-    });
2380
-    this.room.sendPresence();
2376
+    }) && this.room.sendPresence();
2381
 };
2377
 };
2382
 
2378
 
2383
 /**
2379
 /**

+ 2
- 2
modules/xmpp/Caps.js View File

162
                 });
162
                 });
163
             });
163
             });
164
 
164
 
165
-            room.addToPresence('features', { children });
165
+            room.addOrReplaceInPresence('features', { children });
166
         }
166
         }
167
     }
167
     }
168
 
168
 
235
      * @param {ChatRoom} room the room.
235
      * @param {ChatRoom} room the room.
236
      */
236
      */
237
     _fixChatRoomPresenceMap(room) {
237
     _fixChatRoomPresenceMap(room) {
238
-        room.addToPresence('c', {
238
+        room.addOrReplaceInPresence('c', {
239
             attributes: {
239
             attributes: {
240
                 xmlns: Strophe.NS.CAPS,
240
                 xmlns: Strophe.NS.CAPS,
241
                 hash: HASH,
241
                 hash: HASH,

+ 19
- 10
modules/xmpp/ChatRoom.js View File

1382
 
1382
 
1383
     /**
1383
     /**
1384
      * Adds the key to the presence map, overriding any previous value.
1384
      * Adds the key to the presence map, overriding any previous value.
1385
-     * @param key
1386
-     * @param values
1385
+     * @param key The key to add or replace.
1386
+     * @param values The new values.
1387
+     * @returns {boolean|null} <tt>true</tt> if the operation succeeded or <tt>false</tt> when no add or replce was
1388
+     * performed as the value was already there.
1387
      */
1389
      */
1388
-    addToPresence(key, values) {
1390
+    addOrReplaceInPresence(key, values) {
1389
         values.tagName = key;
1391
         values.tagName = key;
1392
+
1393
+        const matchingNodes = this.presMap.nodes.filter(node => key === node.tagName);
1394
+
1395
+        // if we have found just one, let's check is it the same
1396
+        if (matchingNodes.length === 1 && isEqual(matchingNodes[0], values)) {
1397
+            return false;
1398
+        }
1399
+
1390
         this.removeFromPresence(key);
1400
         this.removeFromPresence(key);
1391
         this.presMap.nodes.push(values);
1401
         this.presMap.nodes.push(values);
1392
         this.presenceUpdateTime = Date.now();
1402
         this.presenceUpdateTime = Date.now();
1403
+
1404
+        return true;
1393
     }
1405
     }
1394
 
1406
 
1395
     /**
1407
     /**
1515
      * @param mute
1527
      * @param mute
1516
      */
1528
      */
1517
     addAudioInfoToPresence(mute) {
1529
     addAudioInfoToPresence(mute) {
1518
-        this.addToPresence(
1530
+        return this.addOrReplaceInPresence(
1519
             'audiomuted',
1531
             'audiomuted',
1520
             {
1532
             {
1521
                 attributes: { 'xmlns': 'http://jitsi.org/jitmeet/audio' },
1533
                 attributes: { 'xmlns': 'http://jitsi.org/jitmeet/audio' },
1529
      * @param callback
1541
      * @param callback
1530
      */
1542
      */
1531
     sendAudioInfoPresence(mute, callback) {
1543
     sendAudioInfoPresence(mute, callback) {
1532
-        this.addAudioInfoToPresence(mute);
1533
-
1534
         // FIXME resend presence on CONNECTED
1544
         // FIXME resend presence on CONNECTED
1535
-        this.sendPresence();
1545
+        this.addAudioInfoToPresence(mute) && this.sendPresence();
1536
         if (callback) {
1546
         if (callback) {
1537
             callback();
1547
             callback();
1538
         }
1548
         }
1543
      * @param mute
1553
      * @param mute
1544
      */
1554
      */
1545
     addVideoInfoToPresence(mute) {
1555
     addVideoInfoToPresence(mute) {
1546
-        this.addToPresence(
1556
+        return this.addOrReplaceInPresence(
1547
             'videomuted',
1557
             'videomuted',
1548
             {
1558
             {
1549
                 attributes: { 'xmlns': 'http://jitsi.org/jitmeet/video' },
1559
                 attributes: { 'xmlns': 'http://jitsi.org/jitmeet/video' },
1556
      * @param mute
1566
      * @param mute
1557
      */
1567
      */
1558
     sendVideoInfoPresence(mute) {
1568
     sendVideoInfoPresence(mute) {
1559
-        this.addVideoInfoToPresence(mute);
1560
-        this.sendPresence();
1569
+        this.addVideoInfoToPresence(mute) && this.sendPresence();
1561
     }
1570
     }
1562
 
1571
 
1563
     /**
1572
     /**

+ 3
- 5
modules/xmpp/Lobby.js View File

153
 
153
 
154
         if (displayName) {
154
         if (displayName) {
155
             // remove previously set nickname
155
             // remove previously set nickname
156
-            this.lobbyRoom.removeFromPresence('nick');
157
-            this.lobbyRoom.addToPresence('nick', {
156
+            this.lobbyRoom.addOrReplaceInPresence('nick', {
158
                 attributes: { xmlns: 'http://jabber.org/protocol/nick' },
157
                 attributes: { xmlns: 'http://jabber.org/protocol/nick' },
159
                 value: displayName
158
                 value: displayName
160
             });
159
             });
261
 
260
 
262
                 // send our email, as we do not handle this on initial presence we need a second one
261
                 // send our email, as we do not handle this on initial presence we need a second one
263
                 if (email && !isModerator) {
262
                 if (email && !isModerator) {
264
-                    this.lobbyRoom.removeFromPresence(EMAIL_COMMAND);
265
-                    this.lobbyRoom.addToPresence(EMAIL_COMMAND, { value: email });
266
-                    this.lobbyRoom.sendPresence();
263
+                    this.lobbyRoom.addOrReplaceInPresence(EMAIL_COMMAND, { value: email })
264
+                        && this.lobbyRoom.sendPresence();
267
                 }
265
                 }
268
             });
266
             });
269
             this.lobbyRoom.addEventListener(XMPPEvents.ROOM_JOIN_ERROR, reject);
267
             this.lobbyRoom.addEventListener(XMPPEvents.ROOM_JOIN_ERROR, reject);

Loading…
Cancel
Save