-
Notifications
You must be signed in to change notification settings - Fork 733
/
Copy pathMenu.tsx
195 lines (181 loc) · 6.62 KB
/
Menu.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import React, { useState, useRef } from 'react';
import AboutDialog from '../../AboutDialog/AboutDialog';
import BackgroundIcon from '../../../icons/BackgroundIcon';
import MaskIcon from '../../../icons/MaskIcon';
import CollaborationViewIcon from '@material-ui/icons/AccountBox';
import DeviceSelectionDialog from '../../DeviceSelectionDialog/DeviceSelectionDialog';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import GridViewIcon from '@material-ui/icons/Apps';
import InfoIconOutlined from '../../../icons/InfoIconOutlined';
import MoreIcon from '@material-ui/icons/MoreVert';
import StartRecordingIcon from '../../../icons/StartRecordingIcon';
import StopRecordingIcon from '../../../icons/StopRecordingIcon';
import SearchIcon from '@material-ui/icons/Search';
import SettingsIcon from '../../../icons/SettingsIcon';
import { Button, styled, Theme, useMediaQuery, Menu as MenuContainer, MenuItem, Typography } from '@material-ui/core';
import { isSupported } from '@twilio/video-processors';
import { useAppState } from '../../../state';
import useChatContext from '../../../hooks/useChatContext/useChatContext';
import useIsRecording from '../../../hooks/useIsRecording/useIsRecording';
import useVideoContext from '../../../hooks/useVideoContext/useVideoContext';
import FlipCameraIcon from '../../../icons/FlipCameraIcon';
import useFlipCameraToggle from '../../../hooks/useFlipCameraToggle/useFlipCameraToggle';
import { VideoRoomMonitor } from '@twilio/video-room-monitor';
export const IconContainer = styled('div')({
display: 'flex',
justifyContent: 'center',
width: '1.5em',
marginRight: '0.3em',
});
export default function Menu(props: { buttonClassName?: string }) {
const isMobile = useMediaQuery((theme: Theme) => theme.breakpoints.down('sm'));
const [aboutOpen, setAboutOpen] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const [settingsOpen, setSettingsOpen] = useState(false);
const { isFetching, updateRecordingRules, roomType, setIsGalleryViewActive, isGalleryViewActive } = useAppState();
const { setIsChatWindowOpen } = useChatContext();
const isRecording = useIsRecording();
const { room, setIsBackgroundSelectionOpen, setIsMaskSelectionOpen } = useVideoContext();
const anchorRef = useRef<HTMLButtonElement>(null);
const { flipCameraDisabled, toggleFacingMode, flipCameraSupported } = useFlipCameraToggle();
return (
<>
<Button
onClick={() => setMenuOpen(isOpen => !isOpen)}
ref={anchorRef}
className={props.buttonClassName}
data-cy-more-button
>
{isMobile ? (
<MoreIcon />
) : (
<>
More
<ExpandMoreIcon />
</>
)}
</Button>
<MenuContainer
open={menuOpen}
onClose={() => setMenuOpen(isOpen => !isOpen)}
anchorEl={anchorRef.current}
anchorOrigin={{
vertical: 'top',
horizontal: 'left',
}}
transformOrigin={{
vertical: isMobile ? -55 : 'bottom',
horizontal: 'center',
}}
>
<MenuItem onClick={() => setSettingsOpen(true)}>
<IconContainer>
<SettingsIcon />
</IconContainer>
<Typography variant="body1">Audio and Video Settings</Typography>
</MenuItem>
{isSupported && (
<MenuItem
onClick={() => {
setIsBackgroundSelectionOpen(true);
setIsMaskSelectionOpen(false);
setIsChatWindowOpen(false);
setMenuOpen(false);
}}
>
<IconContainer>
<BackgroundIcon />
</IconContainer>
<Typography variant="body1">Backgrounds</Typography>
</MenuItem>
)}
{isSupported && (
<MenuItem
onClick={() => {
setIsBackgroundSelectionOpen(false);
setIsMaskSelectionOpen(true);
setIsChatWindowOpen(false);
setMenuOpen(false);
}}
>
<IconContainer>
<MaskIcon />
</IconContainer>
<Typography variant="body1">Face Effects</Typography>
</MenuItem>
)}
{flipCameraSupported && (
<MenuItem disabled={flipCameraDisabled} onClick={toggleFacingMode}>
<IconContainer>
<FlipCameraIcon />
</IconContainer>
<Typography variant="body1">Flip Camera</Typography>
</MenuItem>
)}
{roomType !== 'peer-to-peer' && roomType !== 'go' && (
<MenuItem
disabled={isFetching}
onClick={() => {
setMenuOpen(false);
if (isRecording) {
updateRecordingRules(room!.sid, [{ type: 'exclude', all: true }]);
} else {
updateRecordingRules(room!.sid, [{ type: 'include', all: true }]);
}
}}
data-cy-recording-button
>
<IconContainer>{isRecording ? <StopRecordingIcon /> : <StartRecordingIcon />}</IconContainer>
<Typography variant="body1">{isRecording ? 'Stop' : 'Start'} Recording</Typography>
</MenuItem>
)}
<MenuItem
onClick={() => {
VideoRoomMonitor.toggleMonitor();
setMenuOpen(false);
}}
>
<IconContainer>
<SearchIcon style={{ fill: '#707578', width: '0.9em' }} />
</IconContainer>
<Typography variant="body1">Room Monitor</Typography>
</MenuItem>
<MenuItem
onClick={() => {
setIsGalleryViewActive(isGallery => !isGallery);
setMenuOpen(false);
}}
>
<IconContainer>
{isGalleryViewActive ? (
<CollaborationViewIcon style={{ fill: '#707578', width: '0.9em' }} />
) : (
<GridViewIcon style={{ fill: '#707578', width: '0.9em' }} />
)}
</IconContainer>
<Typography variant="body1">{isGalleryViewActive ? 'Speaker View' : 'Gallery View'}</Typography>
</MenuItem>
<MenuItem onClick={() => setAboutOpen(true)}>
<IconContainer>
<InfoIconOutlined />
</IconContainer>
<Typography variant="body1">About</Typography>
</MenuItem>
</MenuContainer>
<AboutDialog
open={aboutOpen}
onClose={() => {
setAboutOpen(false);
setMenuOpen(false);
}}
/>
<DeviceSelectionDialog
open={settingsOpen}
onClose={() => {
setSettingsOpen(false);
setMenuOpen(false);
}}
/>
</>
);
}