/
VideoStreamingSection.tsx
133 lines (127 loc) · 4.5 KB
/
VideoStreamingSection.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import React, { Suspense, useEffect } from 'react';
import {
ConferencingScreen,
DefaultConferencingScreen_Elements,
HLSLiveStreamingScreen_Elements,
} from '@100mslive/types-prebuilt';
import { match } from 'ts-pattern';
import { selectIsConnectedToRoom, selectLocalPeerRoleName, useHMSActions, useHMSStore } from '@100mslive/react-sdk';
import FullPageProgress from '../components/FullPageProgress';
import { GridLayout } from '../components/VideoLayouts/GridLayout';
import { Box, Flex } from '../../Layout';
// @ts-ignore: No implicit Any
import { EmbedView } from './EmbedView';
// @ts-ignore: No implicit Any
import { PDFView } from './PDFView';
import SidePane from './SidePane';
// @ts-ignore: No implicit Any
import { WaitingView } from './WaitingView';
import { CaptionsViewer } from '../plugins/CaptionsViewer';
// @ts-ignore: No implicit Any
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 { SESSION_STORE_KEY } from '../common/constants';
// @ts-ignore: No implicit Any
const HLSView = React.lazy(() => import('./HLSView'));
export const VideoStreamingSection = ({
screenType,
elements,
hideControls = false,
}: {
screenType: keyof ConferencingScreen;
elements: DefaultConferencingScreen_Elements | HLSLiveStreamingScreen_Elements;
hideControls: boolean;
}) => {
const localPeerRole = useHMSStore(selectLocalPeerRoleName);
const isConnected = useHMSStore(selectIsConnectedToRoom);
const hmsActions = useHMSActions();
const waitingViewerRole = useWaitingViewerRole();
const urlToIframe = useUrlToEmbed();
const pdfAnnotatorActive = usePDFConfig();
const isMobileHLSStream = useMobileHLSStream();
const isLandscapeHLSStream = useLandscapeHLSStream();
useCloseScreenshareWhiteboard();
useEffect(() => {
if (!isConnected) {
return;
}
hmsActions.sessionStore.observe([
SESSION_STORE_KEY.PINNED_MESSAGES,
SESSION_STORE_KEY.SPOTLIGHT,
SESSION_STORE_KEY.CHAT_STATE,
SESSION_STORE_KEY.CHAT_MESSAGE_BLACKLIST,
SESSION_STORE_KEY.CHAT_PEER_BLACKLIST,
]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isConnected, hmsActions]);
if (!localPeerRole) {
// we don't know the role yet to decide how to render UI
return null;
}
return (
<Suspense fallback={<FullPageProgress />}>
<Flex
css={{
size: '100%',
position: 'relative',
gap: isMobileHLSStream || isLandscapeHLSStream ? '0' : '$4',
}}
direction={match<Record<string, boolean>, 'row' | 'column'>({ isLandscapeHLSStream, isMobileHLSStream })
.with({ isLandscapeHLSStream: true }, () => 'row')
.with({ isMobileHLSStream: true }, () => 'column')
.otherwise(() => 'row')}
>
{match({ screenType, localPeerRole, pdfAnnotatorActive, urlToIframe })
.with(
{
screenType: 'hls_live_streaming',
},
() => <HLSView />,
)
.when(
({ localPeerRole }) => localPeerRole === waitingViewerRole,
() => <WaitingView />,
)
.when(
({ pdfAnnotatorActive }) => !!pdfAnnotatorActive,
() => <PDFView />,
)
.when(
({ urlToIframe }) => !!urlToIframe,
() => <EmbedView />,
)
.otherwise(() => {
// @ts-ignore
return <GridLayout {...(elements as DefaultConferencingScreen_Elements)?.video_tile_layout?.grid} />;
})}
<CaptionsViewer />
<Box
css={{
flex: match({ isLandscapeHLSStream, isMobileHLSStream })
.with({ isLandscapeHLSStream: true }, () => '1 1 0')
.with({ isMobileHLSStream: true }, () => '2 1 0')
.otherwise(() => undefined),
position: 'relative',
height: !isMobileHLSStream ? '100%' : undefined,
maxHeight: '100%',
'&:empty': { display: 'none' },
overflowY: 'clip',
}}
>
<SidePane
screenType={screenType}
// @ts-ignore
tileProps={(elements as DefaultConferencingScreen_Elements)?.video_tile_layout?.grid}
hideControls={hideControls}
/>
</Box>
</Flex>
</Suspense>
);
};