Skip to content

Commit

Permalink
Merge branch 'dev' into test/video-pause
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 authored May 21, 2024
2 parents d2f1b01 + 377e5b4 commit 5d212a5
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 147 deletions.
2 changes: 0 additions & 2 deletions packages/roomkit-react/src/Prebuilt/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { parsedUserAgent } from '@100mslive/react-sdk';

export const DEFAULT_WAITING_VIEWER_ROLE = 'waiting-room';
export const QUERY_PARAM_SKIP_PREVIEW = 'skip_preview';
export const QUERY_PARAM_SKIP_PREVIEW_HEADFUL = 'skip_preview_headful';
export const QUERY_PARAM_NAME = 'name';
Expand Down Expand Up @@ -30,7 +29,6 @@ export const APP_DATA = {
appConfig: 'appConfig',
sidePane: 'sidePane',
hlsStats: 'hlsStats',
waitingViewerRole: 'waitingViewerRole',
subscribedNotifications: 'subscribedNotifications',
logo: 'logo',
hlsStarted: 'hlsStarted',
Expand Down
35 changes: 34 additions & 1 deletion packages/roomkit-react/src/Prebuilt/common/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useMedia } from 'react-use';
import { HMSHLSPlayer } from '@100mslive/hls-player';
import { JoinForm_JoinBtnType } from '@100mslive/types-prebuilt/elements/join_form';
import {
HMSPeer,
HMSRecording,
parsedUserAgent,
selectAvailableRoleNames,
selectIsAllowedToPublish,
selectIsConnectedToRoom,
selectLocalPeerRole,
selectPeerCount,
selectPeerMetadata,
selectPeers,
selectPeersByRoles,
selectRecordingState,
selectRemotePeers,
selectRolesMap,
useHMSActions,
useHMSStore,
useHMSVanillaStore,
Expand Down Expand Up @@ -218,3 +223,31 @@ export function getResolution(
}
return resolution;
}

export interface WaitingRoomInfo {
isNotAllowedToPublish: boolean;
isScreenOnlyPublishParams: boolean;
hasSubscribedRolePublishing: boolean;
}
export function useWaitingRoomInfo(): WaitingRoomInfo {
const localPeerRole = useHMSStore(selectLocalPeerRole);
const { video, audio, screen } = useHMSStore(selectIsAllowedToPublish);
const roles = useHMSStore(selectRolesMap);
const peersByRoles = useHMSStore(selectPeersByRoles(localPeerRole?.subscribeParams.subscribeToRoles || []));
const isNotAllowedToPublish = video && audio && screen;
const isScreenOnlyPublishParams: boolean = screen;
const hasSubscribedRolePublishing: boolean = useMemo(() => {
return peersByRoles.some((peer: HMSPeer) => {
if (peer.roleName && roles[peer.roleName] && !peer.isLocal) {
return !!roles[peer.roleName].publishParams?.allowed.length;
}
return false;
});
}, [peersByRoles, roles]);

return {
isNotAllowedToPublish,
isScreenOnlyPublishParams,
hasSubscribedRolePublishing,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { useSetAppDataByKey } from './useUISettings';
import {
APP_DATA,
CHAT_SELECTOR,
DEFAULT_WAITING_VIEWER_ROLE,
POLL_STATE,
SIDE_PANE_OPTIONS,
UI_MODE_GRID,
Expand Down Expand Up @@ -56,7 +55,6 @@ const initialAppData = {
[APP_DATA.hlsStarted]: false,
[APP_DATA.rtmpStarted]: false,
[APP_DATA.recordingStarted]: false,
[APP_DATA.waitingViewerRole]: DEFAULT_WAITING_VIEWER_ROLE,
[APP_DATA.dropdownList]: [],
[APP_DATA.authToken]: '',
[APP_DATA.minimiseInset]: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ export const useSetUiSettings = uiSettingKey => {
return [value, setValue];
};

export const useWaitingViewerRole = () => {
return useHMSStore(selectAppData(APP_DATA.waitingViewerRole));
};
export const useIsHLSStartedFromUI = () => {
return useHMSStore(selectAppData(APP_DATA.hlsStarted));
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useEffect, useMemo, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { useMedia } from 'react-use';
import { selectLocalPeer, useHMSStore } from '@100mslive/react-sdk';
import { PeopleAddIcon } from '@100mslive/react-icons';
import { Flex } from '../../../Layout';
import { config as cssConfig } from '../../../Theme';
import { WaitingView } from '../../layouts/WaitingView';
import { InsetTile } from '../InsetTile';
import { Pagination } from '../Pagination';
import { Grid } from './Grid';
Expand All @@ -13,26 +14,14 @@ import { usePagesWithTiles, useTileLayout } from '../hooks/useTileLayout';
import { UI_SETTINGS } from '../../common/constants';

export function EqualProminence({ isInsetEnabled = false, peers, onPageChange, onPageSize, edgeToEdge }: LayoutProps) {
const localPeer = useHMSStore(selectLocalPeer);
const isMobile = useMedia(cssConfig.media.md);
let maxTileCount = useUISettings(UI_SETTINGS.maxTileCount);
maxTileCount = isMobile ? Math.min(maxTileCount, 6) : maxTileCount;
let pageList = usePagesWithTiles({
const pageList = usePagesWithTiles({
peers,
maxTileCount,
});
// useMemo is needed to prevent recursion as new array is created for localPeer
const inputPeers = useMemo(() => {
if (pageList.length === 0) {
return localPeer ? [localPeer] : [];
}
return peers;
}, [pageList.length, peers, localPeer]);
// Pass local peer to main grid if no other peer has tiles
pageList = usePagesWithTiles({
peers: inputPeers,
maxTileCount,
});

const { ref, pagesWithTiles } = useTileLayout({
pageList,
maxTileCount,
Expand Down Expand Up @@ -60,7 +49,14 @@ export function EqualProminence({ isInsetEnabled = false, peers, onPageChange, o
numPages={pagesWithTiles.length}
/>
)}
{isInsetEnabled && pageList.length > 0 && pageList[0][0].peer.id !== localPeer?.id && <InsetTile />}
{pageList.length === 0 ? (
<WaitingView
title="Waiting for Host to join"
subtitle="Sit back and relax till others join"
icon={<PeopleAddIcon width="56px" height="56px" style={{ color: 'white' }} />}
/>
) : null}
{isInsetEnabled && <InsetTile />}
</Flex>
);
}
25 changes: 14 additions & 11 deletions packages/roomkit-react/src/Prebuilt/layouts/HLSView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Loading } from '../../Loading';
import { Text } from '../../Text';
import { config, theme, useTheme } from '../../Theme';
import { Tooltip } from '../../Tooltip';
import { WaitingView } from './WaitingView';
import { useSidepaneToggle } from '../components/AppData/useSidepane';
import { useRoomLayoutConferencingScreen } from '../provider/roomLayoutProvider/hooks/useRoomLayoutScreen';
import { useIsLandscape, useKeyboardHandler } from '../common/hooks';
Expand Down Expand Up @@ -457,17 +458,19 @@ const HLSView = () => {
flex: isLandscape ? '2 1 0' : '1 1 0',
}}
>
<Flex align="center" justify="center" direction="column" css={{ size: '100%', px: '$10' }}>
<Flex css={{ c: '$on_surface_high', r: '$round', bg: '$surface_default', p: '$2' }}>
{streamEnded ? <ColoredHandIcon height={56} width={56} /> : <GoLiveIcon height={56} width={56} />}
</Flex>
<Text variant="h5" css={{ c: '$on_surface_high', mt: '$10', mb: 0, textAlign: 'center' }}>
{streamEnded ? 'Stream has ended' : 'Stream yet to start'}
</Text>
<Text variant="md" css={{ textAlign: 'center', mt: '$4', c: '$on_surface_medium' }}>
{streamEnded ? 'Have a nice day!' : 'Sit back and relax'}
</Text>
</Flex>
{streamEnded ? (
<WaitingView
icon={<ColoredHandIcon height={56} width={56} />}
title="Stream has ended"
subtitle="Have a nice day!"
/>
) : (
<WaitingView
icon={<GoLiveIcon height={56} width={56} style={{ color: 'white' }} />}
title="Stream yet to start"
subtitle="Sit back and relax"
/>
)}
</Flex>
</>
);
Expand Down
51 changes: 0 additions & 51 deletions packages/roomkit-react/src/Prebuilt/layouts/NonPublisherView.jsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import {
HLSLiveStreamingScreen_Elements,
} from '@100mslive/types-prebuilt';
import { match } from 'ts-pattern';
import { selectIsConnectedToRoom, selectLocalPeerRoleName, useHMSActions, useHMSStore } from '@100mslive/react-sdk';
import {
selectIsConnectedToRoom,
selectIsLocalScreenShared,
selectLocalPeerRoleName,
useHMSActions,
useHMSStore,
} from '@100mslive/react-sdk';
import { PeopleAddIcon, ShareScreenIcon } from '@100mslive/react-icons';
import FullPageProgress from '../components/FullPageProgress';
import { GridLayout } from '../components/VideoLayouts/GridLayout';
import { Box, Flex } from '../../Layout';
Expand All @@ -21,11 +28,10 @@ import { CaptionsViewer } from '../plugins/CaptionsViewer';
import {
usePDFConfig,
useUrlToEmbed,
useWaitingViewerRole,
// @ts-ignore: No implicit Any
} from '../components/AppData/useUISettings';
import { useCloseScreenshareWhiteboard } from '../components/hooks/useCloseScreenshareWhiteboard';
import { useLandscapeHLSStream, useMobileHLSStream } from '../common/hooks';
import { useLandscapeHLSStream, useMobileHLSStream, useWaitingRoomInfo } from '../common/hooks';
import { SESSION_STORE_KEY } from '../common/constants';
// @ts-ignore: No implicit Any
const HLSView = React.lazy(() => import('./HLSView'));
Expand All @@ -39,17 +45,20 @@ export const VideoStreamingSection = ({
elements: DefaultConferencingScreen_Elements | HLSLiveStreamingScreen_Elements;
hideControls: boolean;
}) => {
const localPeerRole = useHMSStore(selectLocalPeerRoleName);
const localPeerRoleName = useHMSStore(selectLocalPeerRoleName);
const isConnected = useHMSStore(selectIsConnectedToRoom);
const isSharingScreen = useHMSStore(selectIsLocalScreenShared);

const hmsActions = useHMSActions();
const waitingViewerRole = useWaitingViewerRole();
const urlToIframe = useUrlToEmbed();
const pdfAnnotatorActive = usePDFConfig();
const isMobileHLSStream = useMobileHLSStream();
const isLandscapeHLSStream = useLandscapeHLSStream();
useCloseScreenshareWhiteboard();

const { isNotAllowedToPublish, isScreenOnlyPublishParams, hasSubscribedRolePublishing } = useWaitingRoomInfo();

console.log('pring ', isNotAllowedToPublish, isScreenOnlyPublishParams, hasSubscribedRolePublishing);
useEffect(() => {
if (!isConnected) {
return;
Expand All @@ -64,7 +73,7 @@ export const VideoStreamingSection = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isConnected, hmsActions]);

if (!localPeerRole) {
if (!localPeerRoleName) {
// we don't know the role yet to decide how to render UI
return null;
}
Expand All @@ -82,16 +91,42 @@ export const VideoStreamingSection = ({
.with({ isMobileHLSStream: true }, () => 'column')
.otherwise(() => 'row')}
>
{match({ screenType, localPeerRole, pdfAnnotatorActive, urlToIframe })
{match({
screenType,
isNotAllowedToPublish,
isScreenOnlyPublishParams,
hasSubscribedRolePublishing,
isSharingScreen,
pdfAnnotatorActive,
urlToIframe,
})
.with(
{
screenType: 'hls_live_streaming',
},
() => <HLSView />,
)
.when(
({ localPeerRole }) => localPeerRole === waitingViewerRole,
() => <WaitingView />,
({ isNotAllowedToPublish, hasSubscribedRolePublishing }) =>
isNotAllowedToPublish && !hasSubscribedRolePublishing,
() => (
<WaitingView
title="Waiting for Host to join"
subtitle="Sit back and relax"
icon={<PeopleAddIcon width="56px" height="56px" style={{ color: 'white' }} />}
/>
),
)
.when(
({ isScreenOnlyPublishParams, isSharingScreen, hasSubscribedRolePublishing }) =>
isScreenOnlyPublishParams && !isSharingScreen && !hasSubscribedRolePublishing,
() => (
<WaitingView
title="Ready to present"
subtitle="Select the Screenshare button to start presenting"
icon={<ShareScreenIcon width="56px" height="56px" style={{ color: 'white' }} />}
/>
),
)
.when(
({ pdfAnnotatorActive }) => !!pdfAnnotatorActive,
Expand Down
Loading

0 comments on commit 5d212a5

Please sign in to comment.