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