Skip to content

Commit

Permalink
fix: added hook
Browse files Browse the repository at this point in the history
  • Loading branch information
amar-1995 committed May 21, 2024
1 parent 424a7e1 commit b01b27a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
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 @@ -52,7 +52,7 @@ export function EqualProminence({ isInsetEnabled = false, peers, onPageChange, o
{pageList.length === 0 ? (
<WaitingView
title="Waiting for Host to join"
subTitle="Sit back and relax till others join"
subtitle="Sit back and relax till others join"
icon={<PeopleAddIcon width="56px" height="56px" style={{ color: 'white' }} />}
/>
) : null}
Expand Down
4 changes: 2 additions & 2 deletions packages/roomkit-react/src/Prebuilt/layouts/HLSView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,13 @@ const HLSView = () => {
<WaitingView
icon={<ColoredHandIcon height={56} width={56} />}
title="Stream has ended"
subTitle="Have a nice day!"
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"
subtitle="Sit back and relax"
/>
)}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Suspense, useEffect, useMemo } from 'react';
import React, { Suspense, useEffect } from 'react';
import {
ConferencingScreen,
DefaultConferencingScreen_Elements,
Expand All @@ -8,10 +8,7 @@ import { match } from 'ts-pattern';
import {
selectIsConnectedToRoom,
selectIsLocalScreenShared,
selectLocalPeerRole,
selectLocalPeerRoleName,
selectPeersByRoles,
selectRolesMap,
useHMSActions,
useHMSStore,
} from '@100mslive/react-sdk';
Expand All @@ -34,7 +31,7 @@ import {
// @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 @@ -49,7 +46,6 @@ export const VideoStreamingSection = ({
hideControls: boolean;
}) => {
const localPeerRoleName = useHMSStore(selectLocalPeerRoleName);
const localPeerRole = useHMSStore(selectLocalPeerRole);
const isConnected = useHMSStore(selectIsConnectedToRoom);
const isSharingScreen = useHMSStore(selectIsLocalScreenShared);

Expand All @@ -60,21 +56,9 @@ export const VideoStreamingSection = ({
const isLandscapeHLSStream = useLandscapeHLSStream();
useCloseScreenshareWhiteboard();

const roles = useHMSStore(selectRolesMap);
const peersByRoles = useHMSStore(selectPeersByRoles(localPeerRole?.subscribeParams.subscribeToRoles || []));
const isNotAllowedToPublish = localPeerRole?.publishParams?.allowed.length === 0;
const isScreenOnlyPublishParams =
localPeerRole?.publishParams?.allowed.some(value => value === 'screen') &&
localPeerRole?.publishParams?.allowed.length === 1;
const hasSubscribedRolePublishing = useMemo(() => {
return peersByRoles.some(peer => {
if (peer.roleName && roles[peer.roleName]) {
return !!roles[peer.roleName].publishParams?.allowed.length;
}
return true;
});
}, [peersByRoles, roles]);
const { isNotAllowedToPublish, isScreenOnlyPublishParams, hasSubscribedRolePublishing } = useWaitingRoomInfo();

console.log('pring ', isNotAllowedToPublish, isScreenOnlyPublishParams, hasSubscribedRolePublishing);
useEffect(() => {
if (!isConnected) {
return;
Expand Down Expand Up @@ -128,7 +112,7 @@ export const VideoStreamingSection = ({
() => (
<WaitingView
title="Waiting for Host to join"
subTitle="Sit back and relax"
subtitle="Sit back and relax"
icon={<PeopleAddIcon width="56px" height="56px" style={{ color: 'white' }} />}
/>
),
Expand All @@ -139,7 +123,7 @@ export const VideoStreamingSection = ({
() => (
<WaitingView
title="Ready to present"
subTitle="Select the Screenshare button to start presenting"
subtitle="Select the Screenshare button to start presenting"
icon={<ShareScreenIcon width="56px" height="56px" style={{ color: 'white' }} />}
/>
),
Expand Down
4 changes: 2 additions & 2 deletions packages/roomkit-react/src/Prebuilt/layouts/WaitingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box, Flex } from '../../Layout';
import { Text } from '../../Text';

export const WaitingView = React.memo(
({ icon, title, subTitle }: { icon: React.ReactNode; title: string; subTitle: string }) => {
({ icon, title, subtitle }: { icon: React.ReactNode; title: string; subtitle: string }) => {
return (
<Flex
align="center"
Expand Down Expand Up @@ -43,7 +43,7 @@ export const WaitingView = React.memo(
variant="body1"
css={{ fontWeight: '$regular', color: '$on_surface_medium', '@md': { fontSize: '$sm' } }}
>
{subTitle}
{subtitle}
</Text>
</Flex>
</Flex>
Expand Down

0 comments on commit b01b27a

Please sign in to comment.