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 | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 20 | import React, { useContext } 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 | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 132 | export const CallingVolumeButton = (props: ExpandableButtonProps) => { |
| 133 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 134 | <CallButton |
simon | 33c0618 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 135 | aria-label="volume options" |
| 136 | Icon={VolumeIcon} |
| 137 | expandMenuOptions={[ |
| 138 | { |
| 139 | options: [ |
| 140 | { |
| 141 | key: '0', |
| 142 | description: <Trans i18nKey="dummy_option_string" />, |
| 143 | }, |
| 144 | ], |
| 145 | }, |
| 146 | ]} |
| 147 | {...props} |
| 148 | /> |
| 149 | ); |
| 150 | }; |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 151 | |
| 152 | export const CallingMicButton = (props: ExpandableButtonProps) => { |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 153 | const { isAudioOn, setAudioStatus } = useContext(WebRTCContext); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 154 | |
| 155 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 156 | <CallButton |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 157 | aria-label="microphone options" |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 158 | IconButtonComp={(props) => ( |
| 159 | <ToggleIconButton |
| 160 | IconOn={MicroIcon} |
| 161 | IconOff={MicroOffIcon} |
| 162 | selected={isAudioOn} |
| 163 | toggle={() => setAudioStatus(!isAudioOn)} |
| 164 | {...props} |
| 165 | /> |
| 166 | )} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 167 | {...props} |
| 168 | /> |
| 169 | ); |
| 170 | }; |
| 171 | |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 172 | export const CallingVideoCameraButton = (props: ExpandableButtonProps) => { |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame] | 173 | const { isVideoOn, setVideoStatus } = useContext(WebRTCContext); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 174 | return ( |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 175 | <CallButton |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 176 | aria-label="camera options" |
Gabriel Rochon | 8321a0d | 2022-11-06 23:18:36 -0500 | [diff] [blame] | 177 | IconButtonComp={(props) => ( |
| 178 | <ToggleIconButton |
| 179 | IconOn={VideoCameraIcon} |
| 180 | IconOff={VideoCameraOffIcon} |
| 181 | selected={isVideoOn} |
| 182 | toggle={() => setVideoStatus(!isVideoOn)} |
| 183 | {...props} |
| 184 | /> |
| 185 | )} |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 186 | {...props} |
| 187 | /> |
| 188 | ); |
| 189 | }; |
simon | 2d3b653 | 2022-11-08 21:01:57 -0500 | [diff] [blame^] | 190 | |
| 191 | // Calling pending/receiving interface |
| 192 | export const CallingAnswerAudioButton = (props: ExpandableButtonProps) => { |
| 193 | return <ColoredCallButton aria-label="answer audio" buttonColor="green" Icon={PlaceAudioCallIcon} {...props} />; |
| 194 | }; |
| 195 | |
| 196 | export const CallingAnswerVideoButton = (props: ExpandableButtonProps) => { |
| 197 | return <ColoredCallButton aria-label="answer video" buttonColor="green" Icon={VideoCameraIcon} {...props} />; |
| 198 | }; |
| 199 | |
| 200 | export const CallingRefuseButton = (props: ExpandableButtonProps) => { |
| 201 | return <ColoredCallButton aria-label="reject" buttonColor="red" Icon={RoundCloseIcon} {...props} />; |
| 202 | }; |