Skip to content

Commit

Permalink
Update publish-alpha (#2522)
Browse files Browse the repository at this point in the history
* fix: show trophy only if peer has a score

* fix: preserve attempted polls

* feat: default vb set by layout
  • Loading branch information
KaustubhKumar05 authored Feb 14, 2024
1 parent 21fe3fa commit b25e9e2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 201 deletions.
15 changes: 7 additions & 8 deletions packages/roomkit-react/src/Prebuilt/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export const HMSPrebuilt = React.forwardRef<HMSPrebuiltRefType, HMSPrebuiltProps
ref,
) => {
const reactiveStore = useRef<HMSPrebuiltRefType>();

const [hydrated, setHydrated] = React.useState(false);

useEffect(() => {
setHydrated(true);
const hms = new HMSReactiveStore();
Expand All @@ -122,14 +122,13 @@ export const HMSPrebuilt = React.forwardRef<HMSPrebuiltRefType, HMSPrebuiltProps
(ref as MutableRefObject<HMSPrebuiltRefType>).current = { ...reactiveStore.current };
}, [ref]);

// leave room when component unmounts
useEffect(
() => () => {
useEffect(() => {
// leave room when component unmounts
return () => {
VBHandler.reset();
reactiveStore?.current?.hmsActions.leave();
},
[],
);
};
}, []);

const endpointsObj = endpoints as
| {
Expand Down Expand Up @@ -214,7 +213,6 @@ export const HMSPrebuilt = React.forwardRef<HMSPrebuiltRefType, HMSPrebuiltProps
},
}}
>
<AppData />
<Init />
<DialogContainerProvider dialogContainerSelector={containerSelector}>
<Box
Expand Down Expand Up @@ -291,6 +289,7 @@ function AppRoutes({
return (
<AppStateContext.Provider value={{ rejoin }}>
<>
{activeState !== PrebuiltStates.LEAVE && <AppData />}
<ToastContainer />
<Notifications />
<MwebLandscapePrompt />
Expand Down
2 changes: 1 addition & 1 deletion packages/roomkit-react/src/Prebuilt/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const APP_DATA = {
disableNotifications: 'disableNotifications',
pollState: 'pollState',
background: 'background',
backgroundType: 'backgroundType',
};

export const UI_SETTINGS = {
isAudioOnly: 'isAudioOnly',
maxTileCount: 'maxTileCount',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
useRecordingStreaming,
} from '@100mslive/react-sdk';
import { LayoutMode } from '../Settings/LayoutSettings';
import { useRoomLayoutConferencingScreen } from '../../provider/roomLayoutProvider/hooks/useRoomLayoutScreen';
//@ts-ignore
import { UserPreferencesKeys, useUserPreferences } from '../hooks/useUserPreferences';
// @ts-ignore
Expand Down Expand Up @@ -60,7 +61,6 @@ const initialAppData = {
[APP_DATA.activeScreensharePeerId]: '',
[APP_DATA.disableNotifications]: false,
[APP_DATA.background]: 'none',
[APP_DATA.backgroundType]: 'none',
[APP_DATA.pollState]: {
[POLL_STATE.pollInView]: '',
[POLL_STATE.view]: '',
Expand All @@ -71,6 +71,8 @@ export const AppData = React.memo(() => {
const hmsActions = useHMSActions();
const [preferences = {}] = useUserPreferences(UserPreferencesKeys.UI_SETTINGS);
const appData = useHMSStore(selectFullAppData);
const { elements } = useRoomLayoutConferencingScreen();
const toggleVB = useSidepaneToggle(SIDE_PANE_OPTIONS.VB);

useEffect(() => {
hmsActions.initAppData({
Expand Down Expand Up @@ -103,6 +105,19 @@ export const AppData = React.memo(() => {
hmsActions.setAppData(APP_DATA.subscribedNotifications, preferences.subscribedNotifications, true);
}, [preferences.subscribedNotifications, hmsActions]);

useEffect(() => {
let defaultMediaURL;
elements?.virtual_background?.background_media?.forEach(media => {
if (media.default && media.url) {
defaultMediaURL = media.url;
}
});
if (defaultMediaURL) {
hmsActions.setAppData(APP_DATA.background, defaultMediaURL);
toggleVB();
}
}, [hmsActions, elements?.virtual_background?.background_media, toggleVB]);

return <ResetStreamingStart />;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ const PreviewJoin = ({
asRole,
});
const roomState = useHMSStore(selectRoomState);

const savePreferenceAndJoin = useCallback(() => {
setPreviewPreference({
name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React, { useEffect, useState } from 'react';
import { selectEffectsKey, selectIsEffectsEnabled, selectLocalPeerRole } from '@100mslive/hms-video-store';
import {
selectAppData,
selectEffectsKey,
selectIsEffectsEnabled,
selectLocalPeerRole,
} from '@100mslive/hms-video-store';
import { HMSEffectsPlugin, HMSVBPlugin, HMSVirtualBackgroundTypes } from '@100mslive/hms-virtual-background';
import { VirtualBackgroundMedia } from '@100mslive/types-prebuilt/elements/virtual_background';
import {
Expand All @@ -22,7 +27,7 @@ import { VBHandler } from './VBHandler';
import { useSidepaneToggle } from '../AppData/useSidepane';
// @ts-ignore
import { useUISettings } from '../AppData/useUISettings';
import { SIDE_PANE_OPTIONS, UI_SETTINGS } from '../../common/constants';
import { APP_DATA, SIDE_PANE_OPTIONS, UI_SETTINGS } from '../../common/constants';
import { defaultMedia } from './constants';

const iconDims = { height: '40px', width: '40px' };
Expand All @@ -42,9 +47,7 @@ export const VBPicker = ({ backgroundMedia = [] }: { backgroundMedia: VirtualBac
const isEffectsEnabled = useHMSStore(selectIsEffectsEnabled);
const effectsKey = useHMSStore(selectEffectsKey);
const isPluginAdded = useHMSStore(selectIsLocalVideoPluginPresent(VBHandler?.getName() || ''));
const [activeBackground, setActiveBackground] = useState<string | HMSVirtualBackgroundTypes>(
(VBHandler?.getBackground() as string | HMSVirtualBackgroundTypes) || HMSVirtualBackgroundTypes.NONE,
);
const background = useHMSStore(selectAppData(APP_DATA.background));
const mediaList = backgroundMedia.length
? backgroundMedia.map((media: VirtualBackgroundMedia) => media.url || '')
: defaultMedia;
Expand All @@ -71,8 +74,22 @@ export const VBPicker = ({ backgroundMedia = [] }: { backgroundMedia: VirtualBac
hmsActions.addPluginToVideoTrack(vbObject as HMSVBPlugin, Math.floor(role.publishParams.video.frameRate / 2));
}
}
const handleDefaultBackground = async () => {
switch (background) {
case HMSVirtualBackgroundTypes.NONE: {
break;
}
case HMSVirtualBackgroundTypes.BLUR: {
await VBHandler.setBlur(blurAmount);
break;
}
default:
await VBHandler.setBackground(background);
}
};
handleDefaultBackground();
}
}, [hmsActions, role, isPluginAdded, isEffectsEnabled, effectsKey, track?.id]);
}, [hmsActions, role, isPluginAdded, isEffectsEnabled, effectsKey, track?.id, background, blurAmount]);

useEffect(() => {
if (!isVideoOn) {
Expand Down Expand Up @@ -120,7 +137,7 @@ export const VBPicker = ({ backgroundMedia = [] }: { backgroundMedia: VirtualBac
value: HMSVirtualBackgroundTypes.NONE,
onClick: async () => {
await VBHandler.removeEffects();
setActiveBackground(HMSVirtualBackgroundTypes.NONE);
hmsActions.setAppData(APP_DATA.background, HMSVirtualBackgroundTypes.NONE);
},
},
{
Expand All @@ -129,16 +146,16 @@ export const VBPicker = ({ backgroundMedia = [] }: { backgroundMedia: VirtualBac
value: HMSVirtualBackgroundTypes.BLUR,
onClick: async () => {
await VBHandler?.setBlur(blurAmount);
setActiveBackground(HMSVirtualBackgroundTypes.BLUR);
hmsActions.setAppData(APP_DATA.background, HMSVirtualBackgroundTypes.BLUR);
},
},
]}
activeBackground={activeBackground}
activeBackground={background}
/>

{/* Slider */}
<Flex direction="column" css={{ w: '100%', gap: '$8', mt: '$8' }}>
{activeBackground === HMSVirtualBackgroundTypes.BLUR && isEffectsEnabled && effectsKey ? (
{background === HMSVirtualBackgroundTypes.BLUR && isEffectsEnabled && effectsKey ? (
<Box>
<Text variant="sm" css={{ color: '$on_surface_high', fontWeight: '$semiBold', mb: '$4' }}>
Blur intensity
Expand Down Expand Up @@ -173,10 +190,10 @@ export const VBPicker = ({ backgroundMedia = [] }: { backgroundMedia: VirtualBac
value: mediaURL,
onClick: async () => {
await VBHandler?.setBackground(mediaURL);
setActiveBackground(mediaURL);
hmsActions.setAppData(APP_DATA.background, mediaURL);
},
}))}
activeBackground={activeBackground}
activeBackground={background}
/>
</Box>
</Flex>
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit b25e9e2

Please sign in to comment.