WebRTC-Experiment
WebRTC-Experiment copied to clipboard
How to Add Mute Microphone on Confrence ?
How to Add Mute Microphone on Confrence ?
try it: https://github.com/muaz-khan/WebRTC-Experiment/issues/68
But the latest version doesn't seem to work.
Try the code below:
` var muteVideo = false, muteVoice = false; connection.onstream = function(event) { var existing = document.getElementById(event.streamid); if(existing && existing.parentNode) { existing.parentNode.removeChild(existing); }
event.mediaElement.removeAttribute('src');
event.mediaElement.removeAttribute('srcObject');
event.mediaElement.muted = true;
event.mediaElement.volume = 0;
var video = document.createElement('video');
try {
video.setAttributeNode(document.createAttribute('autoplay'));
video.setAttributeNode(document.createAttribute('playsinline'));
} catch (e) {
video.setAttribute('autoplay', true);
video.setAttribute('playsinline', true);
}
if(event.type === 'local') {
video.volume = 0;
try {
video.setAttributeNode(document.createAttribute('muted'));
} catch (e) {
video.setAttribute('muted', true);
}
connection.dontCaptureUserMedia = true;
// mute/unmute video
document.getElementById('mute-unmute-video').onclick = function() {
if (!this.muteVideo)
this.muteVideo = true;
else
this.muteVideo = false;
if (this.muteVideo) {
event.stream.mute({
video: true
});
} else {
event.stream.unmute({
video: true
});
}
console.log("this.muteVideo: %s", this.muteVideo);
};
// mute/unmute voice
document.getElementById('mute-unmute-voice').onclick = function() {
if (!this.muteVoice)
this.muteVoice = true;
else
this.muteVoice = false;
if (this.muteVoice) {
event.stream.mute({
audio: true,
});
} else {
event.stream.unmute({
audio: true,
});
}
console.log("this.muteVoice: %s", this.muteVoice);
};
}
video.srcObject = event.stream;
var width = parseInt(connection.videosContainer.clientWidth / 3) - 20;
var mediaElement = getHTMLMediaElement(video, {
title: event.userid,
buttons: ['full-screen'],
width: width,
showOnMouseEnter: false
});
connection.videosContainer.appendChild(mediaElement);
setTimeout(function() {
mediaElement.media.play();
}, 5000);
mediaElement.id = event.streamid;
}; `