blob: 573418a847685f11ffb17912711ada9365054a59 [file] [log] [blame]
simon2d3b6532022-11-08 21:01:57 -05001/*
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 */
18
19import { Box, CircularProgress, Grid, Stack, Typography } from '@mui/material';
simon4e7445c2022-11-16 21:18:46 -050020import { useTranslation } from 'react-i18next';
simon2d3b6532022-11-08 21:01:57 -050021
22import {
23 CallingAnswerAudioButton,
24 CallingAnswerVideoButton,
25 CallingEndButton,
26 CallingRefuseButton,
27} from '../components/CallButtons';
28
29export type CallPendingProps = {
30 pending: PendingStatus;
31 caller?: CallerStatus;
32 medium?: CommunicationMedium;
33};
34
35type PendingStatus = 'caller' | 'receiver';
36type CallerStatus = 'calling' | 'connecting';
37type CommunicationMedium = 'audio' | 'video';
38
39const RECEIVER_BUTTONS = [
40 {
41 ButtonComponent: CallingRefuseButton,
42 translationKey: 'refuse_call',
43 },
44 {
45 ButtonComponent: CallingAnswerAudioButton,
46 translationKey: 'accept_call_audio',
47 },
48 {
49 ButtonComponent: CallingAnswerVideoButton,
50 translationKey: 'accept_call_video',
51 },
52];
53
54export const CallPending = (props: CallPendingProps) => {
55 return (
56 <Stack
57 direction="column"
58 justifyContent="center"
59 alignItems="center"
60 height="100%"
61 spacing={4}
62 sx={{
63 backgroundColor: 'black',
64 }}
65 >
66 <Box
67 sx={{
68 position: 'relative',
69 display: 'flex',
70 alignItems: 'center',
71 justifyContent: 'center',
72 width: '100%',
73 height: '30%',
74 }}
75 >
76 <Box
77 sx={{
78 aspectRatio: '1',
79 height: '100%',
80 position: 'absolute',
81 }}
82 >
83 <CircularProgress
84 disableShrink
85 thickness={1}
86 size="100%"
87 sx={{
88 position: 'absolute',
89 color: 'white',
90 zIndex: 1,
91 }}
92 />
93 <img
94 // TODO: Insert incoming caller icon here
95 style={{
96 position: 'absolute',
97 objectFit: 'cover',
98 width: '100%',
99 height: '100%',
100 maxWidth: '100%',
101 borderRadius: '50%',
102 aspectRatio: '1',
103 }}
104 />
105 </Box>
106 </Box>
107 {props.pending === 'caller' ? (
108 <CallPendingCallerInterface {...props} />
109 ) : (
110 <CallPendingReceiverInterface {...props} />
111 )}
112 </Stack>
113 );
114};
115
116export const CallPendingCallerInterface = ({ caller }: CallPendingProps) => {
simon4e7445c2022-11-16 21:18:46 -0500117 const { t } = useTranslation();
simon2d3b6532022-11-08 21:01:57 -0500118 // TODO: Remove the dummy name
119 const defaultName = 'Alex Thérieur';
120 return (
simon4e7445c2022-11-16 21:18:46 -0500121 <>
simon2d3b6532022-11-08 21:01:57 -0500122 <Typography variant="h1" color="white">
123 {defaultName}
124 </Typography>
125 <Typography variant="h3" color="white">
simon4e7445c2022-11-16 21:18:46 -0500126 {caller === 'calling' ? t('calling') : t('connecting')}
simon2d3b6532022-11-08 21:01:57 -0500127 </Typography>
simon4e7445c2022-11-16 21:18:46 -0500128
129 <Stack alignItems="center" spacing={1} width="100%">
130 <CallingEndButton size="large" />
131 <Typography variant="body2" color="white">
132 {t('end_call')}
133 </Typography>
134 </Stack>
135 </>
simon2d3b6532022-11-08 21:01:57 -0500136 );
137};
138
139export const CallPendingReceiverInterface = ({ medium }: CallPendingProps) => {
simon4e7445c2022-11-16 21:18:46 -0500140 const { t } = useTranslation();
simon2d3b6532022-11-08 21:01:57 -0500141 // TODO: Remove the dummy name
142 const defaultName = 'Alain Thérieur';
143 return (
simon4e7445c2022-11-16 21:18:46 -0500144 <>
simon2d3b6532022-11-08 21:01:57 -0500145 <Typography variant="h1" color="white">
simon4e7445c2022-11-16 21:18:46 -0500146 {t('incoming_call', {
147 context: medium,
148 member0: defaultName,
149 })}
simon2d3b6532022-11-08 21:01:57 -0500150 </Typography>
simon4e7445c2022-11-16 21:18:46 -0500151 <Box width="50%">
152 <ReceiverButtons />
153 </Box>
154 </>
simon2d3b6532022-11-08 21:01:57 -0500155 );
156};
157
158const ReceiverButtons = () => {
simon4e7445c2022-11-16 21:18:46 -0500159 const { t } = useTranslation();
simon2d3b6532022-11-08 21:01:57 -0500160 return (
simon4e7445c2022-11-16 21:18:46 -0500161 <Grid container spacing={2}>
simon2d3b6532022-11-08 21:01:57 -0500162 {RECEIVER_BUTTONS.map(({ ButtonComponent, translationKey }, i) => (
163 <Grid item xs={4} key={i}>
simon4e7445c2022-11-16 21:18:46 -0500164 <Stack alignItems="center" spacing={1}>
simon2d3b6532022-11-08 21:01:57 -0500165 <ButtonComponent color="inherit" size="large" />
simon4e7445c2022-11-16 21:18:46 -0500166 <Typography variant="body2" color="white" sx={{ opacity: 0.75 }}>
167 {t(translationKey)}
simon2d3b6532022-11-08 21:01:57 -0500168 </Typography>
169 </Stack>
170 </Grid>
171 ))}
172 </Grid>
173 );
174};