Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: end session should stop stream #1667

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Box, Flex } from '../../Layout';
import { Text } from '../../Text';
import { useShowStreamingUI } from '../common/hooks';

export const EndSessionContent = ({ setShowEndRoomAlert, endRoom, isModal = false }) => {
export const EndSessionContent = ({ setShowEndStreamAlert, stopStream, isModal = false }) => {
const showStreamingUI = useShowStreamingUI();
return (
<Box>
Expand All @@ -21,25 +21,33 @@ export const EndSessionContent = ({ setShowEndRoomAlert, endRoom, isModal = fals
End {showStreamingUI ? 'Stream' : 'Session'}
</Text>
{isModal ? null : (
<Box css={{ color: '$on_surface_high', ml: 'auto' }} onClick={() => setShowEndRoomAlert(false)}>
<Box css={{ color: '$on_surface_high', ml: 'auto' }} onClick={() => setShowEndStreamAlert(false)}>
<CrossIcon />
</Box>
)}
</Flex>
<Text variant="sm" css={{ color: '$on_surface_medium', mb: '$8', mt: '$4' }}>
The {showStreamingUI ? 'stream' : 'session'} will end for everyone and all the activities will stop. You can't
undo this action.
The {showStreamingUI ? 'stream' : 'session'} will end for everyone. You can't undo this action.
</Text>
<Flex align="center" justify="between" css={{ w: '100%', gap: '$8' }}>
<Button
outlined
variant="standard"
css={{ w: '100%', '@md': { display: 'none' } }}
onClick={() => setShowEndRoomAlert(false)}
onClick={() => setShowEndStreamAlert(false)}
>
Cancel
</Button>
<Button variant="danger" css={{ w: '100%' }} onClick={endRoom} id="lockRoom" data-testid="lock_end_room">
<Button
variant="danger"
css={{ w: '100%' }}
onClick={() => {
stopStream();
setShowEndStreamAlert(false);
}}
id="stopStream"
data-testid="stop_stream_btn"
>
End {showStreamingUI ? 'Stream' : 'Session'}
</Button>
</Flex>
Expand Down
24 changes: 17 additions & 7 deletions packages/roomkit-react/src/Prebuilt/components/LeaveRoom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ export const LeaveRoom = () => {
const isConnected = useHMSStore(selectIsConnectedToRoom);
const permissions = useHMSStore(selectPermissions);
const isMobile = useMedia(cssConfig.media.md);

const hmsActions = useHMSActions();
const { showLeave, onLeave } = useHMSPrebuiltContext();

const stopStream = async () => {
try {
console.log('Stopping HLS stream');
await hmsActions.stopHLSStreaming();
ToastManager.addToast({ title: 'Stopping the stream' });
} catch (e) {
console.error('Error stopping stream', e);
ToastManager.addToast({ title: 'Error in stopping the stream', type: 'error' });
}
};

const redirectToLeavePage = () => {
if (showLeave) {
if (params.role) {
Expand All @@ -39,22 +49,22 @@ export const LeaveRoom = () => {
redirectToLeavePage();
};

const endRoom = () => {
hmsActions.endRoom(false, 'End Room');
redirectToLeavePage();
};
// const endRoom = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove if not needed. wouldn't it be needed if stream is not running?

Copy link
Collaborator Author

@KaustubhKumar05 KaustubhKumar05 Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query has been resolved. End room will be needed only for webrtc. Will update

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised fix PR against main here

// hmsActions.endRoom(false, 'End Room');
// redirectToLeavePage();
// };

if (!permissions || !isConnected) {
return null;
}
return isMobile ? (
<MwebLeaveRoom leaveIconButton={LeaveIconButton} leaveRoom={leaveRoom} endRoom={endRoom} />
<MwebLeaveRoom leaveIconButton={LeaveIconButton} leaveRoom={leaveRoom} stopStream={stopStream} />
) : (
<DesktopLeaveRoom
leaveIconButton={LeaveIconButton}
menuTriggerButton={MenuTriggerButton}
leaveRoom={leaveRoom}
endRoom={endRoom}
stopStream={stopStream}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const LeaveSessionContent = ({ setShowLeaveRoomAlert, leaveRoom, isModal
>
<AlertTriangleIcon style={{ marginRight: '0.5rem' }} />
<Text variant="lg" css={{ color: 'inherit', fontWeight: '$semiBold' }}>
Leave Session
Leave
</Text>
{isModal ? null : (
<Box css={{ color: '$on_surface_high', ml: 'auto' }} onClick={() => setShowLeaveRoomAlert(false)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ export const DesktopLeaveRoom = ({
menuTriggerButton: MenuTriggerButton,
leaveIconButton: LeaveIconButton,
leaveRoom,
endRoom,
stopStream,
}) => {
const [open, setOpen] = useState(false);
const [showEndRoomAlert, setShowEndRoomAlert] = useState(false);
const [showEndStreamAlert, setShowEndStreamAlert] = useState(false);
const [showLeaveRoomAlert, setShowLeaveRoomAlert] = useState(false);
const isConnected = useHMSStore(selectIsConnectedToRoom);
const permissions = useHMSStore(selectPermissions);
const { isStreamingOn } = useRecordingStreaming();

const showStreamingUI = useShowStreamingUI();
const isHLSViewer = useIsLocalPeerHLSViewer();
const showStream = showStreamingUI && isStreamingOn;
Expand All @@ -36,7 +35,7 @@ export const DesktopLeaveRoom = ({

return (
<Fragment>
{permissions.endRoom ? (
{permissions.hlsStreaming ? (
<Flex>
<LeaveIconButton
variant="danger"
Expand Down Expand Up @@ -86,23 +85,25 @@ export const DesktopLeaveRoom = ({
css={{ p: 0 }}
/>
</Dropdown.Item>
<Dropdown.Item css={{ bg: '$alert_error_dim' }} data-testid="end_room_btn">
<LeaveCard
title={showStream ? 'End Stream' : 'End Session'}
subtitle={`The ${
showStream ? 'stream' : 'session'
} will end for everyone. You can't undo this action.`}
bg=""
titleColor="$alert_error_brighter"
subtitleColor="$alert_error_bright"
icon={<StopIcon height={24} width={24} />}
onClick={() => {
setOpen(false);
setShowEndRoomAlert(true);
}}
css={{ p: 0 }}
/>
</Dropdown.Item>
{isStreamingOn && permissions?.hlsStreaming ? (
<Dropdown.Item css={{ bg: '$alert_error_dim' }} data-testid="end_room_btn">
<LeaveCard
title={showStream ? 'End Stream' : 'End Session'}
subtitle={`The ${
showStream ? 'stream' : 'session'
} will end for everyone. You can't undo this action.`}
bg=""
titleColor="$alert_error_brighter"
subtitleColor="$alert_error_bright"
icon={<StopIcon height={24} width={24} />}
onClick={() => {
setOpen(false);
setShowEndStreamAlert(true);
}}
css={{ p: 0 }}
/>
</Dropdown.Item>
) : null}
</Dropdown.Content>
</Dropdown.Root>
</Flex>
Expand All @@ -125,11 +126,11 @@ export const DesktopLeaveRoom = ({
</LeaveIconButton>
)}

<Dialog.Root open={showEndRoomAlert} modal={false}>
<Dialog.Root open={showEndStreamAlert} modal={false}>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content css={{ w: 'min(420px, 90%)', p: '$8', bg: '$surface_dim' }}>
<EndSessionContent setShowEndRoomAlert={setShowEndRoomAlert} endRoom={endRoom} isModal />
<EndSessionContent setShowEndStreamAlert={setShowEndStreamAlert} stopStream={stopStream} isModal />
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { LeaveSessionContent } from '../../LeaveSessionContent';
import { useDropdownList } from '../../hooks/useDropdownList';
import { useIsLocalPeerHLSViewer, useShowStreamingUI } from '../../../common/hooks';

export const MwebLeaveRoom = ({ leaveIconButton: LeaveIconButton, endRoom, leaveRoom }) => {
export const MwebLeaveRoom = ({ leaveIconButton: LeaveIconButton, leaveRoom, stopStream }) => {
const [open, setOpen] = useState(false);
const [showEndRoomAlert, setShowEndRoomAlert] = useState(false);
const [showEndStreamAlert, setShowEndStreamAlert] = useState(false);
const [showLeaveRoomAlert, setShowLeaveRoomAlert] = useState(false);
const isConnected = useHMSStore(selectIsConnectedToRoom);
const permissions = useHMSStore(selectPermissions);
Expand All @@ -29,7 +29,7 @@ export const MwebLeaveRoom = ({ leaveIconButton: LeaveIconButton, endRoom, leave

return (
<Fragment>
{permissions.endRoom ? (
{permissions?.hlsStreaming ? (
<Sheet.Root open={open} onOpenChange={setOpen}>
<Sheet.Trigger asChild>
<LeaveIconButton
Expand Down Expand Up @@ -65,20 +65,22 @@ export const MwebLeaveRoom = ({ leaveIconButton: LeaveIconButton, endRoom, leave
onClick={leaveRoom}
css={{ pt: 0, mt: '$10' }}
/>
<LeaveCard
title={showStream ? 'End Stream' : 'End Session'}
subtitle={`The will end the ${
showStream ? 'stream' : 'session'
} for everyone. You can't undo this action.`}
bg="$alert_error_dim"
titleColor="$alert_error_brighter"
subtitleColor="$alert_error_bright"
icon={<StopIcon height={24} width={24} />}
onClick={() => {
setOpen(false);
setShowEndRoomAlert(true);
}}
/>
{isStreamingOn && permissions?.hlsStreaming ? (
<LeaveCard
title={showStream ? 'End Stream' : 'End Session'}
subtitle={`The will end the ${
showStream ? 'stream' : 'session'
} for everyone. You can't undo this action.`}
bg="$alert_error_dim"
titleColor="$alert_error_brighter"
subtitleColor="$alert_error_bright"
icon={<StopIcon height={24} width={24} />}
onClick={() => {
setOpen(false);
setShowEndStreamAlert(true);
}}
/>
) : null}
</Sheet.Content>
</Sheet.Root>
) : (
Expand All @@ -99,9 +101,9 @@ export const MwebLeaveRoom = ({ leaveIconButton: LeaveIconButton, endRoom, leave
</Tooltip>
</LeaveIconButton>
)}
<Sheet.Root open={showEndRoomAlert} onOpenChange={setShowEndRoomAlert}>
<Sheet.Root open={showEndStreamAlert} onOpenChange={setShowEndStreamAlert}>
<Sheet.Content css={{ bg: '$surface_dim', p: '$10', pb: '$12' }}>
<EndSessionContent setShowEndRoomAlert={setShowEndRoomAlert} endRoom={endRoom} />
<EndSessionContent setShowEndStreamAlert={setShowEndStreamAlert} stopStream={stopStream} />
</Sheet.Content>
</Sheet.Root>
{isHlsViewer ? (
Expand Down