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