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