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 | |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame] | 19 | import { IconButtonProps } from '@mui/material'; |
| 20 | import { styled } from '@mui/material/styles'; |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 21 | import { ChangeEvent, useMemo } from 'react'; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 22 | |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 23 | import { useCallManagerContext } from '../contexts/CallManagerProvider'; |
idillon | 27dab02 | 2023-02-02 17:55:47 -0500 | [diff] [blame] | 24 | import { useUserMediaContext } from '../contexts/UserMediaProvider'; |
idillon | c45a43d | 2023-02-10 18:12:10 -0500 | [diff] [blame] | 25 | import { CallStatus, VideoStatus } from '../services/CallManager'; |
simon | 9076a9a | 2022-11-29 17:13:01 -0500 | [diff] [blame] | 26 | import { |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame] | 27 | ColoredRoundButton, |
simon | 9076a9a | 2022-11-29 17:13:01 -0500 | [diff] [blame] | 28 | ExpandableButton, |
| 29 | ExpandableButtonProps, |
| 30 | ExpandMenuRadioOption, |
simon | 9076a9a | 2022-11-29 17:13:01 -0500 | [diff] [blame] | 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 | FullScreenIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 38 | GroupAddIcon, |
| 39 | MicroIcon, |
| 40 | MicroOffIcon, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 41 | MoreVerticalIcon, |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 42 | PlaceAudioCallIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 43 | RecordingIcon, |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 44 | RoundCloseIcon, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 45 | ScreenShareArrowIcon, |
simon | 1e2bf34 | 2022-12-02 12:19:40 -0500 | [diff] [blame] | 46 | ScreenShareStopIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 47 | VideoCameraIcon, |
| 48 | VideoCameraOffIcon, |
| 49 | VolumeIcon, |
| 50 | } from './SvgIcon'; |
| 51 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 52 | const CallButton = styled((props: ExpandableButtonProps) => { |
| 53 | return <ExpandableButton {...props} />; |
| 54 | })({ |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 55 | color: 'white', |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 56 | '&:hover': { |
| 57 | backgroundColor: 'rgba(255, 255, 255, 0.15)', |
| 58 | }, |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 59 | }); |
| 60 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 61 | export const CallingChatButton = (props: ExpandableButtonProps) => { |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 62 | const { setIsChatShown } = useCallManagerContext(); |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 63 | return ( |
| 64 | <CallButton |
| 65 | aria-label="chat" |
| 66 | Icon={ChatBubbleIcon} |
| 67 | onClick={() => { |
| 68 | setIsChatShown((v) => !v); |
| 69 | }} |
| 70 | {...props} |
| 71 | /> |
| 72 | ); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 73 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 74 | |
| 75 | export const CallingEndButton = (props: ExpandableButtonProps) => { |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 76 | const { endCall } = useCallManagerContext(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 77 | return ( |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame] | 78 | <ColoredRoundButton |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 79 | paletteColor={(theme) => theme.palette.error} |
| 80 | onClick={() => { |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 81 | endCall(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 82 | }} |
| 83 | aria-label="call end" |
| 84 | Icon={CallEndIcon} |
| 85 | {...props} |
| 86 | /> |
| 87 | ); |
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 CallingExtensionButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 91 | return <CallButton aria-label="extensions" Icon={ExtensionIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 92 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 93 | |
| 94 | export const CallingFullScreenButton = (props: ExpandableButtonProps) => { |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 95 | const { setIsFullscreen } = useCallManagerContext(); |
simon | 2a5cf14 | 2022-11-25 15:47:35 -0500 | [diff] [blame] | 96 | return ( |
| 97 | <CallButton |
| 98 | aria-label="full screen" |
| 99 | Icon={FullScreenIcon} |
| 100 | onClick={() => { |
| 101 | setIsFullscreen((v) => !v); |
| 102 | }} |
| 103 | {...props} |
| 104 | /> |
| 105 | ); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 106 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 107 | |
| 108 | export const CallingGroupButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 109 | return <CallButton aria-label="group options" Icon={GroupAddIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 110 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 111 | |
| 112 | export const CallingMoreVerticalButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 113 | return <CallButton aria-label="more vertical" Icon={MoreVerticalIcon} {...props} />; |
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 CallingRecordButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 117 | return <CallButton aria-label="recording options" Icon={RecordingIcon} {...props} />; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | export const CallingScreenShareButton = (props: ExpandableButtonProps) => { |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 121 | return ( |
simon | 1e2bf34 | 2022-12-02 12:19:40 -0500 | [diff] [blame] | 122 | <CallButton aria-label="screen share" expandMenuOnClick IconButtonComp={ToggleScreenShareIconButton} {...props} /> |
| 123 | ); |
| 124 | }; |
| 125 | |
| 126 | const ToggleScreenShareIconButton = (props: IconButtonProps) => { |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 127 | const { videoStatus, updateVideoStatus } = useCallManagerContext(); |
simon | 1e2bf34 | 2022-12-02 12:19:40 -0500 | [diff] [blame] | 128 | |
| 129 | return ( |
| 130 | <ToggleIconButton |
| 131 | IconOff={ScreenShareArrowIcon} |
| 132 | IconOn={ScreenShareStopIcon} |
| 133 | selected={videoStatus === VideoStatus.ScreenShare} |
| 134 | toggle={() => { |
| 135 | updateVideoStatus((v) => (v !== VideoStatus.ScreenShare ? VideoStatus.ScreenShare : VideoStatus.Off)); |
| 136 | }} |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 137 | {...props} |
| 138 | /> |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 139 | ); |
| 140 | }; |
| 141 | |
simon | 9076a9a | 2022-11-29 17:13:01 -0500 | [diff] [blame] | 142 | const useMediaDeviceExpandMenuOptions = (kind: MediaDeviceKind): ExpandMenuRadioOption[] | undefined => { |
idillon | 27dab02 | 2023-02-02 17:55:47 -0500 | [diff] [blame] | 143 | const { currentMediaDeviceIds, mediaDevices } = useUserMediaContext(); |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 144 | |
simon | 9076a9a | 2022-11-29 17:13:01 -0500 | [diff] [blame] | 145 | const options = useMemo( |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 146 | () => |
| 147 | mediaDevices[kind].map((device) => ({ |
| 148 | key: device.deviceId, |
| 149 | description: device.label, |
| 150 | })), |
| 151 | [mediaDevices, kind] |
| 152 | ); |
simon | 9076a9a | 2022-11-29 17:13:01 -0500 | [diff] [blame] | 153 | |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 154 | const currentDevice = currentMediaDeviceIds[kind]; |
| 155 | |
| 156 | if (options.length === 0) { |
| 157 | return undefined; |
| 158 | } |
| 159 | return [ |
| 160 | { |
| 161 | options, |
| 162 | value: currentDevice.id ?? '', |
| 163 | onChange: (e: ChangeEvent<HTMLInputElement>) => { |
| 164 | currentDevice.setId(e.target.value); |
| 165 | }, |
| 166 | }, |
| 167 | ]; |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 168 | }; |
| 169 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 170 | export const CallingVolumeButton = (props: ExpandableButtonProps) => { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 171 | const options = useMediaDeviceExpandMenuOptions('audiooutput'); |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 172 | |
| 173 | return ( |
| 174 | <CallButton |
| 175 | aria-label="volume options" |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 176 | expandMenuOnClick |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 177 | Icon={VolumeIcon} |
simon | 571240f | 2022-11-29 23:59:27 -0500 | [diff] [blame] | 178 | expandMenuOptions={options} |
simon | 492e840 | 2022-11-29 16:48:37 -0500 | [diff] [blame] | 179 | {...props} |
| 180 | /> |
| 181 | ); |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 182 | }; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 183 | |
| 184 | export const CallingMicButton = (props: ExpandableButtonProps) => { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 185 | const options = useMediaDeviceExpandMenuOptions('audioinput'); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 186 | |
| 187 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 188 | <CallButton |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 189 | aria-label="microphone options" |
simon | 9076a9a | 2022-11-29 17:13:01 -0500 | [diff] [blame] | 190 | expandMenuOptions={options} |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 191 | IconButtonComp={ToggleAudioCameraIconButton} |
| 192 | {...props} |
| 193 | /> |
| 194 | ); |
| 195 | }; |
| 196 | |
| 197 | const ToggleAudioCameraIconButton = (props: IconButtonProps) => { |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 198 | const { isAudioOn, setIsAudioOn } = useCallManagerContext(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 199 | return ( |
| 200 | <ToggleIconButton |
| 201 | IconOn={MicroIcon} |
| 202 | IconOff={MicroOffIcon} |
| 203 | selected={isAudioOn} |
simon | 9076a9a | 2022-11-29 17:13:01 -0500 | [diff] [blame] | 204 | toggle={() => setIsAudioOn((v) => !v)} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 205 | {...props} |
| 206 | /> |
| 207 | ); |
| 208 | }; |
| 209 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 210 | export const CallingVideoCameraButton = (props: ExpandableButtonProps) => { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame] | 211 | const options = useMediaDeviceExpandMenuOptions('videoinput'); |
| 212 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 213 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 214 | <CallButton |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 215 | aria-label="camera options" |
simon | 9076a9a | 2022-11-29 17:13:01 -0500 | [diff] [blame] | 216 | expandMenuOptions={options} |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 217 | IconButtonComp={ToggleVideoCameraIconButton} |
| 218 | {...props} |
| 219 | /> |
| 220 | ); |
| 221 | }; |
| 222 | |
| 223 | const ToggleVideoCameraIconButton = (props: IconButtonProps) => { |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 224 | const { videoStatus, updateVideoStatus } = useCallManagerContext(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 225 | return ( |
| 226 | <ToggleIconButton |
| 227 | IconOn={VideoCameraIcon} |
| 228 | IconOff={VideoCameraOffIcon} |
simon | 1e2bf34 | 2022-12-02 12:19:40 -0500 | [diff] [blame] | 229 | selected={videoStatus === VideoStatus.Camera} |
| 230 | toggle={() => { |
| 231 | updateVideoStatus((v) => (v !== VideoStatus.Camera ? VideoStatus.Camera : VideoStatus.Off)); |
| 232 | }} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 233 | {...props} |
| 234 | /> |
| 235 | ); |
| 236 | }; |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 237 | |
| 238 | // Calling pending/receiving interface |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 239 | export const CallingCancelButton = (props: IconButtonProps) => { |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 240 | const { endCall } = useCallManagerContext(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 241 | |
| 242 | return ( |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame] | 243 | <ColoredRoundButton |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 244 | aria-label="cancel call" |
| 245 | onClick={() => { |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 246 | endCall(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 247 | }} |
| 248 | Icon={CallEndIcon} |
| 249 | paletteColor={(theme) => theme.palette.error} |
| 250 | {...props} |
| 251 | /> |
| 252 | ); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 253 | }; |
| 254 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 255 | export const CallingAnswerAudioButton = (props: IconButtonProps) => { |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 256 | const { acceptCall, callStatus } = useCallManagerContext(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 257 | |
| 258 | return ( |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame] | 259 | <ColoredRoundButton |
Charlie | 9c8779e | 2022-11-29 20:10:56 -0500 | [diff] [blame] | 260 | disabled={callStatus === CallStatus.Loading || callStatus === CallStatus.Connecting} |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 261 | aria-label="answer call audio" |
| 262 | onClick={() => { |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 263 | acceptCall(false); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 264 | }} |
| 265 | Icon={PlaceAudioCallIcon} |
| 266 | paletteColor={(theme) => theme.palette.success} |
| 267 | {...props} |
| 268 | /> |
| 269 | ); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 270 | }; |
| 271 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 272 | export const CallingAnswerVideoButton = (props: IconButtonProps) => { |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 273 | const { acceptCall, callStatus } = useCallManagerContext(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 274 | return ( |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame] | 275 | <ColoredRoundButton |
Charlie | 9c8779e | 2022-11-29 20:10:56 -0500 | [diff] [blame] | 276 | disabled={callStatus === CallStatus.Connecting || callStatus === CallStatus.Loading} |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 277 | aria-label="answer call video" |
| 278 | onClick={() => { |
MichelleSS | 5516420 | 2022-11-25 18:36:14 -0500 | [diff] [blame] | 279 | acceptCall(true); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 280 | }} |
| 281 | paletteColor={(theme) => theme.palette.success} |
| 282 | Icon={VideoCameraIcon} |
| 283 | {...props} |
| 284 | /> |
| 285 | ); |
| 286 | }; |
| 287 | |
| 288 | export const CallingRefuseButton = (props: IconButtonProps) => { |
idillon | 255682e | 2023-02-06 13:25:26 -0500 | [diff] [blame] | 289 | const { endCall } = useCallManagerContext(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 290 | return ( |
idillon | 18283ac | 2023-01-07 12:06:42 -0500 | [diff] [blame] | 291 | <ColoredRoundButton |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 292 | aria-label="refuse call" |
| 293 | onClick={() => { |
simon | accd802 | 2022-11-24 15:04:53 -0500 | [diff] [blame] | 294 | endCall(); |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 295 | }} |
| 296 | paletteColor={(theme) => theme.palette.error} |
| 297 | Icon={RoundCloseIcon} |
| 298 | {...props} |
| 299 | /> |
| 300 | ); |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 301 | }; |