From 5f17e4153bc0e13cd06cbc52d188c2551092a4e2 Mon Sep 17 00:00:00 2001 From: CrazyStevenz Date: Wed, 22 Mar 2023 00:41:40 +0200 Subject: [PATCH] Wip call handling --- src/app/organisms/room/JitsiRoom.jsx | 52 ++++++++++++++++++---------- src/app/organisms/room/Room.jsx | 23 +++++------- src/app/templates/client/Client.jsx | 28 ++++++++------- 3 files changed, 57 insertions(+), 46 deletions(-) diff --git a/src/app/organisms/room/JitsiRoom.jsx b/src/app/organisms/room/JitsiRoom.jsx index 9f0847a3..188477ca 100644 --- a/src/app/organisms/room/JitsiRoom.jsx +++ b/src/app/organisms/room/JitsiRoom.jsx @@ -10,12 +10,13 @@ import { openNavigation } from '../../../client/action/navigation'; import { getUsername } from '../../../util/matrixUtil'; import Button from '../../atoms/button/Button'; -function JitsiRoom() { +function JitsiRoom(props) { + const { jitsiCallId, setJitsiCallId } = props; + const [roomInfo, setRoomInfo] = useState({ roomTimeline: null, eventId: null, }); - const [activeCall, setActiveCall] = useState(false); const [roomName, setRoomName] = useState(''); const [roomId, setRoomId] = useState(''); const openerRef = useRef(null); @@ -27,15 +28,23 @@ function JitsiRoom() { roomInfo.roomTimeline?.removeInternalListeners(); if (mx.getRoom(rId)) { const roomTimeline = new RoomTimeline(rId); - setRoomInfo({ - roomTimeline, - eventId: eId ?? null, - }); if ( roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic === + 'd38dd491fefa1cfffc27f9c57f2bdb4a' && + confirm('aaa') + ) { + setRoomInfo({ + roomTimeline, + eventId: eId ?? null, + }); + } else if ( + roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic !== 'd38dd491fefa1cfffc27f9c57f2bdb4a' ) { - setActiveCall(true); + setRoomInfo({ + roomTimeline, + eventId: eId ?? null, + }); } } else { // TODO: add ability to join room if roomId is invalid @@ -46,22 +55,29 @@ function JitsiRoom() { } }; - navigation.on(cons.events.navigation.ROOM_SELECTED, handleRoomSelected); - return () => { - navigation.removeListener(cons.events.navigation.ROOM_SELECTED, handleRoomSelected); - }; + navigation.once(cons.events.navigation.ROOM_SELECTED, handleRoomSelected); }, [mx, roomInfo]); + useEffect(() => { + if ( + roomInfo.roomTimeline?.room.currentState.getStateEvents('m.room.topic')[0]?.getContent() + .topic === 'd38dd491fefa1cfffc27f9c57f2bdb4a' && + !jitsiCallId + ) { + setJitsiCallId(roomInfo.roomTimeline.roomId); + if (roomName === '') { + setRoomName(roomInfo.roomTimeline.roomName); + } + } + }, [roomInfo.roomTimeline?.roomName]); + const { roomTimeline } = roomInfo; if (roomTimeline === null) { setTimeout(() => openNavigation()); return null; } - if (activeCall) { - if (roomName === '') { - setRoomName(roomTimeline.roomName); - } + if (jitsiCallId) { return (
); - } - - if (!activeCall) { + } else { return
; } } diff --git a/src/app/organisms/room/Room.jsx b/src/app/organisms/room/Room.jsx index 44209836..77c1bb3b 100644 --- a/src/app/organisms/room/Room.jsx +++ b/src/app/organisms/room/Room.jsx @@ -14,7 +14,7 @@ import RoomSettings from './RoomSettings'; import PeopleDrawer from './PeopleDrawer'; import Button from '../../atoms/button/Button'; -function Room() { +function Room(props) { const [roomInfo, setRoomInfo] = useState({ roomTimeline: null, eventId: null, @@ -27,8 +27,9 @@ function Room() { const handleRoomSelected = (rId, pRoomId, eId) => { roomInfo.roomTimeline?.removeInternalListeners(); if (mx.getRoom(rId)) { + const roomTimeline = new RoomTimeline(rId); setRoomInfo({ - roomTimeline: new RoomTimeline(rId), + roomTimeline, eventId: eId ?? null, }); } else { @@ -40,10 +41,7 @@ function Room() { } }; - navigation.on(cons.events.navigation.ROOM_SELECTED, handleRoomSelected); - return () => { - navigation.removeListener(cons.events.navigation.ROOM_SELECTED, handleRoomSelected); - }; + navigation.once(cons.events.navigation.ROOM_SELECTED, handleRoomSelected); }, [roomInfo]); useEffect(() => { @@ -60,16 +58,11 @@ function Room() { return ; } - if ( + const isJitsiChannel = roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic === - 'd38dd491fefa1cfffc27f9c57f2bdb4a' - ) { - return ( -
- You are already in another call, do you want to switch to this one? - -
- ); + 'd38dd491fefa1cfffc27f9c57f2bdb4a'; + if (isJitsiChannel) { + return null; } return ( diff --git a/src/app/templates/client/Client.jsx b/src/app/templates/client/Client.jsx index 0ea34493..db1dac41 100644 --- a/src/app/templates/client/Client.jsx +++ b/src/app/templates/client/Client.jsx @@ -27,6 +27,7 @@ function Client() { const [isLoading, changeLoading] = useState(true); const [loadingMsg, setLoadingMsg] = useState('Heating up'); const [dragCounter, setDragCounter] = useState(0); + const [jitsiCallId, setJitsiCallId] = useState(null); const classNameHidden = 'client__item-hidden'; const navWrapperRef = useRef(null); @@ -45,19 +46,16 @@ function Client() { navigation.on(cons.events.navigation.ROOM_SELECTED, onRoomSelected); navigation.on(cons.events.navigation.NAVIGATION_OPENED, onNavigationSelected); - return (() => { + return () => { navigation.removeListener(cons.events.navigation.ROOM_SELECTED, onRoomSelected); navigation.removeListener(cons.events.navigation.NAVIGATION_OPENED, onNavigationSelected); - }); + }; }, []); useEffect(() => { let counter = 0; const iId = setInterval(() => { - const msgList = [ - 'Almost there...', - 'Looks like you have a lot of stuff to heat up!', - ]; + const msgList = ['Almost there...', 'Looks like you have a lot of stuff to heat up!']; if (counter === msgList.length - 1) { setLoadingMsg(msgList[msgList.length - 1]); clearInterval(iId); @@ -81,22 +79,28 @@ function Client() {
initMatrix.clearCacheAndReload()}> Clear cache & reload initMatrix.logout()}>Logout + } + render={(toggle) => ( + )} - render={(toggle) => } />
- {loadingMsg} + + {loadingMsg} +
- Cinny + + Cinny +
); @@ -167,13 +171,13 @@ function Client() { onDrop={handleDrop} >
- +
- +