Quellcode durchsuchen

Adds support for muting audio on the bridge.

master
paweldomas vor 11 Jahren
Ursprung
Commit
871c661ba9
3 geänderte Dateien mit 71 neuen und 28 gelöschten Zeilen
  1. 35
    8
      app.js
  2. 29
    16
      moderatemuc.js
  3. 7
    4
      videolayout.js

+ 35
- 8
app.js Datei anzeigen

@@ -37,6 +37,16 @@ var videoSrcToSsrc = {};
37 37
  */
38 38
 var focusedVideoSrc = null;
39 39
 var mutedAudios = {};
40
+/**
41
+ * Remembers if we were muted by the focus.
42
+ * @type {boolean}
43
+ */
44
+var forceMuted = false;
45
+/**
46
+ * Indicates if we have muted our audio before the conference has started.
47
+ * @type {boolean}
48
+ */
49
+var preMuted = false;
40 50
 
41 51
 var localVideoSrc = null;
42 52
 var flipXLocalVideo = true;
@@ -970,28 +980,45 @@ function toggleVideo() {
970 980
  * Mutes / unmutes audio for the local participant.
971 981
  */
972 982
 function toggleAudio() {
983
+    setAudioMuted(!isAudioMuted());
984
+}
985
+
986
+/**
987
+ * Sets muted audio state for the local participant.
988
+ */
989
+function setAudioMuted(mute) {
973 990
     if (!(connection && connection.jingle.localAudio)) {
991
+        preMuted = mute;
974 992
         // We still click the button.
975 993
         buttonClick("#mute", "icon-microphone icon-mic-disabled");
976 994
         return;
977 995
     }
978 996
 
997
+    if (forceMuted && !mute) {
998
+        console.info("Asking focus for unmute");
999
+        connection.moderate.setMute(connection.emuc.myroomjid, mute);
1000
+        // FIXME: wait for result before resetting muted status
1001
+        forceMuted = false;
1002
+    }
1003
+
1004
+    if (mute == isAudioMuted()) {
1005
+        // Nothing to do
1006
+        return;
1007
+    }
1008
+
979 1009
     // It is not clear what is the right way to handle multiple tracks.
980 1010
     // So at least make sure that they are all muted or all unmuted and
981 1011
     // that we send presence just once.
982 1012
     var localAudioTracks = connection.jingle.localAudio.getAudioTracks();
983 1013
     if (localAudioTracks.length > 0) {
984
-        var audioEnabled = localAudioTracks[0].enabled;
985
-
986 1014
         for (var idx = 0; idx < localAudioTracks.length; idx++) {
987
-            localAudioTracks[idx].enabled = !audioEnabled;
1015
+            localAudioTracks[idx].enabled = !mute;
988 1016
         }
989
-
990
-        // isMuted is the opposite of audioEnabled
991
-        connection.emuc.addAudioInfoToPresence(audioEnabled);
992
-        connection.emuc.sendPresence();
993
-        VideoLayout.showLocalAudioIndicator(audioEnabled);
994 1017
     }
1018
+    // isMuted is the opposite of audioEnabled
1019
+    connection.emuc.addAudioInfoToPresence(mute);
1020
+    connection.emuc.sendPresence();
1021
+    VideoLayout.showLocalAudioIndicator(audioEnabled);
995 1022
 
996 1023
     buttonClick("#mute", "icon-microphone icon-mic-disabled");
997 1024
 }

+ 29
- 16
moderatemuc.js Datei anzeigen

@@ -1,4 +1,5 @@
1
-/* global $, $iq, config, connection, messageHandler, Strophe, toggleAudio */
1
+/* global $, $iq, config, connection, focusJid, forceMuted, messageHandler,
2
+   setAudioMuted, Strophe, toggleAudio */
2 3
 /**
3 4
  * Moderate connection plugin.
4 5
  */
@@ -15,27 +16,39 @@ Strophe.addConnectionPlugin('moderate', {
15 16
                                    null);
16 17
     },
17 18
     setMute: function (jid, mute) {
18
-        var iq = $iq({to: jid, type: 'set'})
19
-                    .c('mute', {xmlns: 'http://jitsi.org/jitmeet/audio'})
20
-                    .t(mute.toString())
21
-                    .up();
19
+        console.info("set mute", mute);
20
+        var iqToFocus = $iq({to: focusJid, type: 'set'})
21
+            .c('mute', {
22
+                xmlns: 'http://jitsi.org/jitmeet/audio',
23
+                jid: jid
24
+            })
25
+            .t(mute.toString())
26
+            .up();
22 27
 
23 28
         this.connection.sendIQ(
24
-                iq,
25
-                function (result) {
26
-                    console.log('set mute', result);
27
-                },
28
-                function (error) {
29
-                    console.log('set mute error', error);
30
-                    messageHandler.openReportDialog(null, 'Failed to mute ' +
31
-                        $("#participant_" + jid).find(".displayname").text() ||
32
-                        "participant" + '.', error);
33
-                });
29
+            iqToFocus,
30
+            function (result) {
31
+                console.log('set mute', result);
32
+            },
33
+            function (error) {
34
+                console.log('set mute error', error);
35
+                // FIXME: this causes an exception
36
+                //messageHandler.openReportDialog(null, 'Failed to mute ' +
37
+                  //  $("#participant_" + jid).find(".displayname").text() ||
38
+                    //"participant" + '.', error);
39
+            });
34 40
     },
35 41
     onMute: function (iq) {
42
+        var from = iq.getAttribute('from');
43
+        if (from !== focusJid) {
44
+            console.warn("Ignored mute from non focus peer");
45
+            return false;
46
+        }
36 47
         var mute = $(iq).find('mute');
37 48
         if (mute.length) {
38
-            toggleAudio();
49
+            var doMuteAudio = mute.text() === "true";
50
+            setAudioMuted(doMuteAudio);
51
+            forceMuted = doMuteAudio;
39 52
         }
40 53
         return true;
41 54
     },

+ 7
- 4
videolayout.js Datei anzeigen

@@ -17,6 +17,10 @@ var VideoLayout = (function (my) {
17 17
         RTC.attachMediaStream($('#localAudio'), stream);
18 18
         document.getElementById('localAudio').autoplay = true;
19 19
         document.getElementById('localAudio').volume = 0;
20
+        if (preMuted) {
21
+            setAudioMuted(true);
22
+            preMuted = false;
23
+        }
20 24
     };
21 25
 
22 26
     my.changeLocalVideo = function(stream, flipX) {
@@ -1253,8 +1257,8 @@ var VideoLayout = (function (my) {
1253 1257
             if ($(this).attr('disabled') != undefined) {
1254 1258
                 event.preventDefault();
1255 1259
             }
1256
-            var isMute = !mutedAudios[jid];
1257
-            connection.moderate.setMute(jid, isMute);
1260
+            var isMute = mutedAudios[jid] == true;
1261
+            connection.moderate.setMute(jid, !isMute);
1258 1262
             popupmenuElement.setAttribute('style', 'display:none;');
1259 1263
 
1260 1264
             if (isMute) {
@@ -1349,10 +1353,9 @@ var VideoLayout = (function (my) {
1349 1353
             videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
1350 1354
         }
1351 1355
 
1352
-        VideoLayout.ensurePeerContainerExists(jid);
1356
+        mutedAudios[jid] = isMuted;
1353 1357
 
1354 1358
         if (Moderator.isModerator()) {
1355
-            mutedAudios[jid] = isMuted;
1356 1359
             VideoLayout.updateRemoteVideoMenu(jid, isMuted);
1357 1360
         }
1358 1361
 

Laden…
Abbrechen
Speichern