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 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 19 | import { styled } from '@mui/material/styles'; |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame^] | 20 | import React, { useContext, useMemo } from 'react'; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 21 | import { Trans } from 'react-i18next'; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 22 | |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 23 | import { WebRTCContext } from '../contexts/WebRTCProvider'; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 24 | import { ExpandableButton, ExpandableButtonProps, ToggleIconButton } from './Button'; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 25 | import { |
| 26 | CallEndIcon, |
| 27 | ChatBubbleIcon, |
| 28 | ExtensionIcon, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 29 | FileIcon, |
| 30 | FullScreenIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 31 | GroupAddIcon, |
| 32 | MicroIcon, |
| 33 | MicroOffIcon, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 34 | MoreVerticalIcon, |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 35 | PlaceAudioCallIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 36 | RecordingIcon, |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 37 | RoundCloseIcon, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 38 | ScreenShareArrowIcon, |
| 39 | ScreenShareRegularIcon, |
| 40 | ScreenShareScreenAreaIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 41 | VideoCameraIcon, |
| 42 | VideoCameraOffIcon, |
| 43 | VolumeIcon, |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 44 | WindowIcon, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 45 | } from './SvgIcon'; |
| 46 | |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 47 | type ColoredCallButtonColor = 'red' | 'green'; |
| 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 | ({ |
| 60 | ...props |
| 61 | }: ExpandableButtonProps & { |
| 62 | buttonColor: ColoredCallButtonColor; |
| 63 | }) => { |
| 64 | return <ExpandableButton {...props} />; |
| 65 | } |
| 66 | )(({ buttonColor }) => { |
| 67 | return { |
| 68 | color: 'white', |
| 69 | backgroundColor: buttonColor === 'green' ? '#183722' : '#5E070D', |
| 70 | '&:hover': { |
| 71 | backgroundColor: buttonColor === 'green' ? '#0B8271' : '#CC0022', |
| 72 | }, |
| 73 | }; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 74 | }); |
| 75 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 76 | export const CallingChatButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 77 | return <CallButton aria-label="chat" Icon={ChatBubbleIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 78 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 79 | |
| 80 | export const CallingEndButton = (props: ExpandableButtonProps) => { |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 81 | return <ColoredCallButton buttonColor="red" aria-label="call end" Icon={CallEndIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 82 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 83 | |
| 84 | export const CallingExtensionButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 85 | return <CallButton aria-label="extensions" Icon={ExtensionIcon} {...props} />; |
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 CallingFullScreenButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 89 | return <CallButton aria-label="full screen" Icon={FullScreenIcon} {...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 CallingGroupButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 93 | return <CallButton aria-label="group options" Icon={GroupAddIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 94 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 95 | |
| 96 | export const CallingMoreVerticalButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 97 | return <CallButton aria-label="more vertical" Icon={MoreVerticalIcon} {...props} />; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 98 | }; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 99 | |
| 100 | export const CallingRecordButton = (props: ExpandableButtonProps) => { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 101 | return <CallButton aria-label="recording options" Icon={RecordingIcon} {...props} />; |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | export const CallingScreenShareButton = (props: ExpandableButtonProps) => { |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 105 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 106 | <CallButton |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 107 | aria-label="screen share" |
| 108 | Icon={ScreenShareArrowIcon} |
| 109 | expandMenuOptions={[ |
| 110 | { |
| 111 | description: <Trans i18nKey="share_screen" />, |
| 112 | icon: <ScreenShareRegularIcon />, |
| 113 | }, |
| 114 | { |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 115 | description: <Trans i18nKey="share_window" />, |
| 116 | icon: <WindowIcon />, |
| 117 | }, |
| 118 | { |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 119 | description: <Trans i18nKey="share_screen_area" />, |
| 120 | icon: <ScreenShareScreenAreaIcon />, |
| 121 | }, |
| 122 | { |
| 123 | description: <Trans i18nKey="share_file" />, |
| 124 | icon: <FileIcon />, |
| 125 | }, |
| 126 | ]} |
| 127 | {...props} |
| 128 | /> |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 129 | ); |
| 130 | }; |
| 131 | |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame^] | 132 | const useMediaDeviceExpandMenuOptions = (kind: MediaDeviceKind) => { |
| 133 | const { mediaDevices } = useContext(WebRTCContext); |
| 134 | |
| 135 | return useMemo( |
| 136 | () => |
| 137 | mediaDevices[kind].map((device) => ({ |
| 138 | key: device.deviceId, |
| 139 | description: device.label, |
| 140 | })), |
| 141 | [mediaDevices, kind] |
| 142 | ); |
| 143 | }; |
| 144 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 145 | export const CallingVolumeButton = (props: ExpandableButtonProps) => { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame^] | 146 | const options = useMediaDeviceExpandMenuOptions('audiooutput'); |
| 147 | |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 148 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 149 | <CallButton |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 150 | aria-label="volume options" |
| 151 | Icon={VolumeIcon} |
| 152 | expandMenuOptions={[ |
| 153 | { |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame^] | 154 | options, |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 155 | }, |
| 156 | ]} |
| 157 | {...props} |
| 158 | /> |
| 159 | ); |
| 160 | }; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 161 | |
| 162 | export const CallingMicButton = (props: ExpandableButtonProps) => { |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 163 | const { isAudioOn, setAudioStatus } = useContext(WebRTCContext); |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame^] | 164 | const options = useMediaDeviceExpandMenuOptions('audioinput'); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 165 | |
| 166 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 167 | <CallButton |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 168 | aria-label="microphone options" |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame^] | 169 | expandMenuOptions={[ |
| 170 | { |
| 171 | options, |
| 172 | }, |
| 173 | ]} |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 174 | IconButtonComp={(props) => ( |
| 175 | <ToggleIconButton |
| 176 | IconOn={MicroIcon} |
| 177 | IconOff={MicroOffIcon} |
| 178 | selected={isAudioOn} |
| 179 | toggle={() => setAudioStatus(!isAudioOn)} |
| 180 | {...props} |
| 181 | /> |
| 182 | )} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 183 | {...props} |
| 184 | /> |
| 185 | ); |
| 186 | }; |
| 187 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 188 | export const CallingVideoCameraButton = (props: ExpandableButtonProps) => { |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 189 | const { isVideoOn, setVideoStatus } = useContext(WebRTCContext); |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame^] | 190 | const options = useMediaDeviceExpandMenuOptions('videoinput'); |
| 191 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 192 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 193 | <CallButton |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 194 | aria-label="camera options" |
simon | 9a8fe20 | 2022-11-15 18:25:49 -0500 | [diff] [blame^] | 195 | expandMenuOptions={[ |
| 196 | { |
| 197 | options, |
| 198 | }, |
| 199 | ]} |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 200 | IconButtonComp={(props) => ( |
| 201 | <ToggleIconButton |
| 202 | IconOn={VideoCameraIcon} |
| 203 | IconOff={VideoCameraOffIcon} |
| 204 | selected={isVideoOn} |
| 205 | toggle={() => setVideoStatus(!isVideoOn)} |
| 206 | {...props} |
| 207 | /> |
| 208 | )} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 209 | {...props} |
| 210 | /> |
| 211 | ); |
| 212 | }; |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 213 | |
| 214 | // Calling pending/receiving interface |
| 215 | export const CallingAnswerAudioButton = (props: ExpandableButtonProps) => { |
| 216 | return <ColoredCallButton aria-label="answer audio" buttonColor="green" Icon={PlaceAudioCallIcon} {...props} />; |
| 217 | }; |
| 218 | |
| 219 | export const CallingAnswerVideoButton = (props: ExpandableButtonProps) => { |
| 220 | return <ColoredCallButton aria-label="answer video" buttonColor="green" Icon={VideoCameraIcon} {...props} />; |
| 221 | }; |
| 222 | |
| 223 | export const CallingRefuseButton = (props: ExpandableButtonProps) => { |
| 224 | return <ColoredCallButton aria-label="reject" buttonColor="red" Icon={RoundCloseIcon} {...props} />; |
| 225 | }; |