Skip to content

Commit

Permalink
feat: add mute options
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlaz committed Oct 2, 2023
1 parent 898f38d commit c4b2ba8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const ParticipantActionsContextMenu = ({
const [pictureInPictureElement, setPictureInPictureElement] = useState(
document.pictureInPictureElement,
);
const activeCall = useCall();
const call = useCall();
const { t } = useI18n();

const { pin, publishedTracks, sessionId, userId } = participant;
Expand All @@ -152,44 +152,41 @@ export const ParticipantActionsContextMenu = ({
const hasScreenShare = publishedTracks.includes(
SfuModels.TrackType.SCREEN_SHARE,
);
const hasScreenShareAudio = publishedTracks.includes(
SfuModels.TrackType.SCREEN_SHARE_AUDIO,
);

const blockUser = () => {
activeCall?.blockUser(userId);
};
const muteAudio = () => {
activeCall?.muteUser(userId, 'audio');
};
const muteVideo = () => {
activeCall?.muteUser(userId, 'video');
};
const muteScreenShare = () => {
activeCall?.muteUser(userId, 'screenshare');
};
const blockUser = () => call?.blockUser(userId);
const muteAudio = () => call?.muteUser(userId, 'audio');
const muteVideo = () => call?.muteUser(userId, 'video');
const muteScreenShare = () => call?.muteUser(userId, 'screenshare');
const muteScreenShareAudio = () =>
call?.muteUser(userId, 'screenshare_audio');

const grantPermission = (permission: string) => () => {
activeCall?.updateUserPermissions({
call?.updateUserPermissions({
user_id: userId,
grant_permissions: [permission],
});
};

const revokePermission = (permission: string) => () => {
activeCall?.updateUserPermissions({
call?.updateUserPermissions({
user_id: userId,
revoke_permissions: [permission],
});
};

const toggleParticipantPinnedAt = () => {
if (pin) {
activeCall?.unpin(sessionId);
call?.unpin(sessionId);
} else {
activeCall?.pin(sessionId);
call?.pin(sessionId);
}
};

const pinForEveryone = () => {
activeCall
call
?.pinForEveryone({
user_id: userId,
session_id: sessionId,
Expand All @@ -200,7 +197,7 @@ export const ParticipantActionsContextMenu = ({
};

const unpinForEveryone = () => {
activeCall
call
?.unpinForEveryone({
user_id: userId,
session_id: sessionId,
Expand Down Expand Up @@ -253,10 +250,11 @@ export const ParticipantActionsContextMenu = ({
}, [videoElement]);

const togglePictureInPicture = () => {
if (videoElement && pictureInPictureElement !== videoElement)
if (videoElement && pictureInPictureElement !== videoElement) {
return videoElement
.requestPictureInPicture()
.catch(console.error) as Promise<void>;
}

document.exitPictureInPicture().catch(console.error);
};
Expand Down Expand Up @@ -308,6 +306,13 @@ export const ParticipantActionsContextMenu = ({
<Icon icon="no-audio" />
{t('Mute audio')}
</GenericMenuButtonItem>
<GenericMenuButtonItem
disabled={!hasScreenShareAudio}
onClick={muteScreenShareAudio}
>
<Icon icon="no-audio" />
{t('Mute screen share audio')}
</GenericMenuButtonItem>
</Restricted>
{participantViewElement && (
<GenericMenuButtonItem onClick={toggleFullscreenMode}>
Expand Down
1 change: 1 addition & 0 deletions packages/react-sdk/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"Turn off video": "Turn off video",
"Turn off screen share": "Turn off screen share",
"Mute audio": "Mute audio",
"Mute screen share audio": "Mute screen share audio",
"Allow audio": "Allow audio",
"Allow video": "Allow video",
"Allow screen sharing": "Allow screen sharing",
Expand Down

0 comments on commit c4b2ba8

Please sign in to comment.