simon | 26e79f7 | 2022-10-05 22:16:08 -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 | */ |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 18 | import { Divider, Stack, Typography } from '@mui/material'; |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 19 | import { useContext } from 'react'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 20 | |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 21 | import { CallManagerContext } from '../contexts/CallManagerProvider'; |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 22 | import { useCallContext } from '../contexts/CallProvider'; |
simon | 09fe482 | 2022-11-30 23:36:25 -0500 | [diff] [blame] | 23 | import { useConversationContext } from '../contexts/ConversationProvider'; |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 24 | import { useWebRtcContext } from '../contexts/WebRtcProvider'; |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 25 | import CallInterface from '../pages/CallInterface'; |
idillon | 6847e25 | 2022-11-04 11:50:08 -0400 | [diff] [blame] | 26 | import ChatInterface from '../pages/ChatInterface'; |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 27 | import { AddParticipantButton, ShowOptionsMenuButton, StartAudioCallButton, StartVideoCallButton } from './Button'; |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 28 | |
simon | f929a36 | 2022-11-18 16:53:45 -0500 | [diff] [blame] | 29 | const ConversationView = () => { |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 30 | const { conversationId } = useConversationContext(); |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 31 | const webRtcContext = useWebRtcContext(true); |
| 32 | const callContext = useCallContext(true); |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 33 | const { callData } = useContext(CallManagerContext); |
| 34 | |
simon | 5c67796 | 2022-12-02 16:51:54 -0500 | [diff] [blame] | 35 | if (webRtcContext && callContext && callData?.conversationId === conversationId) { |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 36 | return <CallInterface />; |
| 37 | } |
| 38 | |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 39 | return ( |
simon | 9f814a3 | 2022-11-22 21:40:53 -0500 | [diff] [blame] | 40 | <Stack flexGrow={1} height="100%"> |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 41 | <ConversationHeader /> |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 42 | <Divider |
| 43 | sx={{ |
| 44 | borderTop: '1px solid #E5E5E5', |
| 45 | }} |
| 46 | /> |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 47 | <ChatInterface /> |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 48 | </Stack> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 49 | ); |
| 50 | }; |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 51 | |
simon | f9d78f2 | 2022-11-25 15:47:15 -0500 | [diff] [blame] | 52 | const ConversationHeader = () => { |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 53 | const { conversationId, conversationDisplayName } = useConversationContext(); |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 54 | const { startCall } = useContext(CallManagerContext); |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 55 | |
| 56 | return ( |
idillon | 6847e25 | 2022-11-04 11:50:08 -0400 | [diff] [blame] | 57 | <Stack direction="row" padding="16px" overflow="hidden"> |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 58 | <Stack flex={1} justifyContent="center" whiteSpace="nowrap" overflow="hidden"> |
| 59 | <Typography variant="h3" textOverflow="ellipsis"> |
idillon | 07d31cc | 2022-12-06 22:40:14 -0500 | [diff] [blame] | 60 | {conversationDisplayName} |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 61 | </Typography> |
| 62 | </Stack> |
| 63 | <Stack direction="row" spacing="20px"> |
simon | e35acc2 | 2022-12-02 16:51:12 -0500 | [diff] [blame] | 64 | <StartAudioCallButton onClick={() => startCall({ conversationId, role: 'caller' })} /> |
| 65 | <StartVideoCallButton onClick={() => startCall({ conversationId, role: 'caller', withVideoOn: true })} /> |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 66 | <AddParticipantButton /> |
| 67 | <ShowOptionsMenuButton /> |
| 68 | </Stack> |
| 69 | </Stack> |
| 70 | ); |
| 71 | }; |
| 72 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 73 | export default ConversationView; |