fix mute + pause after screen share

This commit is contained in:
Ian Ramzy 2020-04-02 17:19:58 -04:00
parent 94be316cf1
commit 53604d4b49

View File

@ -1,4 +1,6 @@
// Vars // Vars
var isMuted;
var videoIsPaused;
var dataChanel = null; var dataChanel = null;
const browserName = getBrowserName(); const browserName = getBrowserName();
const url = window.location.href; const url = window.location.href;
@ -410,12 +412,22 @@ function openFullscreen() {
// //
// Mute microphone // Mute microphone
// //
function muteMicrophone() { function muteMicrophone() {
var muted = VideoChat.localStream.getAudioTracks()[0].enabled; var audioTrack = null;
VideoChat.localStream.getAudioTracks()[0].enabled = !muted; VideoChat.peerConnection.getSenders().find(function (s) {
if (s.track.kind === "audio") {
audioTrack = s.track;
}
});
isMuted = !audioTrack.enabled;
audioTrack.enabled = isMuted;
isMuted = !isMuted;
const micIcon = document.getElementById("mic-icon"); const micIcon = document.getElementById("mic-icon");
const micText = document.getElementById("mic-text"); const micText = document.getElementById("mic-text");
if (muted) { if (isMuted) {
micIcon.classList.remove("fa-microphone"); micIcon.classList.remove("fa-microphone");
micIcon.classList.add("fa-microphone-slash"); micIcon.classList.add("fa-microphone-slash");
micText.innerText = "Unmute"; micText.innerText = "Unmute";
@ -433,12 +445,20 @@ function muteMicrophone() {
// //
// Pause Video // Pause Video
// //
function pauseVideo() { function pauseVideo() {
var paused = VideoChat.localStream.getVideoTracks()[0].enabled; var videoTrack = null;
VideoChat.localStream.getVideoTracks()[0].enabled = !paused; VideoChat.peerConnection.getSenders().find(function (s) {
if (s.track.kind === "video") {
videoTrack = s.track;
}
});
videoIsPaused = !videoTrack.enabled;
videoTrack.enabled = videoIsPaused;
videoIsPaused = !videoIsPaused;
const micIcon = document.getElementById("video-icon"); const micIcon = document.getElementById("video-icon");
const micText = document.getElementById("video-text"); const micText = document.getElementById("video-text");
if (paused) { if (videoIsPaused) {
micIcon.classList.remove("fa-video"); micIcon.classList.remove("fa-video");
micIcon.classList.add("fa-video-slash"); micIcon.classList.add("fa-video-slash");
micText.innerText = "Unpause Video"; micText.innerText = "Unpause Video";
@ -475,6 +495,9 @@ function swap() {
swapIcon.classList.remove("fa-desktop"); swapIcon.classList.remove("fa-desktop");
swapIcon.classList.add("fa-camera"); swapIcon.classList.add("fa-camera");
swapText.innerText = "Share Webcam"; swapText.innerText = "Share Webcam";
if (videoIsPaused) {
pauseVideo();
}
switchStreamHelper(stream); switchStreamHelper(stream);
}); });
} else { } else {
@ -497,7 +520,7 @@ function swap() {
function switchStreamHelper(stream) { function switchStreamHelper(stream) {
let videoTrack = stream.getVideoTracks()[0]; let videoTrack = stream.getVideoTracks()[0];
if (VideoChat.connected) { if (VideoChat.connected) {
var sender = VideoChat.peerConnection.getSenders().find(function (s) { const sender = VideoChat.peerConnection.getSenders().find(function (s) {
return s.track.kind === videoTrack.kind; return s.track.kind === videoTrack.kind;
}); });
sender.replaceTrack(videoTrack); sender.replaceTrack(videoTrack);