Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -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 | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame^] | 18 | import { Box, Button, Card, Grid, Stack, Typography } from '@mui/material'; |
| 19 | import { useContext } from 'react'; |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 20 | |
| 21 | import { |
| 22 | CallingChatButton, |
| 23 | CallingEndButton, |
| 24 | CallingExtensionButton, |
| 25 | CallingFullscreenButton, |
| 26 | CallingGroupButton, |
| 27 | CallingMicButton, |
| 28 | CallingRecordButton, |
| 29 | CallingScreenShareButton, |
| 30 | CallingVideoCameraButton, |
| 31 | CallingVolumeButton, |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 32 | } from '../components/CallButtons'; |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame^] | 33 | import WebRTCProvider, { WebRTCContext } from '../contexts/WebRTCProvider'; |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 34 | import { useUrlParams } from '../utils/hooks'; |
| 35 | import { CallRouteParams } from './JamiMessenger'; |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 36 | |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 37 | export default () => { |
| 38 | const { |
| 39 | queryParams: { video }, |
| 40 | } = useUrlParams<CallRouteParams>(); |
| 41 | |
| 42 | return ( |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame^] | 43 | <WebRTCProvider isVideoOn={video === 'true'}> |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 44 | <CallInterface /> |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame^] | 45 | </WebRTCProvider> |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 46 | ); |
| 47 | }; |
| 48 | |
| 49 | const CallInterface = () => { |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame^] | 50 | const { localVideoRef, remoteVideoRef, isVideoOn } = useContext(WebRTCContext); |
| 51 | |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 52 | return ( |
| 53 | <> |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame^] | 54 | <video |
| 55 | ref={remoteVideoRef} |
| 56 | autoPlay |
| 57 | style={{ backgroundColor: 'black', width: '100%', height: '100%', position: 'absolute' }} |
| 58 | /> |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 59 | <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%"> |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame^] | 72 | {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 Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 88 | </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 | ); |
simon | 1170c32 | 2022-10-31 14:51:31 -0400 | [diff] [blame] | 102 | }; |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 103 | |
| 104 | const 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 | |
| 117 | const CallInterfacePrimaryButtons = () => { |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame^] | 118 | const { sendWebRTCOffer } = useContext(WebRTCContext); |
| 119 | |
Gabriel Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 120 | return ( |
| 121 | <Card sx={{ backgroundColor: 'black', textAlign: 'center' }}> |
simon | ce2c0c4 | 2022-11-02 17:39:31 -0400 | [diff] [blame^] | 122 | <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 Rochon | e3ec0d2 | 2022-10-08 14:27:03 -0400 | [diff] [blame] | 131 | <CallingMicButton /> |
| 132 | <CallingEndButton /> |
| 133 | <CallingVideoCameraButton /> |
| 134 | </Card> |
| 135 | ); |
| 136 | }; |
| 137 | |
| 138 | const 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 | }; |