Skip to content

Commit

Permalink
use for of
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Oct 13, 2023
1 parent a1857de commit afb7994
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
32 changes: 21 additions & 11 deletions src/components/footer/icons/microphone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,22 @@ const MicrophoneIcon = ({ currentRoom }: IMicrophoneIconProps) => {

// for change in mic lock setting
useEffect(() => {
const closeMicOnLock = () => {
currentRoom?.localParticipant.audioTracks.forEach((publication) => {
const closeMicOnLock = async () => {
for (const [
,
publication,
] of currentRoom?.localParticipant.audioTracks.entries()) {
if (
publication.track &&
publication.source === Track.Source.Microphone
) {
currentRoom.localParticipant.unpublishTrack(publication.track, true);
await currentRoom.localParticipant.unpublishTrack(
publication.track,
true,
);
}
});
}

dispatch(updateIsActiveMicrophone(false));
dispatch(updateIsMicMuted(false));
};
Expand Down Expand Up @@ -158,8 +165,11 @@ const MicrophoneIcon = ({ currentRoom }: IMicrophoneIconProps) => {
};
}, [currentRoom]);

const muteUnmuteMic = () => {
currentRoom?.localParticipant.audioTracks.forEach(async (publication) => {
const muteUnmuteMic = async () => {
for (const [
,
publication,
] of currentRoom?.localParticipant.audioTracks.entries()) {
if (
publication.track &&
publication.track.source === Track.Source.Microphone
Expand All @@ -186,16 +196,16 @@ const MicrophoneIcon = ({ currentRoom }: IMicrophoneIconProps) => {
);
}
}
});
}
};

const manageMic = () => {
const manageMic = async () => {
if (!isActiveMicrophone && !lockMic) {
dispatch(updateShowMicrophoneModal(true));
}

if (isActiveMicrophone) {
muteUnmuteMic();
await muteUnmuteMic();
}
};

Expand Down Expand Up @@ -238,7 +248,7 @@ const MicrophoneIcon = ({ currentRoom }: IMicrophoneIconProps) => {
const audioTracks = currentRoom?.localParticipant.audioTracks;

if (audioTracks) {
audioTracks.forEach(async (publication) => {
for (const [, publication] of audioTracks.entries()) {
if (
publication.track &&
publication.track.source === Track.Source.Microphone
Expand All @@ -250,7 +260,7 @@ const MicrophoneIcon = ({ currentRoom }: IMicrophoneIconProps) => {
dispatch(updateMuteOnStart(false));
}
}
});
}
}
}, 500);
}
Expand Down
14 changes: 10 additions & 4 deletions src/components/footer/icons/screenshare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,23 @@ const ScrenshareIcon = ({ currentRoom }: IScrenshareIconProps) => {
//eslint-disable-next-line
}, [sessionScreenSharing]);

const endScreenShare = useCallback(() => {
const endScreenShare = useCallback(async () => {
if (isActiveScreenshare) {
currentRoom.localParticipant.tracks.forEach((publication) => {
for (const [
,
publication,
] of currentRoom.localParticipant.tracks.entries()) {
if (
(publication.source === Track.Source.ScreenShare ||
publication.source === Track.Source.ScreenShareAudio) &&
publication.track
) {
currentRoom.localParticipant.unpublishTrack(publication.track, true);
await currentRoom.localParticipant.unpublishTrack(
publication.track,
true,
);
}
});
}
dispatch(updateIsActiveScreenshare(false));
dispatch(
updateScreenSharing({
Expand Down
32 changes: 22 additions & 10 deletions src/components/footer/icons/webcam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,18 @@ const WebcamIcon = ({ currentRoom }: IWebcamIconProps) => {

// for change in webcam lock setting
useEffect(() => {
const closeMicOnLock = () => {
currentRoom?.localParticipant.videoTracks.forEach((publication) => {
const closeMicOnLock = async () => {
for (const [
,
publication,
] of currentRoom?.localParticipant.videoTracks.entries()) {
if (publication.track && publication.source === Track.Source.Camera) {
currentRoom.localParticipant.unpublishTrack(publication.track, true);
await currentRoom.localParticipant.unpublishTrack(
publication.track,
true,
);
}
});
}
dispatch(updateIsActiveWebcam(false));
};

Expand Down Expand Up @@ -172,7 +178,7 @@ const WebcamIcon = ({ currentRoom }: IWebcamIconProps) => {
}
};

const toggleWebcam = () => {
const toggleWebcam = async () => {
if (lockWebcam) {
return;
}
Expand All @@ -181,14 +187,20 @@ const WebcamIcon = ({ currentRoom }: IWebcamIconProps) => {
dispatch(updateShowVideoShareModal(!isActiveWebcam));
} else if (isActiveWebcam) {
// leave webcam
currentRoom.localParticipant.videoTracks.forEach(async (publication) => {
for (const [
,
publication,
] of currentRoom.localParticipant.videoTracks.entries()) {
if (
publication.track &&
publication.track.source === Track.Source.Camera
) {
currentRoom.localParticipant.unpublishTrack(publication.track, true);
await currentRoom.localParticipant.unpublishTrack(
publication.track,
true,
);
}
});
}
dispatch(updateIsActiveWebcam(false));
dispatch(updateSelectedVideoDevice(''));
dispatch(
Expand All @@ -199,7 +211,7 @@ const WebcamIcon = ({ currentRoom }: IWebcamIconProps) => {
}
};

const createDeviceStream = async (deviceId) => {
const createDeviceStream = async (deviceId: string) => {
if (virtualBackground.type === 'none') {
const resolution = getWebcamResolution();
const track = await createLocalVideoTrack({
Expand Down Expand Up @@ -231,7 +243,7 @@ const WebcamIcon = ({ currentRoom }: IWebcamIconProps) => {
return;
};

const onSelectedDevice = async (deviceId) => {
const onSelectedDevice = async (deviceId: string) => {
setDeviceId(deviceId);
await createDeviceStream(deviceId);
dispatch(updateSelectedVideoDevice(deviceId));
Expand Down

0 comments on commit afb7994

Please sign in to comment.