1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-26 02:25:58 +01:00

Implement local mute.

This commit is contained in:
Juliusz Chroboczek 2020-06-09 18:05:16 +02:00
parent 94c42ea784
commit 0308719719
3 changed files with 53 additions and 4 deletions

View file

@ -64,9 +64,17 @@ h1 {
#audioselect { #audioselect {
width: 8em; width: 8em;
text-align-last: center; text-align-last: center;
}
#mutebutton {
width: 6em;
margin-right: 0.4em; margin-right: 0.4em;
} }
.muted {
color: red;
}
#sharebutton, #unsharebutton { #sharebutton, #unsharebutton {
width: 8em; width: 8em;
white-space: nowrap; white-space: nowrap;

View file

@ -44,6 +44,7 @@
<option>default</option> <option>default</option>
<option>off</option> <option>off</option>
</select> </select>
<button id="mutebutton">Mute</button>
</span> </span>
<button id="sharebutton" class="invisible">Share screen</button> <button id="sharebutton" class="invisible">Share screen</button>

View file

@ -170,16 +170,38 @@ function setButtonsVisibility() {
setVisibility('mediaoptions', permissions.present); setVisibility('mediaoptions', permissions.present);
} }
document.getElementById('audioselect').onchange = function(e) { let localMute = false;
e.preventDefault();
changePresentation(); function toggleLocalMute() {
}; setLocalMute(!localMute);
}
function setLocalMute(mute) {
localMute = mute;
muteLocalTracks(localMute);
let button = document.getElementById('mutebutton');
button.textContent = localMute ? 'Unmute' : 'Mute';
if(localMute)
button.classList.add('muted');
else
button.classList.remove('muted');
}
document.getElementById('videoselect').onchange = function(e) { document.getElementById('videoselect').onchange = function(e) {
e.preventDefault(); e.preventDefault();
changePresentation(); changePresentation();
}; };
document.getElementById('audioselect').onchange = function(e) {
e.preventDefault();
changePresentation();
};
document.getElementById('mutebutton').onclick = function(e) {
e.preventDefault();
toggleLocalMute();
}
document.getElementById('sharebutton').onclick = function(e) { document.getElementById('sharebutton').onclick = function(e) {
e.preventDefault(); e.preventDefault();
addShareMedia(); addShareMedia();
@ -349,6 +371,8 @@ async function addLocalMedia() {
c.stream = stream; c.stream = stream;
stream.getTracks().forEach(t => { stream.getTracks().forEach(t => {
c.labels[t.id] = t.kind c.labels[t.id] = t.kind
if(t.kind == 'audio' && localMute)
t.enabled = false;
let sender = c.pc.addTrack(t, stream); let sender = c.pc.addTrack(t, stream);
c.setInterval(() => { c.setInterval(() => {
updateStats(c, sender); updateStats(c, sender);
@ -428,6 +452,20 @@ function findUpMedia(kind) {
return false; return false;
} }
function muteLocalTracks(mute) {
for(let id in up) {
let c = up[id];
if(c.kind === 'local') {
let stream = c.stream;
stream.getTracks().forEach(t => {
if(t.kind === 'audio') {
t.enabled = !mute;
}
});
}
}
}
function setMedia(id) { function setMedia(id) {
let mine = true; let mine = true;
let c = up[id]; let c = up[id];
@ -1194,6 +1232,8 @@ function start() {
document.getElementById('title').textContent = title; document.getElementById('title').textContent = title;
} }
setLocalMute(localMute);
myid = randomid(); myid = randomid();
getIceServers().catch(console.error).then(c => { getIceServers().catch(console.error).then(c => {