simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 18 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 19 | import { IconButton, IconButtonProps, PaletteColor } from '@mui/material'; |
| 20 | import { styled, Theme } from '@mui/material/styles'; |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 21 | import { useContext, useMemo } from 'react'; |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 22 | import { useTranslation } from 'react-i18next'; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 23 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 24 | import { CallContext } from '../contexts/CallProvider'; |
| 25 | import { ExpandableButton, ExpandableButtonProps, ShapedButtonProps, ToggleIconButton } from './Button'; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 26 | import { |
| 27 | CallEndIcon, |
| 28 | ChatBubbleIcon, |
| 29 | ExtensionIcon, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 30 | FileIcon, |
| 31 | FullScreenIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 32 | GroupAddIcon, |
| 33 | MicroIcon, |
| 34 | MicroOffIcon, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 35 | MoreVerticalIcon, |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 36 | PlaceAudioCallIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 37 | RecordingIcon, |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 38 | RoundCloseIcon, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 39 | ScreenShareArrowIcon, |
| 40 | ScreenShareRegularIcon, |
| 41 | ScreenShareScreenAreaIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 42 | VideoCameraIcon, |
| 43 | VideoCameraOffIcon, |
| 44 | VolumeIcon, |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 45 | WindowIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 46 | } from './SvgIcon'; |
| 47 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 48 | const CallButton = styled((props: ExpandableButtonProps) => { |
| 49 | return <ExpandableButton {...props} />; |
| 50 | })({ |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 51 | color: 'white', |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 52 | '&:hover': { |
| 53 | backgroundColor: 'rgba(255, 255, 255, 0.15)', |
| 54 | }, |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 55 | }); |
| 56 | |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 57 | const ColoredCallButton = styled( |
| 58 | ({ |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 59 | paletteColor, |
| 60 | Icon, |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 61 | ...props |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 62 | }: ShapedButtonProps & { |
| 63 | paletteColor?: PaletteColor | ((theme: Theme) => PaletteColor); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 64 | }) => { |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 65 | return ( |
| 66 | <IconButton {...props} disableRipple={true}> |
| 67 | <Icon fontSize="inherit" /> |
| 68 | </IconButton> |
| 69 | ); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 70 | } |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 71 | )(({ theme, paletteColor = theme.palette.primary }) => { |
| 72 | if (typeof paletteColor === 'function') { |
| 73 | paletteColor = paletteColor(theme); |
| 74 | } |
| 75 | |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 76 | return { |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 77 | color: paletteColor.contrastText, |
| 78 | backgroundColor: paletteColor.dark, |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 79 | '&:hover': { |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 80 | backgroundColor: paletteColor.main, |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 81 | }, |
| 82 | }; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 83 | }); |
| 84 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 85 | export const CallingChatButton = (props: ExpandableButtonProps) => { |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 86 | const { setIsChatShown } = useContext(CallContext); |
| 87 | return ( |
| 88 | <CallButton |
| 89 | aria-label="chat" |
| 90 | Icon={ChatBubbleIcon} |
| 91 | onClick={() => { |
| 92 | setIsChatShown((v) => !v); |
| 93 | }} |
| 94 | {...props} |
| 95 | /> |
| 96 | ); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 97 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 98 | |
| 99 | export const CallingEndButton = (props: ExpandableButtonProps) => { |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 100 | const { endCall } = useContext(CallContext); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 101 | return ( |
| 102 | <ColoredCallButton |
| 103 | paletteColor={(theme) => theme.palette.error} |
| 104 | onClick={() => { |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 105 | endCall(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 106 | }} |
| 107 | aria-label="call end" |
| 108 | Icon={CallEndIcon} |
| 109 | {...props} |
| 110 | /> |
| 111 | ); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 112 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 113 | |
| 114 | export const CallingExtensionButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 115 | return <CallButton aria-label="extensions" Icon={ExtensionIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 116 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 117 | |
| 118 | export const CallingFullScreenButton = (props: ExpandableButtonProps) => { |
simon | 2a5cf14 | 2022-11-25 15:47:35 -0500 | [diff] [blame] | 119 | const { setIsFullscreen } = useContext(CallContext); |
| 120 | return ( |
| 121 | <CallButton |
| 122 | aria-label="full screen" |
| 123 | Icon={FullScreenIcon} |
| 124 | onClick={() => { |
| 125 | setIsFullscreen((v) => !v); |
| 126 | }} |
| 127 | {...props} |
| 128 | /> |
| 129 | ); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 130 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 131 | |
| 132 | export const CallingGroupButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 133 | return <CallButton aria-label="group options" Icon={GroupAddIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 134 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 135 | |
| 136 | export const CallingMoreVerticalButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 137 | return <CallButton aria-label="more vertical" Icon={MoreVerticalIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 138 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 139 | |
| 140 | export const CallingRecordButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 141 | return <CallButton aria-label="recording options" Icon={RecordingIcon} {...props} />; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | export const CallingScreenShareButton = (props: ExpandableButtonProps) => { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 145 | const { t } = useTranslation(); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 146 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 147 | <CallButton |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 148 | aria-label="screen share" |
| 149 | Icon={ScreenShareArrowIcon} |
| 150 | expandMenuOptions={[ |
| 151 | { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 152 | description: t('share_screen'), |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 153 | icon: <ScreenShareRegularIcon />, |
| 154 | }, |
| 155 | { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 156 | description: t('share_window'), |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 157 | icon: <WindowIcon />, |
| 158 | }, |
| 159 | { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 160 | description: t('share_screen_area'), |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 161 | icon: <ScreenShareScreenAreaIcon />, |
| 162 | }, |
| 163 | { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 164 | description: t('share_file'), |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 165 | icon: <FileIcon />, |
| 166 | }, |
| 167 | ]} |
| 168 | {...props} |
| 169 | /> |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 170 | ); |
| 171 | }; |
| 172 | |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 173 | const useMediaDeviceExpandMenuOptions = (kind: MediaDeviceKind) => { |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 174 | const { mediaDevices } = useContext(CallContext); |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 175 | |
| 176 | return useMemo( |
| 177 | () => |
| 178 | mediaDevices[kind].map((device) => ({ |
| 179 | key: device.deviceId, |
| 180 | description: device.label, |
| 181 | })), |
| 182 | [mediaDevices, kind] |
| 183 | ); |
| 184 | }; |
| 185 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 186 | export const CallingVolumeButton = (props: ExpandableButtonProps) => { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 187 | const options = useMediaDeviceExpandMenuOptions('audiooutput'); |
| 188 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 189 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 190 | <CallButton |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 191 | aria-label="volume options" |
| 192 | Icon={VolumeIcon} |
| 193 | expandMenuOptions={[ |
| 194 | { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 195 | options, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 196 | }, |
| 197 | ]} |
| 198 | {...props} |
| 199 | /> |
| 200 | ); |
| 201 | }; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 202 | |
| 203 | export const CallingMicButton = (props: ExpandableButtonProps) => { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 204 | const options = useMediaDeviceExpandMenuOptions('audioinput'); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 205 | |
| 206 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 207 | <CallButton |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 208 | aria-label="microphone options" |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 209 | expandMenuOptions={[ |
| 210 | { |
| 211 | options, |
| 212 | }, |
| 213 | ]} |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 214 | IconButtonComp={ToggleAudioCameraIconButton} |
| 215 | {...props} |
| 216 | /> |
| 217 | ); |
| 218 | }; |
| 219 | |
| 220 | const ToggleAudioCameraIconButton = (props: IconButtonProps) => { |
| 221 | const { isAudioOn, setAudioStatus } = useContext(CallContext); |
| 222 | return ( |
| 223 | <ToggleIconButton |
| 224 | IconOn={MicroIcon} |
| 225 | IconOff={MicroOffIcon} |
| 226 | selected={isAudioOn} |
| 227 | toggle={() => setAudioStatus(!isAudioOn)} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 228 | {...props} |
| 229 | /> |
| 230 | ); |
| 231 | }; |
| 232 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 233 | export const CallingVideoCameraButton = (props: ExpandableButtonProps) => { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 234 | const options = useMediaDeviceExpandMenuOptions('videoinput'); |
| 235 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 236 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 237 | <CallButton |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 238 | aria-label="camera options" |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 239 | expandMenuOptions={[ |
| 240 | { |
| 241 | options, |
| 242 | }, |
| 243 | ]} |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 244 | IconButtonComp={ToggleVideoCameraIconButton} |
| 245 | {...props} |
| 246 | /> |
| 247 | ); |
| 248 | }; |
| 249 | |
| 250 | const ToggleVideoCameraIconButton = (props: IconButtonProps) => { |
| 251 | const { isVideoOn, setVideoStatus } = useContext(CallContext); |
| 252 | return ( |
| 253 | <ToggleIconButton |
| 254 | IconOn={VideoCameraIcon} |
| 255 | IconOff={VideoCameraOffIcon} |
| 256 | selected={isVideoOn} |
| 257 | toggle={() => setVideoStatus(!isVideoOn)} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 258 | {...props} |
| 259 | /> |
| 260 | ); |
| 261 | }; |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 262 | |
| 263 | // Calling pending/receiving interface |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 264 | export const CallingCancelButton = (props: IconButtonProps) => { |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 265 | const { endCall } = useContext(CallContext); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 266 | |
| 267 | return ( |
| 268 | <ColoredCallButton |
| 269 | aria-label="cancel call" |
| 270 | onClick={() => { |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 271 | endCall(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 272 | }} |
| 273 | Icon={CallEndIcon} |
| 274 | paletteColor={(theme) => theme.palette.error} |
| 275 | {...props} |
| 276 | /> |
| 277 | ); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 278 | }; |
| 279 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 280 | export const CallingAnswerAudioButton = (props: IconButtonProps) => { |
| 281 | const { acceptCall } = useContext(CallContext); |
| 282 | |
| 283 | return ( |
| 284 | <ColoredCallButton |
| 285 | aria-label="answer call audio" |
| 286 | onClick={() => { |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 287 | acceptCall(false); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 288 | }} |
| 289 | Icon={PlaceAudioCallIcon} |
| 290 | paletteColor={(theme) => theme.palette.success} |
| 291 | {...props} |
| 292 | /> |
| 293 | ); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 294 | }; |
| 295 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 296 | export const CallingAnswerVideoButton = (props: IconButtonProps) => { |
| 297 | const { acceptCall } = useContext(CallContext); |
| 298 | |
| 299 | return ( |
| 300 | <ColoredCallButton |
| 301 | aria-label="answer call video" |
| 302 | onClick={() => { |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 303 | acceptCall(true); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 304 | }} |
| 305 | paletteColor={(theme) => theme.palette.success} |
| 306 | Icon={VideoCameraIcon} |
| 307 | {...props} |
| 308 | /> |
| 309 | ); |
| 310 | }; |
| 311 | |
| 312 | export const CallingRefuseButton = (props: IconButtonProps) => { |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 313 | const { endCall } = useContext(CallContext); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 314 | return ( |
| 315 | <ColoredCallButton |
| 316 | aria-label="refuse call" |
| 317 | onClick={() => { |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 318 | endCall(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 319 | }} |
| 320 | paletteColor={(theme) => theme.palette.error} |
| 321 | Icon={RoundCloseIcon} |
| 322 | {...props} |
| 323 | /> |
| 324 | ); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 325 | }; |