@100mslive/roomkit-react 0.1.19-alpha.0 → 0.1.19-alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. package/dist/{HLSView-GG4WVUQY.js → HLSView-7X5BVAZE.js} +2 -2
  2. package/dist/Prebuilt/App.d.ts +1 -0
  3. package/dist/Prebuilt/common/constants.d.ts +1 -1
  4. package/dist/Prebuilt/components/Chat/EmptyChat.d.ts +2 -0
  5. package/dist/Prebuilt/components/Polls/Voting/{Leaderboard.d.ts → LeaderboardSummary.d.ts} +1 -1
  6. package/dist/Prebuilt/components/Polls/Voting/StatisticBox.d.ts +5 -0
  7. package/dist/Prebuilt/components/VirtualBackground/VBCollection.d.ts +3 -4
  8. package/dist/Prebuilt/components/VirtualBackground/VBHandler.d.ts +13 -0
  9. package/dist/Prebuilt/components/VirtualBackground/VBPicker.d.ts +4 -2
  10. package/dist/Prebuilt/components/VirtualBackground/constants.d.ts +0 -2
  11. package/dist/{chunk-GXJIUWTP.js → chunk-H3B4ARYV.js} +1399 -1296
  12. package/dist/chunk-H3B4ARYV.js.map +7 -0
  13. package/dist/index.cjs.js +1744 -1612
  14. package/dist/index.cjs.js.map +4 -4
  15. package/dist/index.js +1 -1
  16. package/dist/meta.cjs.json +228 -91
  17. package/dist/meta.esbuild.json +235 -98
  18. package/package.json +6 -6
  19. package/src/Prebuilt/App.tsx +2 -1
  20. package/src/Prebuilt/common/constants.ts +1 -1
  21. package/src/Prebuilt/components/Chat/ChatActions.tsx +3 -3
  22. package/src/Prebuilt/components/Chat/ChatBody.tsx +28 -46
  23. package/src/Prebuilt/components/Chat/EmptyChat.tsx +51 -0
  24. package/src/Prebuilt/components/Footer/PollsToggle.tsx +7 -1
  25. package/src/Prebuilt/components/Notifications/Notifications.tsx +0 -29
  26. package/src/Prebuilt/components/Polls/Polls.tsx +2 -2
  27. package/src/Prebuilt/components/Polls/Voting/LeaderboardEntry.tsx +2 -2
  28. package/src/Prebuilt/components/Polls/Voting/LeaderboardSummary.tsx +162 -0
  29. package/src/Prebuilt/components/Polls/Voting/PeerParticipationSummary.tsx +2 -9
  30. package/src/Prebuilt/components/Polls/Voting/StatisticBox.tsx +15 -0
  31. package/src/Prebuilt/components/Polls/Voting/Voting.jsx +1 -17
  32. package/src/Prebuilt/components/TileMenu/TileMenuContent.tsx +1 -1
  33. package/src/Prebuilt/components/VirtualBackground/VBCollection.tsx +5 -11
  34. package/src/Prebuilt/components/VirtualBackground/VBHandler.tsx +72 -0
  35. package/src/Prebuilt/components/VirtualBackground/VBPicker.tsx +48 -83
  36. package/src/Prebuilt/components/VirtualBackground/constants.ts +0 -4
  37. package/src/Prebuilt/layouts/SidePane.tsx +11 -2
  38. package/src/Prebuilt/provider/roomLayoutProvider/index.tsx +5 -3
  39. package/src/Theme/stitches.config.ts +2 -10
  40. package/dist/chunk-GXJIUWTP.js.map +0 -7
  41. package/src/Prebuilt/components/Polls/Voting/Leaderboard.tsx +0 -123
  42. package/src/Prebuilt/components/Polls/Voting/PollResultSummary.jsx +0 -125
  43. /package/dist/{HLSView-GG4WVUQY.js.map → HLSView-7X5BVAZE.js.map} +0 -0
@@ -0,0 +1,72 @@
1
+ import { HMSEffectsPlugin, HMSVBPlugin, HMSVirtualBackgroundTypes } from '@100mslive/hms-virtual-background';
2
+
3
+ export class VBPlugin {
4
+ private hmsPlugin?: HMSVBPlugin;
5
+ private effectsPlugin?: HMSEffectsPlugin | undefined;
6
+
7
+ initialisePlugin = (effectsSDKKey?: string) => {
8
+ if (this.getVBObject()) {
9
+ return;
10
+ }
11
+ if (effectsSDKKey) {
12
+ this.effectsPlugin = new HMSEffectsPlugin(effectsSDKKey);
13
+ } else {
14
+ this.hmsPlugin = new HMSVBPlugin(HMSVirtualBackgroundTypes.NONE, HMSVirtualBackgroundTypes.NONE);
15
+ }
16
+ };
17
+
18
+ getBackground = () => {
19
+ if (this.effectsPlugin) {
20
+ return this.effectsPlugin?.getBackground();
21
+ } else {
22
+ // @ts-ignore
23
+ return this.hmsPlugin?.background?.src || this.hmsPlugin?.background;
24
+ }
25
+ };
26
+
27
+ getVBObject = () => {
28
+ return this.effectsPlugin || this.hmsPlugin;
29
+ };
30
+
31
+ getName = () => {
32
+ return this.effectsPlugin ? this.effectsPlugin?.getName() : this.hmsPlugin?.getName();
33
+ };
34
+
35
+ setBlur = async (blurPower: number) => {
36
+ if (this.effectsPlugin) {
37
+ this.effectsPlugin?.setBlur(blurPower);
38
+ } else {
39
+ await this.hmsPlugin?.setBackground(HMSVirtualBackgroundTypes.BLUR, HMSVirtualBackgroundTypes.BLUR);
40
+ }
41
+ };
42
+
43
+ setBackground = async (mediaURL: string) => {
44
+ if (this.effectsPlugin) {
45
+ this.effectsPlugin?.setBackground(mediaURL);
46
+ } else {
47
+ const img = document.createElement('img');
48
+ let retries = 0;
49
+ const MAX_RETRIES = 3;
50
+ img.alt = 'VB';
51
+ img.src = mediaURL;
52
+ try {
53
+ await this.hmsPlugin?.setBackground(img, HMSVirtualBackgroundTypes.IMAGE);
54
+ } catch (e) {
55
+ console.error(e);
56
+ if (retries++ < MAX_RETRIES) {
57
+ await this.hmsPlugin?.setBackground(img, HMSVirtualBackgroundTypes.IMAGE);
58
+ }
59
+ }
60
+ }
61
+ };
62
+
63
+ removeEffects = async () => {
64
+ if (this.effectsPlugin) {
65
+ this.effectsPlugin?.removeEffects();
66
+ } else {
67
+ await this.hmsPlugin?.setBackground(HMSVirtualBackgroundTypes.NONE, HMSVirtualBackgroundTypes.NONE);
68
+ }
69
+ };
70
+ }
71
+
72
+ export const VBHandler = new VBPlugin();
@@ -1,13 +1,13 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import { HMSVirtualBackgroundTypes } from '@100mslive/hms-virtual-background';
3
- import { VirtualBackground, VirtualBackgroundMedia } from '@100mslive/types-prebuilt/elements/virtual_background';
1
+ import React, { useEffect, useState } from 'react';
2
+ import { selectEffectsKey, selectIsEffectsEnabled, selectLocalPeerRole } from '@100mslive/hms-video-store';
3
+ import { HMSEffectsPlugin, HMSVBPlugin, HMSVirtualBackgroundTypes } from '@100mslive/hms-virtual-background';
4
+ import { VirtualBackgroundMedia } from '@100mslive/types-prebuilt/elements/virtual_background';
4
5
  import {
5
6
  HMSRoomState,
6
7
  selectIsLargeRoom,
7
8
  selectIsLocalVideoEnabled,
9
+ selectIsLocalVideoPluginPresent,
8
10
  selectLocalPeer,
9
- selectLocalPeerRole,
10
- selectLocalVideoTrackID,
11
11
  selectRoomState,
12
12
  selectVideoTrackByID,
13
13
  useHMSActions,
@@ -17,94 +17,58 @@ import { BlurPersonHighIcon, CloseIcon, CrossCircleIcon } from '@100mslive/react
17
17
  import { Box, Flex, Video } from '../../../index';
18
18
  import { Text } from '../../../Text';
19
19
  import { VBCollection } from './VBCollection';
20
+ import { VBHandler } from './VBHandler';
20
21
  // @ts-ignore
21
22
  import { useSidepaneToggle } from '../AppData/useSidepane';
22
23
  // @ts-ignore
23
24
  import { useUISettings } from '../AppData/useUISettings';
24
- // @ts-ignore
25
25
  import { SIDE_PANE_OPTIONS, UI_SETTINGS } from '../../common/constants';
26
- import { defaultMedia, vbPlugin } from './constants';
26
+ import { defaultMedia } from './constants';
27
27
 
28
28
  const iconDims = { height: '40px', width: '40px' };
29
- const MAX_RETRIES = 2;
30
29
 
31
- export const VBPicker = ({ background_media = [] }: VirtualBackground = {}) => {
30
+ export const VBPicker = ({ backgroundMedia = [] }: { backgroundMedia: VirtualBackgroundMedia[] }) => {
32
31
  const toggleVB = useSidepaneToggle(SIDE_PANE_OPTIONS.VB);
33
32
  const hmsActions = useHMSActions();
34
- const role = useHMSStore(selectLocalPeerRole);
35
- const [isVBSupported, setIsVBSupported] = useState(false);
36
- const localPeerVideoTrackID = useHMSStore(selectLocalVideoTrackID);
37
33
  const localPeer = useHMSStore(selectLocalPeer);
38
- // @ts-ignore
39
- const [background, setBackground] = useState(vbPlugin.background);
40
- // @ts-ignore
41
- const [backgroundType, setBackgroundType] = useState(vbPlugin.backgroundType);
34
+ const role = useHMSStore(selectLocalPeerRole);
42
35
  const isVideoOn = useHMSStore(selectIsLocalVideoEnabled);
43
36
  const mirrorLocalVideo = useUISettings(UI_SETTINGS.mirrorLocalVideo);
44
37
  const trackSelector = selectVideoTrackByID(localPeer?.videoTrack);
45
38
  const track = useHMSStore(trackSelector);
46
39
  const roomState = useHMSStore(selectRoomState);
47
40
  const isLargeRoom = useHMSStore(selectIsLargeRoom);
48
- const addedPluginToVideoTrack = useRef(false);
49
- const mediaList = [...background_media.map((media: VirtualBackgroundMedia) => media?.url), ...defaultMedia];
41
+ const isEffectsEnabled = useHMSStore(selectIsEffectsEnabled);
42
+ const effectsKey = useHMSStore(selectEffectsKey);
43
+ const isPluginAdded = useHMSStore(selectIsLocalVideoPluginPresent(VBHandler?.getName() || ''));
44
+ const [activeBackground, setActiveBackground] = useState<string | HMSVirtualBackgroundTypes>(
45
+ (VBHandler?.getBackground() as string | HMSVirtualBackgroundTypes) || HMSVirtualBackgroundTypes.NONE,
46
+ );
47
+ const mediaList = backgroundMedia.length
48
+ ? backgroundMedia.map((media: VirtualBackgroundMedia) => media.url || '')
49
+ : defaultMedia;
50
50
 
51
51
  const inPreview = roomState === HMSRoomState.Preview;
52
- // Hidden in preview as the effect will be visible in the preview tile. Needed inside the room because the peer might not be on-screen
52
+ // Hidden in preview as the effect will be visible in the preview tile
53
53
  const showVideoTile = isVideoOn && isLargeRoom && !inPreview;
54
54
 
55
- const clearVBState = () => {
56
- setBackground(HMSVirtualBackgroundTypes.NONE);
57
- setBackgroundType(HMSVirtualBackgroundTypes.NONE);
58
- };
59
-
60
55
  useEffect(() => {
61
- if (!localPeerVideoTrackID) {
62
- return;
63
- }
64
-
65
- //check support of plugin
66
- if (vbPlugin) {
67
- const pluginSupport = hmsActions.validateVideoPluginSupport(vbPlugin);
68
- setIsVBSupported(pluginSupport.isSupported);
69
- }
70
- }, [hmsActions, localPeerVideoTrackID]);
71
-
72
- async function disableEffects() {
73
- if (vbPlugin) {
74
- vbPlugin.setBackground(HMSVirtualBackgroundTypes.NONE, HMSVirtualBackgroundTypes.NONE);
75
- clearVBState();
76
- }
77
- }
78
-
79
- async function addPlugin({ mediaURL = '', blurPower = 0 }) {
80
- let retries = 0;
81
- try {
82
- if (mediaURL) {
83
- const img = document.createElement('img');
84
- img.alt = 'VB';
85
- img.src = mediaURL;
86
- try {
87
- await vbPlugin.setBackground(img, HMSVirtualBackgroundTypes.IMAGE);
88
- } catch (e) {
89
- console.error(e);
90
- if (retries++ < MAX_RETRIES) {
91
- await vbPlugin.setBackground(img, HMSVirtualBackgroundTypes.IMAGE);
56
+ if (!isPluginAdded) {
57
+ let vbObject = VBHandler.getVBObject();
58
+ if (!vbObject) {
59
+ VBHandler.initialisePlugin(isEffectsEnabled && effectsKey ? effectsKey : '');
60
+ vbObject = VBHandler.getVBObject();
61
+ if (isEffectsEnabled && effectsKey) {
62
+ hmsActions.addPluginsToVideoStream([vbObject as HMSEffectsPlugin]);
63
+ } else {
64
+ if (!role) {
65
+ return;
92
66
  }
67
+ hmsActions.addPluginToVideoTrack(vbObject as HMSVBPlugin, Math.floor(role.publishParams.video.frameRate / 2));
93
68
  }
94
- } else if (blurPower) {
95
- await vbPlugin.setBackground(HMSVirtualBackgroundTypes.BLUR, HMSVirtualBackgroundTypes.BLUR);
96
- }
97
- setBackground(mediaURL || HMSVirtualBackgroundTypes.BLUR);
98
- setBackgroundType(mediaURL ? HMSVirtualBackgroundTypes.IMAGE : HMSVirtualBackgroundTypes.BLUR);
99
- if (role && !addedPluginToVideoTrack.current) {
100
- await hmsActions.addPluginToVideoTrack(vbPlugin, Math.floor(role.publishParams.video.frameRate / 2));
101
- addedPluginToVideoTrack.current = true;
102
69
  }
103
- } catch (err) {
104
- console.error('Failed to apply VB', err);
105
- disableEffects();
106
70
  }
107
- }
71
+ }, [hmsActions, role, isPluginAdded, isEffectsEnabled, effectsKey]);
108
72
 
109
73
  useEffect(() => {
110
74
  if (!isVideoOn) {
@@ -112,10 +76,6 @@ export const VBPicker = ({ background_media = [] }: VirtualBackground = {}) => {
112
76
  }
113
77
  }, [isVideoOn, toggleVB]);
114
78
 
115
- if (!isVBSupported) {
116
- return null;
117
- }
118
-
119
79
  return (
120
80
  <Flex css={{ pr: '$6', size: '100%' }} direction="column">
121
81
  <Flex align="center" justify="between" css={{ w: '100%', background: '$surface_dim', pb: '$4' }}>
@@ -138,7 +98,6 @@ export const VBPicker = ({ background_media = [] }: VirtualBackground = {}) => {
138
98
  css={{ width: '100%', height: '16rem' }}
139
99
  />
140
100
  ) : null}
141
-
142
101
  <Box
143
102
  css={{
144
103
  mt: '$4',
@@ -154,30 +113,36 @@ export const VBPicker = ({ background_media = [] }: VirtualBackground = {}) => {
154
113
  {
155
114
  title: 'No effect',
156
115
  icon: <CrossCircleIcon style={iconDims} />,
157
- type: HMSVirtualBackgroundTypes.NONE,
158
- onClick: async () => await disableEffects(),
116
+ value: HMSVirtualBackgroundTypes.NONE,
117
+ onClick: async () => {
118
+ await VBHandler.removeEffects();
119
+ setActiveBackground(HMSVirtualBackgroundTypes.NONE);
120
+ },
159
121
  },
160
122
  {
161
123
  title: 'Blur',
162
124
  icon: <BlurPersonHighIcon style={iconDims} />,
163
- type: HMSVirtualBackgroundTypes.BLUR,
164
- onClick: async () => await addPlugin({ blurPower: 0.5 }),
125
+ value: HMSVirtualBackgroundTypes.BLUR,
126
+ onClick: async () => {
127
+ await VBHandler?.setBlur(0.5);
128
+ setActiveBackground(HMSVirtualBackgroundTypes.BLUR);
129
+ },
165
130
  },
166
131
  ]}
167
- activeBackgroundType={backgroundType || HMSVirtualBackgroundTypes.NONE}
168
- // @ts-ignore
169
- activeBackground={vbPlugin.background?.src || vbPlugin.background || HMSVirtualBackgroundTypes.NONE}
132
+ activeBackground={activeBackground}
170
133
  />
171
134
 
172
135
  <VBCollection
173
136
  title="Backgrounds"
174
137
  options={mediaList.map(mediaURL => ({
175
- type: HMSVirtualBackgroundTypes.IMAGE,
176
138
  mediaURL,
177
- onClick: async () => await addPlugin({ mediaURL }),
139
+ value: mediaURL,
140
+ onClick: async () => {
141
+ await VBHandler?.setBackground(mediaURL);
142
+ setActiveBackground(mediaURL);
143
+ },
178
144
  }))}
179
- activeBackgroundType={backgroundType || HMSVirtualBackgroundTypes.NONE}
180
- activeBackground={background?.src || background || HMSVirtualBackgroundTypes.NONE}
145
+ activeBackground={activeBackground}
181
146
  />
182
147
  </Box>
183
148
  </Flex>
@@ -1,5 +1,3 @@
1
- import { HMSVBPlugin, HMSVirtualBackgroundTypes } from '@100mslive/hms-virtual-background';
2
-
3
1
  export const defaultMedia = [
4
2
  'https://assets.100ms.live/webapp/vb-mini/vb-1.jpg',
5
3
  'https://assets.100ms.live/webapp/vb-mini/vb-2.jpg',
@@ -14,5 +12,3 @@ export const defaultMedia = [
14
12
  'https://assets.100ms.live/webapp/vb-mini/vb-11.jpg',
15
13
  'https://assets.100ms.live/webapp/vb-mini/vb-12.jpg',
16
14
  ];
17
-
18
- export const vbPlugin = new HMSVBPlugin(HMSVirtualBackgroundTypes.NONE, HMSVirtualBackgroundTypes.NONE);
@@ -12,7 +12,10 @@ import { Box, Flex } from '../../Layout';
12
12
  import { config as cssConfig } from '../../Theme';
13
13
  // @ts-ignore: No implicit Any
14
14
  import { useSidepaneReset } from '../components/AppData/useSidepane';
15
- import { useRoomLayoutConferencingScreen } from '../provider/roomLayoutProvider/hooks/useRoomLayoutScreen';
15
+ import {
16
+ useRoomLayoutConferencingScreen,
17
+ useRoomLayoutPreviewScreen,
18
+ } from '../provider/roomLayoutProvider/hooks/useRoomLayoutScreen';
16
19
  import { translateAcross } from '../../utils';
17
20
  import { APP_DATA, SIDE_PANE_OPTIONS } from '../common/constants';
18
21
 
@@ -28,6 +31,12 @@ const SidePane = ({
28
31
  const activeScreensharePeerId = useHMSStore(selectAppData(APP_DATA.activeScreensharePeerId));
29
32
  const trackId = useHMSStore(selectVideoTrackByPeerID(activeScreensharePeerId))?.id;
30
33
  const { elements } = useRoomLayoutConferencingScreen();
34
+ const { elements: preview_elements } = useRoomLayoutPreviewScreen();
35
+
36
+ const backgroundMedia = preview_elements?.virtual_background?.background_media?.length
37
+ ? preview_elements?.virtual_background?.background_media
38
+ : elements?.virtual_background?.background_media || [];
39
+
31
40
  const resetSidePane = useSidepaneReset();
32
41
  let ViewComponent;
33
42
  if (sidepane === SIDE_PANE_OPTIONS.POLLS) {
@@ -37,7 +46,7 @@ const SidePane = ({
37
46
  ViewComponent = <SidePaneTabs hideControls={hideControls} active={sidepane} />;
38
47
  }
39
48
  if (sidepane === SIDE_PANE_OPTIONS.VB) {
40
- ViewComponent = <VBPicker {...elements.virtual_background} />;
49
+ ViewComponent = <VBPicker backgroundMedia={backgroundMedia} />;
41
50
  }
42
51
 
43
52
  useEffect(() => {
@@ -18,11 +18,14 @@ export const RoomLayoutContext = React.createContext<
18
18
  | undefined
19
19
  >(undefined);
20
20
 
21
+ // The default merge in lodash merges the values of current layout and the changes.
22
+ // This behaviour makes changes in array based values inconsistent since a union happens.
23
+ // The customizer uses the new value provided if one of the values is an array
21
24
  function customizer(objValue: any, srcValue: any) {
22
- if (isArray(objValue) && isArray(srcValue)) {
25
+ if (isArray(objValue) || isArray(srcValue)) {
23
26
  return srcValue;
24
27
  }
25
- // default mergeWith behaviour is followed
28
+ // default merge behaviour is followed
26
29
  return undefined;
27
30
  }
28
31
 
@@ -34,7 +37,6 @@ export const RoomLayoutProvider: React.FC<React.PropsWithChildren<RoomLayoutProv
34
37
  const authToken: string = useAuthToken();
35
38
  const { layout, updateRoomLayoutForRole } = useFetchRoomLayout({ authToken, endpoint: roomLayoutEndpoint });
36
39
  const mergedLayout = authToken && layout ? mergeWith(layout, overrideLayout, customizer) : layout;
37
-
38
40
  return (
39
41
  <RoomLayoutContext.Provider value={{ layout: mergedLayout, updateRoomLayoutForRole }}>
40
42
  {children}
@@ -2,6 +2,7 @@ import type * as Stitches from '@stitches/react';
2
2
  import { createStitches } from '@stitches/react';
3
3
  import merge from 'lodash.merge';
4
4
  import { baseConfig, defaultMedia, defaultThemeMap, defaultUtils } from './base.config';
5
+ import { DEFAULT_PORTAL_CONTAINER } from '../Prebuilt/common/constants';
5
6
 
6
7
  const HmsStitches = createStitches({
7
8
  prefix: 'hms-ui',
@@ -28,18 +29,9 @@ export const {
28
29
  } = HmsStitches;
29
30
 
30
31
  export const globalStyles = globalCss({
31
- '*': {
32
+ [`${DEFAULT_PORTAL_CONTAINER} *`]: {
32
33
  fontFamily: '$sans',
33
34
  boxSizing: 'border-box',
34
- borderWidth: 0,
35
- borderStyle: 'solid',
36
- },
37
- body: {
38
- margin: 0,
39
- },
40
- '#root': {
41
- height: '100%',
42
- overscrollBehaviorY: 'none',
43
35
  },
44
36
  '::-webkit-scrollbar-track': {
45
37
  WebkitBoxShadow: 'inset 0 0 6px rgba(0, 0, 0, 0.3)',