blob: e729474bfc5c70f360b6b5b61609887382dd353b [file] [log] [blame]
Gabriel Rochone3ec0d22022-10-08 14:27:03 -04001/*
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 */
simonce2c0c42022-11-02 17:39:31 -040018import { Box, Button, Card, Grid, Stack, Typography } from '@mui/material';
19import { useContext } from 'react';
Gabriel Rochone3ec0d22022-10-08 14:27:03 -040020
21import {
22 CallingChatButton,
23 CallingEndButton,
24 CallingExtensionButton,
25 CallingFullscreenButton,
26 CallingGroupButton,
27 CallingMicButton,
28 CallingRecordButton,
29 CallingScreenShareButton,
30 CallingVideoCameraButton,
31 CallingVolumeButton,
simon1170c322022-10-31 14:51:31 -040032} from '../components/CallButtons';
simonce2c0c42022-11-02 17:39:31 -040033import WebRTCProvider, { WebRTCContext } from '../contexts/WebRTCProvider';
simon1170c322022-10-31 14:51:31 -040034import { useUrlParams } from '../utils/hooks';
35import { CallRouteParams } from './JamiMessenger';
Gabriel Rochone3ec0d22022-10-08 14:27:03 -040036
simon1170c322022-10-31 14:51:31 -040037export default () => {
38 const {
39 queryParams: { video },
40 } = useUrlParams<CallRouteParams>();
41
42 return (
simonce2c0c42022-11-02 17:39:31 -040043 <WebRTCProvider isVideoOn={video === 'true'}>
simon1170c322022-10-31 14:51:31 -040044 <CallInterface />
simonce2c0c42022-11-02 17:39:31 -040045 </WebRTCProvider>
simon1170c322022-10-31 14:51:31 -040046 );
47};
48
49const CallInterface = () => {
simonce2c0c42022-11-02 17:39:31 -040050 const { localVideoRef, remoteVideoRef, isVideoOn } = useContext(WebRTCContext);
51
Gabriel Rochone3ec0d22022-10-08 14:27:03 -040052 return (
53 <>
simonce2c0c42022-11-02 17:39:31 -040054 <video
55 ref={remoteVideoRef}
56 autoPlay
57 style={{ backgroundColor: 'black', width: '100%', height: '100%', position: 'absolute' }}
58 />
Gabriel Rochone3ec0d22022-10-08 14:27:03 -040059 <Stack
60 position="absolute"
61 direction="column"
62 spacing={1}
63 margin={2}
64 sx={{ left: 0, right: 0, top: 0, bottom: 0 }}
65 >
66 {/* Top panel with guest information */}
67 <Box>
68 <CallInterfaceInformation />
69 </Box>
70 {/* Guest video, with empty space to be moved around and stickied to walls */}
71 <Box height="100%">
simonce2c0c42022-11-02 17:39:31 -040072 {isVideoOn && (
73 <video
74 ref={localVideoRef}
75 autoPlay
76 style={{
77 position: 'absolute',
78 right: 0,
79 zIndex: 2,
80 borderRadius: '12px',
81 minWidth: '25%',
82 minHeight: '25%',
83 maxWidth: '50%',
84 maxHeight: '50%',
85 }}
86 />
87 )}
Gabriel Rochone3ec0d22022-10-08 14:27:03 -040088 </Box>
89 {/* Bottom panel with calling buttons */}
90 <Grid container justifyContent="space-between">
91 <Grid item xs />
92 <Grid item>
93 <CallInterfacePrimaryButtons />
94 </Grid>
95 <Grid item xs sx={{ display: 'flex', justifyContent: 'flex-end' }}>
96 <CallInterfaceSecondaryButtons />
97 </Grid>
98 </Grid>
99 </Stack>
100 </>
101 );
simon1170c322022-10-31 14:51:31 -0400102};
Gabriel Rochone3ec0d22022-10-08 14:27:03 -0400103
104const CallInterfaceInformation = () => {
105 return (
106 <Stack direction="row" justifyContent="space-between" alignItems="center">
107 <Typography color="white" component="p">
108 Alain Thérieur
109 </Typography>
110 <Typography color="white" component="p">
111 01:23
112 </Typography>
113 </Stack>
114 );
115};
116
117const CallInterfacePrimaryButtons = () => {
simonce2c0c42022-11-02 17:39:31 -0400118 const { sendWebRTCOffer } = useContext(WebRTCContext);
119
Gabriel Rochone3ec0d22022-10-08 14:27:03 -0400120 return (
121 <Card sx={{ backgroundColor: 'black', textAlign: 'center' }}>
simonce2c0c42022-11-02 17:39:31 -0400122 <Button
123 variant="contained"
124 onClick={() => {
125 sendWebRTCOffer();
126 }}
127 >
128 {/* TODO: Remove this button and make calling automatic (https://git.jami.net/savoirfairelinux/jami-web/-/issues/91)*/}
129 Call
130 </Button>
Gabriel Rochone3ec0d22022-10-08 14:27:03 -0400131 <CallingMicButton />
132 <CallingEndButton />
133 <CallingVideoCameraButton />
134 </Card>
135 );
136};
137
138const CallInterfaceSecondaryButtons = () => {
139 return (
140 <Card style={{ backgroundColor: 'black' }}>
141 <CallingVolumeButton />
142 <CallingGroupButton />
143 <CallingChatButton />
144 <CallingScreenShareButton />
145 <CallingRecordButton />
146 <CallingExtensionButton />
147 <CallingFullscreenButton />
148 </Card>
149 );
150};