Skip to content
Merged
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
23 changes: 23 additions & 0 deletions packages/shared/src/components/liveRooms/LiveRoom.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ const createContextValue = (
},
role: 'host',
participantId: 'host',
disconnect: jest.fn().mockResolvedValue(undefined),
preflightMediaPermissions: jest.fn(),
startRoom: jest.fn(),
endRoom: jest.fn(),
Expand Down Expand Up @@ -415,6 +416,28 @@ describe('LiveRoom', () => {
expect(screen.getByText('tile-speaker2')).toBeInTheDocument();
});

it('disconnects before navigating home from the ended standup state', async () => {
const disconnect = jest.fn().mockResolvedValue(undefined);
mockUseLiveRoomConnection.mockReturnValue(
createContextValue({
disconnect,
roomState: {
...createContextValue().roomState!,
status: 'ended',
},
}),
);

renderLiveRoom();

fireEvent.click(screen.getByRole('button', { name: 'Back home' }));

await waitFor(() => {
expect(disconnect).toHaveBeenCalledTimes(1);
expect(mockPush).toHaveBeenCalledWith('/');
});
});

it('passes raised hand queue positions to matching stage tiles', () => {
mockUseLiveRoomConnection.mockReturnValue(
createContextValue({
Expand Down
12 changes: 8 additions & 4 deletions packages/shared/src/components/liveRooms/LiveRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import useLogEventOnce from '../../hooks/log/useLogEventOnce';
import { useToastNotification } from '../../hooks/useToastNotification';
import { useExitConfirmation } from '../../hooks/useExitConfirmation';
import { useViewSize, ViewSize } from '../../hooks';
import { clearStoredLiveRoomResumeSession } from '../../lib/liveRoom/resumeSessionStorage';
import { useLiveRoomSubscription } from '../../hooks/liveRooms/useLiveRoomSubscription';
import { usePushNotificationContext } from '../../contexts/PushNotificationContext';
import { usePushNotificationMutation } from '../../hooks/notifications/usePushNotificationMutation';
Expand Down Expand Up @@ -73,6 +72,7 @@ const LiveRoomInner = ({ roomId }: LiveRoomProps): ReactElement => {
roomState,
role,
participantId,
disconnect,
sendChatMessage,
deleteChatMessage,
sendChatMessageReaction,
Expand Down Expand Up @@ -135,10 +135,14 @@ const LiveRoomInner = ({ roomId }: LiveRoomProps): ReactElement => {
videoSettings,
});

const handleLeave = (): void => {
const navigateHome = useCallback(async (): Promise<void> => {
onAskConfirmation(false);
clearStoredLiveRoomResumeSession(roomId);
router.push('/');
await disconnect();
await router.push('/');
}, [disconnect, onAskConfirmation, router]);

const handleLeave = (): void => {
navigateHome().catch(() => undefined);
};
const handleNavigateBack = (surface: string): void => {
logStandupAction(LogEvent.LeaveStandup, roomId, { surface });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const createContextValue = (
},
role: 'audience',
participantId: 'audience',
disconnect: jest.fn().mockResolvedValue(undefined),
preflightMediaPermissions: jest.fn(),
startRoom: jest.fn(),
endRoom: jest.fn(),
Expand Down
24 changes: 24 additions & 0 deletions packages/shared/src/contexts/LiveRoomContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export interface LiveRoomContextValue {
role: LiveRoomParticipantRoleValue | null;
participantId: string | null;

disconnect: () => Promise<void>;
preflightMediaPermissions: () => Promise<void>;
startRoom: () => Promise<void>;
endRoom: () => Promise<void>;
Expand Down Expand Up @@ -450,6 +451,7 @@ export const LiveRoomProvider = ({
recv: false,
});
const mediaRebuildQueuedRef = useRef(false);
const intentionalDisconnectRef = useRef(false);
const currentRole =
(participantId && roomState?.participants[participantId]?.role) || role;
const privilegeState = getLiveRoomPrivilegeState(
Expand Down Expand Up @@ -691,6 +693,19 @@ export const LiveRoomProvider = ({
setIsMicOn(false);
}, []);

const disconnect = useCallback(async () => {
intentionalDisconnectRef.current = true;
clearStoredLiveRoomResumeSession(roomId);
setStoredResumeSession(null);
setResumeSessionTtlMs(null);
setErrorMessage(null);
setStatus('idle');
closeMediaSession(true);
stopLocalCapture();
connectionRef.current?.close();
connectionRef.current = null;
}, [closeMediaSession, roomId, stopLocalCapture]);

const queueMediaRebuild = useCallback(() => {
if (mediaRebuildQueuedRef.current || status !== 'connected') {
return;
Expand Down Expand Up @@ -1064,6 +1079,7 @@ export const LiveRoomProvider = ({
: { token: joinToken?.token ?? '' }),
});
connectionRef.current = connection;
intentionalDisconnectRef.current = false;
setStatus('connecting');
setErrorMessage(null);
const openingWithResume = !!storedResumeSession;
Expand Down Expand Up @@ -1114,6 +1130,9 @@ export const LiveRoomProvider = ({
},
);
const offClose = connection.onClose(({ code, reason }) => {
if (intentionalDisconnectRef.current) {
return;
}
if (openingWithResume && !sessionReady) {
requestFreshJoinToken();
return;
Expand All @@ -1126,6 +1145,9 @@ export const LiveRoomProvider = ({
setErrorMessage(reason || 'Standup connection closed');
});
const offError = connection.onError((error) => {
if (intentionalDisconnectRef.current) {
return;
}
if (openingWithResume && !sessionReady) {
return;
}
Expand Down Expand Up @@ -2163,6 +2185,7 @@ export const LiveRoomProvider = ({
roomState,
role: currentRole,
participantId,
disconnect,
preflightMediaPermissions,
startRoom,
endRoom,
Expand Down Expand Up @@ -2212,6 +2235,7 @@ export const LiveRoomProvider = ({
roomState,
currentRole,
participantId,
disconnect,
preflightMediaPermissions,
startRoom,
endRoom,
Expand Down
Loading