Sfoglia il codice sorgente

Adds support for muting audio on the bridge.

master
paweldomas 11 anni fa
parent
commit
871c661ba9
3 ha cambiato i file con 71 aggiunte e 28 eliminazioni
  1. 35
    8
      app.js
  2. 29
    16
      moderatemuc.js
  3. 7
    4
      videolayout.js

+ 35
- 8
app.js Vedi File

37
  */
37
  */
38
 var focusedVideoSrc = null;
38
 var focusedVideoSrc = null;
39
 var mutedAudios = {};
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
 var localVideoSrc = null;
51
 var localVideoSrc = null;
42
 var flipXLocalVideo = true;
52
 var flipXLocalVideo = true;
970
  * Mutes / unmutes audio for the local participant.
980
  * Mutes / unmutes audio for the local participant.
971
  */
981
  */
972
 function toggleAudio() {
982
 function toggleAudio() {
983
+    setAudioMuted(!isAudioMuted());
984
+}
985
+
986
+/**
987
+ * Sets muted audio state for the local participant.
988
+ */
989
+function setAudioMuted(mute) {
973
     if (!(connection && connection.jingle.localAudio)) {
990
     if (!(connection && connection.jingle.localAudio)) {
991
+        preMuted = mute;
974
         // We still click the button.
992
         // We still click the button.
975
         buttonClick("#mute", "icon-microphone icon-mic-disabled");
993
         buttonClick("#mute", "icon-microphone icon-mic-disabled");
976
         return;
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
     // It is not clear what is the right way to handle multiple tracks.
1009
     // It is not clear what is the right way to handle multiple tracks.
980
     // So at least make sure that they are all muted or all unmuted and
1010
     // So at least make sure that they are all muted or all unmuted and
981
     // that we send presence just once.
1011
     // that we send presence just once.
982
     var localAudioTracks = connection.jingle.localAudio.getAudioTracks();
1012
     var localAudioTracks = connection.jingle.localAudio.getAudioTracks();
983
     if (localAudioTracks.length > 0) {
1013
     if (localAudioTracks.length > 0) {
984
-        var audioEnabled = localAudioTracks[0].enabled;
985
-
986
         for (var idx = 0; idx < localAudioTracks.length; idx++) {
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
     buttonClick("#mute", "icon-microphone icon-mic-disabled");
1023
     buttonClick("#mute", "icon-microphone icon-mic-disabled");
997
 }
1024
 }

+ 29
- 16
moderatemuc.js Vedi File

1
-/* global $, $iq, config, connection, messageHandler, Strophe, toggleAudio */
1
+/* global $, $iq, config, connection, focusJid, forceMuted, messageHandler,
2
+   setAudioMuted, Strophe, toggleAudio */
2
 /**
3
 /**
3
  * Moderate connection plugin.
4
  * Moderate connection plugin.
4
  */
5
  */
15
                                    null);
16
                                    null);
16
     },
17
     },
17
     setMute: function (jid, mute) {
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
         this.connection.sendIQ(
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
     onMute: function (iq) {
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
         var mute = $(iq).find('mute');
47
         var mute = $(iq).find('mute');
37
         if (mute.length) {
48
         if (mute.length) {
38
-            toggleAudio();
49
+            var doMuteAudio = mute.text() === "true";
50
+            setAudioMuted(doMuteAudio);
51
+            forceMuted = doMuteAudio;
39
         }
52
         }
40
         return true;
53
         return true;
41
     },
54
     },

+ 7
- 4
videolayout.js Vedi File

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

Loading…
Annulla
Salva