Skip to content

Commit

Permalink
Fixed edge case which allowed multiple screen share.
Browse files Browse the repository at this point in the history
  • Loading branch information
BhumiSalat committed Mar 27, 2024
1 parent 71d34a3 commit ba75934
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions src/meetingContainer/TopBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,19 +441,52 @@ const WhiteBoardBTN = ({ onClick, isMobile, isTab }) => {
};
const ScreenShareBTN = ({ onClick, isMobile, isTab }) => {
const mMeeting = useMeeting({});
const { whiteboardStarted, appTheme } = useMeetingAppContext();
const {
whiteboardStarted,
appTheme,
notificationSoundEnabled,
notificationAlertsEnabled,
} = useMeetingAppContext();
const { enqueueSnackbar } = useSnackbar();

const theme = useTheme();

const localScreenShareOn = mMeeting?.localScreenShareOn;
const presenterId = mMeeting?.presenterId;
const presenterIdRef = useRef(presenterId);

useEffect(() => {
presenterIdRef.current = presenterId;
}, [presenterId]);

const { getCustomScreenShareTrack } = useCustomTrack();

const toggleScreenShare = async () => {
let track;
if (!localScreenShareOn) track = await getCustomScreenShareTrack();
// console.log("screneshare ", track);
mMeeting?.toggleScreenShare(track);

if (presenterIdRef.current) {
let participantName = null;
mMeeting.participants.forEach((participant) => {
if (participant.id === presenterIdRef.current) {
participantName = participant.displayName;
}
});

if (notificationSoundEnabled) {
new Audio(
`https://static.videosdk.live/prebuilt/notification.mp3`
).play();
}

if (notificationAlertsEnabled) {
enqueueSnackbar(
`Screen sharing unavailable: ${participantName} is currently presenting.`
);
}
} else {
mMeeting?.toggleScreenShare(track);
}
};

return isMobile || isTab ? (
Expand All @@ -474,9 +507,9 @@ const ScreenShareBTN = ({ onClick, isMobile, isTab }) => {
}
isFocused={localScreenShareOn}
Icon={ScreenShare}
onClick={() => {
onClick={async () => {
await toggleScreenShare();
typeof onClick === "function" && onClick();
toggleScreenShare();
}}
disabled={
RDDIsMobile || RDDIsTablet
Expand Down Expand Up @@ -2195,6 +2228,7 @@ const TopBar = ({ topBarHeight }) => {
};

const handleCloseFAB = () => {
console.log("asdas");
setOpen(false);
};

Expand Down

0 comments on commit ba75934

Please sign in to comment.