Skip to content

Commit

Permalink
refactor: remove template app data
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 authored Aug 29, 2023
1 parent 004b6d1 commit b3f5c91
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 143 deletions.
19 changes: 0 additions & 19 deletions packages/roomkit-react/src/Prebuilt/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,6 @@ export const isIPadOS = false;
// navigator?.maxTouchPoints > 2 &&
// navigator?.userAgent?.match(/Mac/);

export const FEATURE_LIST = {
AUDIO_ONLY_SCREENSHARE: 'audioscreenshare',
AUDIO_PLAYLIST: 'audioplaylist',
VIDEO_PLAYLIST: 'videoplaylist',
EMOJI_REACTION: 'emojireaction',
AUDIO_PLUGINS: 'audioplugins',
VIDEO_PLUGINS: 'videoplugins',
WHITEBOARD: 'whiteboard',
CHANGE_NAME: 'changename',
FULLSCREEN: 'fullscreen',
PICTURE_IN_PICTURE: 'pip',
STARTS_FOR_NERDS: 'statsfornerds',
EMBED_URL: 'embedurl',
BRB: 'brb',
HAND_RAISE: 'handraise',
CHAT: 'chat',
PIN_TILE: 'pintile',
};

export const SESSION_STORE_KEY = {
TRANSCRIPTION_STATE: 'transcriptionState',
PINNED_MESSAGE: 'pinnedMessage',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import { Tooltip } from '../../Tooltip';
import IconButton from '../IconButton';
import { useHLSViewerRole } from './AppData/useUISettings';
import { useDropdownList } from './hooks/useDropdownList';
import { useIsFeatureEnabled } from './hooks/useFeatures';
import { EMOJI_REACTION_TYPE, FEATURE_LIST } from '../common/constants';
import { EMOJI_REACTION_TYPE } from '../common/constants';

init({ data });

export const EmojiReaction = () => {
const [open, setOpen] = useState(false);
const isConnected = useHMSStore(selectIsConnectedToRoom);
const isFeatureEnabled = useIsFeatureEnabled(FEATURE_LIST.EMOJI_REACTION);
useDropdownList({ open: open, name: 'EmojiReaction' });
const hmsActions = useHMSActions();
const roles = useHMSStore(selectAvailableRoleNames);
Expand Down Expand Up @@ -70,7 +68,7 @@ export const EmojiReaction = () => {
}
};

if (!isConnected || !isFeatureEnabled) {
if (!isConnected) {
return null;
}
return isMobile ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ import { ChatIcon, ChatUnreadIcon } from '@100mslive/react-icons';
import { Tooltip } from '../../../';
import IconButton from '../../IconButton';
import { useIsSidepaneTypeOpen, useSidepaneToggle } from '../AppData/useSidepane';
import { useIsFeatureEnabled } from '../hooks/useFeatures';
import { FEATURE_LIST, SIDE_PANE_OPTIONS } from '../../common/constants';
import { SIDE_PANE_OPTIONS } from '../../common/constants';

export const ChatToggle = () => {
const countUnreadMessages = useHMSStore(selectUnreadHMSMessagesCount);
const isChatOpen = useIsSidepaneTypeOpen(SIDE_PANE_OPTIONS.CHAT);
const toggleChat = useSidepaneToggle(SIDE_PANE_OPTIONS.CHAT);
const isFeatureEnabled = useIsFeatureEnabled(FEATURE_LIST.CHAT);

if (!isFeatureEnabled) {
return;
}

return (
<Tooltip key="chat" title={`${isChatOpen ? 'Close' : 'Open'} chat`}>
Expand Down
38 changes: 15 additions & 23 deletions packages/roomkit-react/src/Prebuilt/components/MetaActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,32 @@ import { BrbIcon, HandIcon } from '@100mslive/react-icons';
import { Flex } from '../../Layout';
import { Tooltip } from '../../Tooltip';
import IconButton from '../IconButton';
import { useIsFeatureEnabled } from './hooks/useFeatures';
import { useMyMetadata } from './hooks/useMetadata';
import { FEATURE_LIST } from '../common/constants';

const MetaActions = ({ isMobile = false, compact = false }) => {
const isConnected = useHMSStore(selectIsConnectedToRoom);
const { isHandRaised, isBRBOn, toggleHandRaise, toggleBRB } = useMyMetadata();
const isHandRaiseEnabled = useIsFeatureEnabled(FEATURE_LIST.HAND_RAISE);
const isBRBEnabled = useIsFeatureEnabled(FEATURE_LIST.BRB);

if (!isConnected || (!isHandRaiseEnabled && !isBRBEnabled)) {
if (!isConnected) {
return null;
}

return (
<Flex align="center" css={{ gap: compact ? '$4' : '$8' }}>
{isHandRaiseEnabled && (
<Tooltip title={`${!isHandRaised ? 'Raise' : 'Unraise'} hand`}>
<IconButton
onClick={toggleHandRaise}
active={!isHandRaised}
data-testid={isMobile ? 'raise_hand_btn_mobile' : 'raise_hand_btn'}
>
<HandIcon />
</IconButton>
</Tooltip>
)}
{isBRBEnabled && (
<Tooltip title={isBRBOn ? `I'm back` : `I'll be right back`}>
<IconButton onClick={toggleBRB} active={!isBRBOn} data-testid="brb_btn">
<BrbIcon />
</IconButton>
</Tooltip>
)}
<Tooltip title={`${!isHandRaised ? 'Raise' : 'Unraise'} hand`}>
<IconButton
onClick={toggleHandRaise}
active={!isHandRaised}
data-testid={isMobile ? 'raise_hand_btn_mobile' : 'raise_hand_btn'}
>
<HandIcon />
</IconButton>
</Tooltip>
<Tooltip title={isBRBOn ? `I'm back` : `I'll be right back`}>
<IconButton onClick={toggleBRB} active={!isBRBOn} data-testid="brb_btn">
<BrbIcon />
</IconButton>
</Tooltip>
</Flex>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import React from 'react';
import { ExpandIcon } from '@100mslive/react-icons';
import { Dropdown, Text } from '../../../';
import { useIsFeatureEnabled } from '../hooks/useFeatures';
import { useFullscreen } from '../hooks/useFullscreen';
import { FEATURE_LIST } from '../../common/constants';

export const FullScreenItem = () => {
const { allowed, isFullscreen, toggleFullscreen } = useFullscreen();
const isFullscreenEnabled = useIsFeatureEnabled(FEATURE_LIST.FULLSCREEN);

if (!isFullscreenEnabled || !allowed) {
if (!allowed) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import { BulkRoleChangeModal } from '.././BulkRoleChangeModal';
import { FullScreenItem } from '.././FullScreenItem';
import { MuteAllModal } from '.././MuteAllModal';
import { useDropdownList } from '../../hooks/useDropdownList';
import { useIsFeatureEnabled } from '../../hooks/useFeatures';
import { useMyMetadata } from '../../hooks/useMetadata';
import { useIsLocalPeerHLSViewer, useShowStreamingUI } from '../../../common/hooks';
import { FeatureFlags } from '../../../services/FeatureFlags';
import { APP_DATA, FEATURE_LIST, isMacOS } from '../../../common/constants';
import { APP_DATA, isMacOS } from '../../../common/constants';

const MODALS = {
CHANGE_NAME: 'changeName',
Expand All @@ -43,14 +42,10 @@ export const DesktopOptions = () => {
const localPeerRole = useHMSStore(selectLocalPeerRoleName);
const hmsActions = useHMSActions();
const enablHlsStats = useHMSStore(selectAppData(APP_DATA.hlsStats));
const isSFNEnabled = useIsFeatureEnabled(FEATURE_LIST.STARTS_FOR_NERDS);
const [openModals, setOpenModals] = useState(new Set());
const { isHandRaised, isBRBOn, toggleHandRaise, toggleBRB } = useMyMetadata();
const isHandRaiseEnabled = useIsFeatureEnabled(FEATURE_LIST.HAND_RAISE);
const isBRBEnabled = useIsFeatureEnabled(FEATURE_LIST.BRB);
const showStreamingUI = useShowStreamingUI();
const isHlsViewer = useIsLocalPeerHLSViewer();
const isPIPEnabled = useIsFeatureEnabled(FEATURE_LIST.PICTURE_IN_PICTURE);
const isPipOn = PictureInPicture.isOn();

useDropdownList({ open: openModals.size > 0, name: 'MoreSettings' });
Expand Down Expand Up @@ -96,7 +91,7 @@ export const DesktopOptions = () => {
},
}}
>
{isHandRaiseEnabled && !(showStreamingUI || isHlsViewer) ? (
{!(showStreamingUI || isHlsViewer) ? (
<Dropdown.Item onClick={toggleHandRaise} data-testid="raise_hand_btn">
<HandIcon />
<Text variant="sm" css={{ ml: '$4', color: '$on_surface_high' }}>
Expand All @@ -108,7 +103,7 @@ export const DesktopOptions = () => {
</Dropdown.Item>
) : null}

{isBRBEnabled && !(showStreamingUI || isHlsViewer) ? (
{!(showStreamingUI || isHlsViewer) ? (
<Dropdown.Item onClick={toggleBRB} data-testid="brb_btn">
<BrbIcon />
<Text variant="sm" css={{ ml: '$4', color: '$on_surface_high' }}>
Expand All @@ -120,11 +115,9 @@ export const DesktopOptions = () => {
</Dropdown.Item>
) : null}

{(isBRBEnabled || isHandRaiseEnabled) && !(showStreamingUI || isHlsViewer) ? (
<Dropdown.ItemSeparator css={{ mx: '0' }} />
) : null}
{!(showStreamingUI || isHlsViewer) ? <Dropdown.ItemSeparator css={{ mx: '0' }} /> : null}

{isPIPEnabled && !isHlsViewer ? (
{!isHlsViewer ? (
<Dropdown.Item>
<PIP
content={
Expand Down Expand Up @@ -154,7 +147,6 @@ export const DesktopOptions = () => {
</Dropdown.Item>

{FeatureFlags.enableStatsForNerds &&
isSFNEnabled &&
(localPeerRole === 'hls-viewer' ? (
HMSHLSPlayer.isSupported() ? (
<Dropdown.Item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { useEffect } from 'react';
import { HMSNotificationTypes, useHMSActions, useHMSNotifications } from '@100mslive/react-sdk';
import { ToastBatcher } from '../Toast/ToastBatcher';
import { useIsHeadless, useSubscribedNotifications } from '../AppData/useUISettings';
import { useIsFeatureEnabled } from '../hooks/useFeatures';
import { useMyMetadata } from '../hooks/useMetadata';
import { FEATURE_LIST, LOWER_HAND, SUBSCRIBED_NOTIFICATIONS } from '../../common/constants';
import { LOWER_HAND, SUBSCRIBED_NOTIFICATIONS } from '../../common/constants';

export const MessageNotifications = () => {
const hmsActions = useHMSActions();
hmsActions.ignoreMessageTypes([LOWER_HAND]);
const notification = useHMSNotifications(HMSNotificationTypes.NEW_MESSAGE);
const isChatEnabled = useIsFeatureEnabled(FEATURE_LIST.CHAT);
const isNewMessageSubscribed = useSubscribedNotifications(SUBSCRIBED_NOTIFICATIONS.NEW_MESSAGE);
const isHeadless = useIsHeadless();
const metadata = useMyMetadata();
Expand All @@ -25,11 +23,11 @@ export const MessageNotifications = () => {
hmsActions.changeMetadata(newMetadata);
}
console.debug(`[${notification.type}]`, notification);
if (!isNewMessageSubscribed || notification.data?.ignored || !isChatEnabled) {
if (!isNewMessageSubscribed || notification.data?.ignored) {
return;
}
ToastBatcher.showToast({ notification });
}, [notification, isNewMessageSubscribed, isHeadless, isChatEnabled]);
}, [notification, isNewMessageSubscribed, isHeadless]);

return null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import IconButton from '../../IconButton';
import { PictureInPicture } from './PIPManager';
import { MediaSession } from './SetupMediaSession';
import { usePinnedTrack } from '../AppData/useUISettings';
import { useIsFeatureEnabled } from '../hooks/useFeatures';
import { DEFAULT_HLS_VIEWER_ROLE, FEATURE_LIST } from '../../common/constants';
import { DEFAULT_HLS_VIEWER_ROLE } from '../../common/constants';

/**
* shows a button which when clicked shows some videos in PIP, clicking
Expand All @@ -25,7 +24,6 @@ const PIPComponent = ({ content = null }) => {
const [isPipOn, setIsPipOn] = useState(PictureInPicture.isOn());
const hmsActions = useHMSActions();
const store = useHMSVanillaStore();
const isFeatureEnabled = useIsFeatureEnabled(FEATURE_LIST.PICTURE_IN_PICTURE);

const onPipToggle = useCallback(() => {
if (!isPipOn) {
Expand All @@ -36,7 +34,7 @@ const PIPComponent = ({ content = null }) => {
}
}, [hmsActions, isPipOn, store]);

if (!PictureInPicture.isSupported() || localPeerRole === DEFAULT_HLS_VIEWER_ROLE || !isFeatureEnabled) {
if (!PictureInPicture.isSupported() || localPeerRole === DEFAULT_HLS_VIEWER_ROLE) {
return null;
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { Box, Dropdown, Flex, Text, Tooltip } from '../../../';
import IconButton from '../../IconButton';
import { AudioPlaylistControls } from './PlaylistControls';
import { PlaylistItem } from './PlaylistItem';
import { useIsFeatureEnabled } from '../hooks/useFeatures';
import { usePlaylist } from '../hooks/usePlaylist';
import { FEATURE_LIST } from '../../common/constants';

const BrowseAndPlayFromLocal = ({ type, actions }) => {
return (
Expand Down Expand Up @@ -44,10 +42,7 @@ export const Playlist = ({ type }) => {
const [open, setOpen] = useState(false);
const [collapse, setCollapse] = useState(false);
const isAllowedToPublish = useHMSStore(selectIsAllowedToPublish);
const isFeatureEnabled = useIsFeatureEnabled(
isAudioPlaylist ? FEATURE_LIST.AUDIO_PLAYLIST : FEATURE_LIST.VIDEO_PLAYLIST,
);
if (!isAllowedToPublish.screen || playlist.length === 0 || !isFeatureEnabled) {
if (!isAllowedToPublish.screen || playlist.length === 0) {
return null;
}

Expand Down
7 changes: 0 additions & 7 deletions packages/roomkit-react/src/Prebuilt/components/RaiseHand.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ import { selectLocalPeer, selectPeerMetadata, useHMSStore } from '@100mslive/rea
import { HandIcon } from '@100mslive/react-icons';
import { Tooltip } from '../../Tooltip';
import IconButton from '../IconButton';
import { useIsFeatureEnabled } from './hooks/useFeatures';
import { useMyMetadata } from './hooks/useMetadata';
import { FEATURE_LIST } from '../common/constants';

export const RaiseHand = () => {
const isHandRaiseEnabled = useIsFeatureEnabled(FEATURE_LIST.HAND_RAISE);
const { toggleHandRaise } = useMyMetadata();
const localPeer = useHMSStore(selectLocalPeer);
const isHandRaised = useHMSStore(selectPeerMetadata(localPeer.id))?.isHandRaised || false;

if (!isHandRaiseEnabled) {
return null;
}

return (
<Tooltip title={isHandRaised ? 'Lower hand' : 'Raise hand'}>
<IconButton active={!isHandRaised} onClick={toggleHandRaise}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import { StyledMenuTile } from '../../../TileMenu';
import { ChangeNameModal } from '../MoreSettings/ChangeNameModal';
import { TileMenuContent } from './TileMenuContent';
import { useDropdownList } from '../hooks/useDropdownList';
import { useIsFeatureEnabled } from '../hooks/useFeatures';
import { FEATURE_LIST } from '../../common/constants';

/**
* Taking peerID as peer won't necesarilly have tracks
Expand All @@ -39,8 +37,7 @@ const TileMenu = ({ audioTrackID, videoTrackID, peerID, isScreenshare = false, c
const uiMode = useHMSStore(selectTemplateAppData).uiMode;
const isInset = uiMode === 'inset';

const isPinEnabled = useIsFeatureEnabled(FEATURE_LIST.PIN_TILE);
const showPinAction = isPinEnabled && (audioTrackID || (videoTrackID && isPrimaryVideoTrack)) && !isInset;
const showPinAction = (audioTrackID || (videoTrackID && isPrimaryVideoTrack)) && !isInset;

const track = useHMSStore(selectTrackByID(videoTrackID));
const hideSimulcastLayers = !track?.layerDefinitions?.length || track.degraded || !track.enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import { StyledMenuTile } from '../../../TileMenu';
import { ToastManager } from '../Toast/ToastManager';
import { useSetAppDataByKey } from '../AppData/useUISettings';
import { useDropdownSelection } from '../hooks/useDropdownSelection';
import { useIsFeatureEnabled } from '../hooks/useFeatures';
import { APP_DATA, FEATURE_LIST, REMOTE_STOP_SCREENSHARE_TYPE, SESSION_STORE_KEY } from '../../common/constants';
import { APP_DATA, REMOTE_STOP_SCREENSHARE_TYPE, SESSION_STORE_KEY } from '../../common/constants';

export const isSameTile = ({ trackId, videoTrackID, audioTrackID }) =>
trackId && ((videoTrackID && videoTrackID === trackId) || (audioTrackID && audioTrackID === trackId));
Expand Down Expand Up @@ -211,27 +210,23 @@ export const TileMenuContent = props => {
type: REMOTE_STOP_SCREENSHARE_TYPE,
});

const isChangeNameEnabled = useIsFeatureEnabled(FEATURE_LIST.CHANGE_NAME);

return isLocal ? (
(showPinAction || canMinimise) && (
<>
{showPinAction && <PinActions audioTrackID={audioTrackID} videoTrackID={videoTrackID} />}
{showSpotlight && <SpotlightActions peerId={peerID} onSpotLightClick={() => closeSheetOnClick()} />}
{canMinimise && <MinimiseInset />}
{isChangeNameEnabled ? (
<StyledMenuTile.ItemButton
onClick={() => {
openNameChangeModal();
closeSheetOnClick();
}}
>
<PencilIcon />
<Text variant="sm" css={{ '@md': { fontWeight: '$semiBold' }, c: '$on_surface_high' }}>
Change Name
</Text>
</StyledMenuTile.ItemButton>
) : null}
<StyledMenuTile.ItemButton
onClick={() => {
openNameChangeModal();
closeSheetOnClick();
}}
>
<PencilIcon />
<Text variant="sm" css={{ '@md': { fontWeight: '$semiBold' }, c: '$on_surface_high' }}>
Change Name
</Text>
</StyledMenuTile.ItemButton>
</>
)
) : (
Expand Down
Loading

0 comments on commit b3f5c91

Please sign in to comment.