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