Przeglądaj źródła

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 miesięcy temu
rodzic
commit
64dcc15c1c
No account linked to committer's email address
2 zmienionych plików z 52 dodań i 36 usunięć
  1. 43
    0
      JitsiConference.js
  2. 9
    36
      JitsiConferenceEventManager.js

+ 43
- 0
JitsiConference.js Wyświetl plik

2634
     // Do not apply the startMutedPolicy locally on the moderator, the moderator should join with available local
2634
     // Do not apply the startMutedPolicy locally on the moderator, the moderator should join with available local
2635
     // sources and the policy needs to be applied only on users that join the call after.
2635
     // sources and the policy needs to be applied only on users that join the call after.
2636
     // this.startMutedPolicy = policy;
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
     this.room.addOrReplaceInPresence('startmuted', {
2639
     this.room.addOrReplaceInPresence('startmuted', {
2638
         attributes: {
2640
         attributes: {
2639
             audio: policy.audio,
2641
             audio: policy.audio,
2641
             xmlns: 'http://jitsi.org/jitmeet/start-muted'
2643
             xmlns: 'http://jitsi.org/jitmeet/start-muted'
2642
         }
2644
         }
2643
     }) && this.room.sendPresence();
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 Wyświetl plik

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
     // Breakout rooms.
407
     // Breakout rooms.
442
     this.chatRoomForwarder.forward(XMPPEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM,
408
     this.chatRoomForwarder.forward(XMPPEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM,
443
         JitsiConferenceEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM);
409
         JitsiConferenceEvents.BREAKOUT_ROOMS_MOVE_TO_ROOM);
445
         JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED);
411
         JitsiConferenceEvents.BREAKOUT_ROOMS_UPDATED);
446
 
412
 
447
     // Room metadata.
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
 /**

Ładowanie…
Anuluj
Zapisz