Browse Source

feat(startMutedPolicy): Uses metadata for startMuted policy. (#2759)

* feat(startMutedPolicy): Uses metadata for startMuted policy.

* squash: Make sure we add boolean.

* squash: Fix lint.

* squash: Ignore policy when set locally.

* squash: Adds a comment.

* squash: Fix lint errors.
dev0
Дамян Минков 6 months ago
parent
commit
64dcc15c1c
No account linked to committer's email address
2 changed files with 52 additions and 36 deletions
  1. 43
    0
      JitsiConference.js
  2. 9
    36
      JitsiConferenceEventManager.js

+ 43
- 0
JitsiConference.js View File

@@ -2634,6 +2634,8 @@ JitsiConference.prototype.setStartMutedPolicy = function(policy) {
2634 2634
     // Do not apply the startMutedPolicy locally on the moderator, the moderator should join with available local
2635 2635
     // sources and the policy needs to be applied only on users that join the call after.
2636 2636
     // this.startMutedPolicy = policy;
2637
+    // TODO: to remove using presence for startmuted policy after old clients update
2638
+    // we keep presence to update UI of old clients
2637 2639
     this.room.addOrReplaceInPresence('startmuted', {
2638 2640
         attributes: {
2639 2641
             audio: policy.audio,
@@ -2641,6 +2643,47 @@ JitsiConference.prototype.setStartMutedPolicy = function(policy) {
2641 2643
             xmlns: 'http://jitsi.org/jitmeet/start-muted'
2642 2644
         }
2643 2645
     }) && this.room.sendPresence();
2646
+
2647
+    // we want to ignore applying startMutedPolicy locally when we set it
2648
+    this._ignoreFirstStartMutedPolicyUpdate = true;
2649
+
2650
+    this.getMetadataHandler().setMetadata('startMuted', {
2651
+        audio: policy.audio,
2652
+        video: policy.video
2653
+    });
2654
+};
2655
+
2656
+/**
2657
+ * Updates conference startMuted policy if needed and fires an event.
2658
+ *
2659
+ * @param {boolean} audio if audio should be muted.
2660
+ * @param {boolean} video if video should be muted.
2661
+ */
2662
+JitsiConference.prototype._updateStartMutedPolicy = function(audio, video) {
2663
+    if (this._ignoreFirstStartMutedPolicyUpdate) {
2664
+        this._ignoreFirstStartMutedPolicyUpdate = false;
2665
+
2666
+        return;
2667
+    }
2668
+
2669
+    let updated = false;
2670
+
2671
+    if (audio !== this.startMutedPolicy.audio) {
2672
+        this.startMutedPolicy.audio = audio;
2673
+        updated = true;
2674
+    }
2675
+
2676
+    if (video !== this.startMutedPolicy.video) {
2677
+        this.startMutedPolicy.video = video;
2678
+        updated = true;
2679
+    }
2680
+
2681
+    if (updated) {
2682
+        this.eventEmitter.emit(
2683
+            JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
2684
+            this.startMutedPolicy
2685
+        );
2686
+    }
2644 2687
 };
2645 2688
 
2646 2689
 /**

+ 9
- 36
JitsiConferenceEventManager.js View File

@@ -404,40 +404,6 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
404 404
             }
405 405
         });
406 406
 
407
-    chatRoom.addPresenceListener('startmuted', (data, from) => {
408
-        // Ignore the strartmuted policy if the presence is received from self. The moderator should join with
409
-        // available local sources and the policy needs to be applied only on users that join the call after.
410
-        if (conference.myUserId() === from) {
411
-            return;
412
-        }
413
-        const participant = conference.getParticipantById(from);
414
-
415
-        if (!participant || !participant.isModerator()) {
416
-            return;
417
-        }
418
-        const startAudioMuted = data.attributes.audio === 'true';
419
-        const startVideoMuted = data.attributes.video === 'true';
420
-
421
-        let updated = false;
422
-
423
-        if (startAudioMuted !== conference.startMutedPolicy.audio) {
424
-            conference.startMutedPolicy.audio = startAudioMuted;
425
-            updated = true;
426
-        }
427
-
428
-        if (startVideoMuted !== conference.startMutedPolicy.video) {
429
-            conference.startMutedPolicy.video = startVideoMuted;
430
-            updated = true;
431
-        }
432
-
433
-        if (updated) {
434
-            conference.eventEmitter.emit(
435
-                JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
436
-                conference.startMutedPolicy
437
-            );
438
-        }
439
-    });
440
-
441 407
     // Breakout rooms.
442 408
     this.chatRoomForwarder.forward(XMPPEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM,
443 409
         JitsiConferenceEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM);
@@ -445,8 +411,15 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
445 411
         JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED);
446 412
 
447 413
     // Room metadata.
448
-    this.chatRoomForwarder.forward(XMPPEvents.ROOM_METADATA_UPDATED,
449
-        JitsiConferenceEvents.METADATA_UPDATED);
414
+    chatRoom.addListener(XMPPEvents.ROOM_METADATA_UPDATED, metadata => {
415
+        if (metadata.startMuted) {
416
+            conference._updateStartMutedPolicy(
417
+                metadata.startMuted.audio || false,
418
+                metadata.startMuted.video || false
419
+            );
420
+        }
421
+        conference.eventEmitter.emit(JitsiConferenceEvents.METADATA_UPDATED, metadata);
422
+    });
450 423
 };
451 424
 
452 425
 /**

Loading…
Cancel
Save