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

QA Handover PR #2006

Merged
merged 2 commits into from
Oct 3, 2023
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
33 changes: 19 additions & 14 deletions apps/100ms-custom-app/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { Suspense, useEffect, useRef, useState } from 'react';
import React, {
Suspense,
useCallback,
useEffect,
useRef,
useState,
} from 'react';
import { Flex, HMSPrebuilt } from '@100mslive/roomkit-react';
import { useOverridePrebuiltLayout } from './hooks/useOverridePrebuiltLayout';
import { useSearchParam } from './hooks/useSearchParam';
Expand All @@ -22,6 +28,13 @@ const App = () => {
const { roomId, role } = getRoomIdRoleFromUrl();
const { overrideLayout, isHeadless } = useOverridePrebuiltLayout();
const hmsPrebuiltRef = useRef();
const confirmLeave = useCallback(e => {
e.returnValue = 'Are you sure you want to leave?';
}, []);
const removeExitListener = useCallback(
() => window.removeEventListener('beforeunload', confirmLeave),
[]
);

useEffect(() => {
if (roomCode) {
Expand Down Expand Up @@ -54,19 +67,6 @@ const App = () => {
}
}, [authToken, role, roomCode, roomId, subdomain]);

// Prompt for page refresh/tab close
useEffect(() => {
const confirmLeave = e => {
e.returnValue = 'Are you sure you want to leave?';
};

window.addEventListener('beforeunload', confirmLeave);

return () => {
window.removeEventListener('beforeunload', confirmLeave);
};
}, []);

return (
<Flex
className="prebuilt-wrapper"
Expand All @@ -88,6 +88,11 @@ const App = () => {
authToken={authToken}
roomId={roomId}
role={role}
onLeave={removeExitListener}
onJoin={() => {
if (!isHeadless)
window.addEventListener('beforeunload', confirmLeave);
}}
screens={overrideLayout ? overrideLayout : undefined}
options={{
userName: isHeadless ? 'Beam' : undefined,
Expand Down
3 changes: 3 additions & 0 deletions packages/roomkit-react/src/Prebuilt/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type HMSPrebuiltProps = {
roomId?: string;
role?: string;
onLeave?: () => void;
onJoin?: () => void;
};

export type HMSPrebuiltRefType = {
Expand All @@ -91,6 +92,7 @@ export const HMSPrebuilt = React.forwardRef<HMSPrebuiltRefType, HMSPrebuiltProps
options: { userName = '', userId = '', endpoints } = {},
screens,
onLeave,
onJoin,
},
ref,
) => {
Expand Down Expand Up @@ -173,6 +175,7 @@ export const HMSPrebuilt = React.forwardRef<HMSPrebuiltRefType, HMSPrebuiltProps
roomId,
role,
onLeave,
onJoin,
userName,
userId,
endpoints: {
Expand Down
2 changes: 2 additions & 0 deletions packages/roomkit-react/src/Prebuilt/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type HMSPrebuiltContextType = {
userId?: string;
endpoints?: Record<string, string>;
onLeave?: () => void;
onJoin?: () => void;
};

export const HMSPrebuiltContext = React.createContext<HMSPrebuiltContextType>({
Expand All @@ -16,6 +17,7 @@ export const HMSPrebuiltContext = React.createContext<HMSPrebuiltContextType>({
userId: '',
endpoints: {},
onLeave: undefined,
onJoin: undefined,
});

HMSPrebuiltContext.displayName = 'HMSPrebuiltContext';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { APP_DATA, isAndroid, isIOS, isIPadOS } from '../common/constants';
const Conference = () => {
const navigate = useNavigate();
const { roomId, role } = useParams();
const { userName, endpoints } = useHMSPrebuiltContext();
const { userName, endpoints, onJoin: onJoinFunc } = useHMSPrebuiltContext();
const screenProps = useRoomLayoutConferencingScreen();
const { isPreviewScreenEnabled } = useRoomLayoutPreviewScreen();
const roomState = useHMSStore(selectRoomState);
Expand Down Expand Up @@ -109,6 +109,7 @@ const Conference = () => {
}, [authTokenInAppData, endpoints?.init, hmsActions, isConnectedToRoom, isPreviewScreenEnabled, roomState, userName]);

useEffect(() => {
onJoinFunc?.();
return () => {
PictureInPicture.stop().catch(error => console.error('stopping pip', error));
};
Expand Down
Loading