mirror of
https://github.com/ianramzy/decentralized-video-chat.git
synced 2025-02-23 00:15:04 +08:00
fix video toggling and muting
This commit is contained in:
parent
9132d430af
commit
cb419b0817
@ -29,6 +29,8 @@ const chatZone = $("#chat-zone");
|
|||||||
|
|
||||||
var VideoChat = {
|
var VideoChat = {
|
||||||
nickname: undefined,
|
nickname: undefined,
|
||||||
|
videoEnabled: true,
|
||||||
|
audioEnabled: true,
|
||||||
connected: new Map(),
|
connected: new Map(),
|
||||||
localICECandidates: {},
|
localICECandidates: {},
|
||||||
socket: io(),
|
socket: io(),
|
||||||
@ -480,21 +482,23 @@ function isConnected() {
|
|||||||
|
|
||||||
// Mute microphone
|
// Mute microphone
|
||||||
function muteMicrophone() {
|
function muteMicrophone() {
|
||||||
|
VideoChat.audioEnabled = !VideoChat.audioEnabled;
|
||||||
var audioTrack = null;
|
var audioTrack = null;
|
||||||
// Get audio track to mute
|
|
||||||
VideoChat.peerConnections.first.getSenders().find(function (s) {
|
VideoChat.peerConnections.forEach(function(value, key, map) {
|
||||||
if (s.track.kind === "audio") {
|
value.getSenders().find(function (s) {
|
||||||
audioTrack = s.track;
|
if (s.track.kind === "audio") {
|
||||||
}
|
audioTrack = s.track;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
audioTrack.enabled = VideoChat.audioEnabled;
|
||||||
});
|
});
|
||||||
isMuted = !audioTrack.enabled;
|
|
||||||
audioTrack.enabled = isMuted;
|
|
||||||
isMuted = !isMuted;
|
|
||||||
// select mic button and mic button text
|
// select mic button and mic button text
|
||||||
const micButtonIcon = document.getElementById("mic-icon");
|
const micButtonIcon = document.getElementById("mic-icon");
|
||||||
const micButtonText = document.getElementById("mic-text");
|
const micButtonText = document.getElementById("mic-text");
|
||||||
// Update mute button text and icon
|
// Update mute button text and icon
|
||||||
if (isMuted) {
|
if (!VideoChat.audioEnabled) {
|
||||||
micButtonIcon.classList.remove("fa-microphone");
|
micButtonIcon.classList.remove("fa-microphone");
|
||||||
micButtonIcon.classList.add("fa-microphone-slash");
|
micButtonIcon.classList.add("fa-microphone-slash");
|
||||||
micButtonText.innerText = "Unmute";
|
micButtonText.innerText = "Unmute";
|
||||||
@ -508,21 +512,25 @@ function muteMicrophone() {
|
|||||||
|
|
||||||
// Pause Video
|
// Pause Video
|
||||||
function pauseVideo() {
|
function pauseVideo() {
|
||||||
var videoTrack = null;
|
VideoChat.videoEnabled = !VideoChat.videoEnabled;
|
||||||
// Get video track to pause
|
|
||||||
VideoChat.peerConnection.getSenders().find(function (s) {
|
// Communicate pause to all the peers' video tracks
|
||||||
if (s.track.kind === "video") {
|
VideoChat.peerConnections.forEach(function(value, key, map) {
|
||||||
videoTrack = s.track;
|
console.log("pausing video for ", key);
|
||||||
}
|
value.getSenders().find(function (s) {
|
||||||
|
if (s.track.kind === "video") {
|
||||||
|
console.log("found video track")
|
||||||
|
videoTrack = s.track;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
videoTrack.enabled = VideoChat.videoEnabled;
|
||||||
});
|
});
|
||||||
videoIsPaused = !videoTrack.enabled;
|
|
||||||
videoTrack.enabled = videoIsPaused;
|
|
||||||
videoIsPaused = !videoIsPaused;
|
|
||||||
// select video button and video button text
|
// select video button and video button text
|
||||||
const videoButtonIcon = document.getElementById("video-icon");
|
const videoButtonIcon = document.getElementById("video-icon");
|
||||||
const videoButtonText = document.getElementById("video-text");
|
const videoButtonText = document.getElementById("video-text");
|
||||||
// update pause button icon and text
|
// update pause button icon and text
|
||||||
if (videoIsPaused) {
|
if (!VideoChat.videoEnabled) {
|
||||||
localVideoText.text("Video is paused");
|
localVideoText.text("Video is paused");
|
||||||
localVideoText.show();
|
localVideoText.show();
|
||||||
videoButtonIcon.classList.remove("fa-video");
|
videoButtonIcon.classList.remove("fa-video");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user