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) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 87 | return <CallButton aria-label="chat" Icon={ChatBubbleIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 88 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 89 | |
| 90 | export const CallingEndButton = (props: ExpandableButtonProps) => { |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 91 | const navigate = useNavigate(); |
| 92 | return ( |
| 93 | <ColoredCallButton |
| 94 | paletteColor={(theme) => theme.palette.error} |
| 95 | onClick={() => { |
| 96 | // TODO: Send event to end call |
| 97 | navigate('/'); |
| 98 | }} |
| 99 | aria-label="call end" |
| 100 | Icon={CallEndIcon} |
| 101 | {...props} |
| 102 | /> |
| 103 | ); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 104 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 105 | |
| 106 | export const CallingExtensionButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 107 | return <CallButton aria-label="extensions" Icon={ExtensionIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 108 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 109 | |
| 110 | export const CallingFullScreenButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 111 | return <CallButton aria-label="full screen" Icon={FullScreenIcon} {...props} />; |
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 CallingGroupButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 115 | return <CallButton aria-label="group options" Icon={GroupAddIcon} {...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 CallingMoreVerticalButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 119 | return <CallButton aria-label="more vertical" Icon={MoreVerticalIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 120 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 121 | |
| 122 | export const CallingRecordButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 123 | return <CallButton aria-label="recording options" Icon={RecordingIcon} {...props} />; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | export const CallingScreenShareButton = (props: ExpandableButtonProps) => { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 127 | const { t } = useTranslation(); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 128 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 129 | <CallButton |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 130 | aria-label="screen share" |
| 131 | Icon={ScreenShareArrowIcon} |
| 132 | expandMenuOptions={[ |
| 133 | { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 134 | description: t('share_screen'), |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 135 | icon: <ScreenShareRegularIcon />, |
| 136 | }, |
| 137 | { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 138 | description: t('share_window'), |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 139 | icon: <WindowIcon />, |
| 140 | }, |
| 141 | { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 142 | description: t('share_screen_area'), |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 143 | icon: <ScreenShareScreenAreaIcon />, |
| 144 | }, |
| 145 | { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 146 | description: t('share_file'), |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 147 | icon: <FileIcon />, |
| 148 | }, |
| 149 | ]} |
| 150 | {...props} |
| 151 | /> |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 152 | ); |
| 153 | }; |
| 154 | |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 155 | const useMediaDeviceExpandMenuOptions = (kind: MediaDeviceKind) => { |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 156 | const { mediaDevices } = useContext(CallContext); |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 157 | |
| 158 | return useMemo( |
| 159 | () => |
| 160 | mediaDevices[kind].map((device) => ({ |
| 161 | key: device.deviceId, |
| 162 | description: device.label, |
| 163 | })), |
| 164 | [mediaDevices, kind] |
| 165 | ); |
| 166 | }; |
| 167 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 168 | export const CallingVolumeButton = (props: ExpandableButtonProps) => { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 169 | const options = useMediaDeviceExpandMenuOptions('audiooutput'); |
| 170 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 171 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 172 | <CallButton |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 173 | aria-label="volume options" |
| 174 | Icon={VolumeIcon} |
| 175 | expandMenuOptions={[ |
| 176 | { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 177 | options, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 178 | }, |
| 179 | ]} |
| 180 | {...props} |
| 181 | /> |
| 182 | ); |
| 183 | }; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 184 | |
| 185 | export const CallingMicButton = (props: ExpandableButtonProps) => { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 186 | const options = useMediaDeviceExpandMenuOptions('audioinput'); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 187 | |
| 188 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 189 | <CallButton |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 190 | aria-label="microphone options" |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 191 | expandMenuOptions={[ |
| 192 | { |
| 193 | options, |
| 194 | }, |
| 195 | ]} |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 196 | IconButtonComp={ToggleAudioCameraIconButton} |
| 197 | {...props} |
| 198 | /> |
| 199 | ); |
| 200 | }; |
| 201 | |
| 202 | const ToggleAudioCameraIconButton = (props: IconButtonProps) => { |
| 203 | const { isAudioOn, setAudioStatus } = useContext(CallContext); |
| 204 | return ( |
| 205 | <ToggleIconButton |
| 206 | IconOn={MicroIcon} |
| 207 | IconOff={MicroOffIcon} |
| 208 | selected={isAudioOn} |
| 209 | toggle={() => setAudioStatus(!isAudioOn)} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 210 | {...props} |
| 211 | /> |
| 212 | ); |
| 213 | }; |
| 214 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 215 | export const CallingVideoCameraButton = (props: ExpandableButtonProps) => { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 216 | const options = useMediaDeviceExpandMenuOptions('videoinput'); |
| 217 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 218 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 219 | <CallButton |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 220 | aria-label="camera options" |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 221 | expandMenuOptions={[ |
| 222 | { |
| 223 | options, |
| 224 | }, |
| 225 | ]} |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 226 | IconButtonComp={ToggleVideoCameraIconButton} |
| 227 | {...props} |
| 228 | /> |
| 229 | ); |
| 230 | }; |
| 231 | |
| 232 | const ToggleVideoCameraIconButton = (props: IconButtonProps) => { |
| 233 | const { isVideoOn, setVideoStatus } = useContext(CallContext); |
| 234 | return ( |
| 235 | <ToggleIconButton |
| 236 | IconOn={VideoCameraIcon} |
| 237 | IconOff={VideoCameraOffIcon} |
| 238 | selected={isVideoOn} |
| 239 | toggle={() => setVideoStatus(!isVideoOn)} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 240 | {...props} |
| 241 | /> |
| 242 | ); |
| 243 | }; |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 244 | |
| 245 | // Calling pending/receiving interface |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 246 | export const CallingCancelButton = (props: IconButtonProps) => { |
| 247 | const navigate = useNavigate(); |
| 248 | |
| 249 | return ( |
| 250 | <ColoredCallButton |
| 251 | aria-label="cancel call" |
| 252 | onClick={() => { |
| 253 | navigate(-1); |
| 254 | }} |
| 255 | Icon={CallEndIcon} |
| 256 | paletteColor={(theme) => theme.palette.error} |
| 257 | {...props} |
| 258 | /> |
| 259 | ); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 260 | }; |
| 261 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 262 | export const CallingAnswerAudioButton = (props: IconButtonProps) => { |
| 263 | const { acceptCall } = useContext(CallContext); |
| 264 | |
| 265 | return ( |
| 266 | <ColoredCallButton |
| 267 | aria-label="answer call audio" |
| 268 | onClick={() => { |
| 269 | acceptCall(); |
| 270 | }} |
| 271 | Icon={PlaceAudioCallIcon} |
| 272 | paletteColor={(theme) => theme.palette.success} |
| 273 | {...props} |
| 274 | /> |
| 275 | ); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 276 | }; |
| 277 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 278 | export const CallingAnswerVideoButton = (props: IconButtonProps) => { |
| 279 | const { acceptCall } = useContext(CallContext); |
| 280 | |
| 281 | return ( |
| 282 | <ColoredCallButton |
| 283 | aria-label="answer call video" |
| 284 | onClick={() => { |
| 285 | acceptCall(); |
| 286 | }} |
| 287 | paletteColor={(theme) => theme.palette.success} |
| 288 | Icon={VideoCameraIcon} |
| 289 | {...props} |
| 290 | /> |
| 291 | ); |
| 292 | }; |
| 293 | |
| 294 | export const CallingRefuseButton = (props: IconButtonProps) => { |
| 295 | const navigate = useNavigate(); |
| 296 | return ( |
| 297 | <ColoredCallButton |
| 298 | aria-label="refuse call" |
| 299 | onClick={() => { |
| 300 | navigate(-1); |
| 301 | }} |
| 302 | paletteColor={(theme) => theme.palette.error} |
| 303 | Icon={RoundCloseIcon} |
| 304 | {...props} |
| 305 | /> |
| 306 | ); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 307 | }; |