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