Wip call handling

This commit is contained in:
CrazyStevenz 2023-03-22 00:41:40 +02:00
parent dba8638109
commit 5f17e4153b
3 changed files with 57 additions and 46 deletions

View file

@ -10,12 +10,13 @@ import { openNavigation } from '../../../client/action/navigation';
import { getUsername } from '../../../util/matrixUtil'; import { getUsername } from '../../../util/matrixUtil';
import Button from '../../atoms/button/Button'; import Button from '../../atoms/button/Button';
function JitsiRoom() { function JitsiRoom(props) {
const { jitsiCallId, setJitsiCallId } = props;
const [roomInfo, setRoomInfo] = useState({ const [roomInfo, setRoomInfo] = useState({
roomTimeline: null, roomTimeline: null,
eventId: null, eventId: null,
}); });
const [activeCall, setActiveCall] = useState(false);
const [roomName, setRoomName] = useState(''); const [roomName, setRoomName] = useState('');
const [roomId, setRoomId] = useState(''); const [roomId, setRoomId] = useState('');
const openerRef = useRef(null); const openerRef = useRef(null);
@ -27,15 +28,23 @@ function JitsiRoom() {
roomInfo.roomTimeline?.removeInternalListeners(); roomInfo.roomTimeline?.removeInternalListeners();
if (mx.getRoom(rId)) { if (mx.getRoom(rId)) {
const roomTimeline = new RoomTimeline(rId); const roomTimeline = new RoomTimeline(rId);
if (
roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic ===
'd38dd491fefa1cfffc27f9c57f2bdb4a' &&
confirm('aaa')
) {
setRoomInfo({ setRoomInfo({
roomTimeline, roomTimeline,
eventId: eId ?? null, eventId: eId ?? null,
}); });
if ( } else if (
roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic === roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic !==
'd38dd491fefa1cfffc27f9c57f2bdb4a' 'd38dd491fefa1cfffc27f9c57f2bdb4a'
) { ) {
setActiveCall(true); setRoomInfo({
roomTimeline,
eventId: eId ?? null,
});
} }
} else { } else {
// TODO: add ability to join room if roomId is invalid // TODO: add ability to join room if roomId is invalid
@ -46,22 +55,29 @@ function JitsiRoom() {
} }
}; };
navigation.on(cons.events.navigation.ROOM_SELECTED, handleRoomSelected); navigation.once(cons.events.navigation.ROOM_SELECTED, handleRoomSelected);
return () => {
navigation.removeListener(cons.events.navigation.ROOM_SELECTED, handleRoomSelected);
};
}, [mx, roomInfo]); }, [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; const { roomTimeline } = roomInfo;
if (roomTimeline === null) { if (roomTimeline === null) {
setTimeout(() => openNavigation()); setTimeout(() => openNavigation());
return null; return null;
} }
if (activeCall) { if (jitsiCallId) {
if (roomName === '') {
setRoomName(roomTimeline.roomName);
}
return ( return (
<div className="call"> <div className="call">
<div className="call_header" id="header" ref={openerRef}> <div className="call_header" id="header" ref={openerRef}>
@ -69,7 +85,7 @@ function JitsiRoom() {
</div> </div>
<Button <Button
onClick={() => { onClick={() => {
setActiveCall(false); setJitsiCallId(null);
setRoomName(''); setRoomName('');
}} }}
> >
@ -130,9 +146,7 @@ function JitsiRoom() {
/> />
</div> </div>
); );
} } else {
if (!activeCall) {
return <div className="hiddenJitsiCall" />; return <div className="hiddenJitsiCall" />;
} }
} }

View file

@ -14,7 +14,7 @@ import RoomSettings from './RoomSettings';
import PeopleDrawer from './PeopleDrawer'; import PeopleDrawer from './PeopleDrawer';
import Button from '../../atoms/button/Button'; import Button from '../../atoms/button/Button';
function Room() { function Room(props) {
const [roomInfo, setRoomInfo] = useState({ const [roomInfo, setRoomInfo] = useState({
roomTimeline: null, roomTimeline: null,
eventId: null, eventId: null,
@ -27,8 +27,9 @@ function Room() {
const handleRoomSelected = (rId, pRoomId, eId) => { const handleRoomSelected = (rId, pRoomId, eId) => {
roomInfo.roomTimeline?.removeInternalListeners(); roomInfo.roomTimeline?.removeInternalListeners();
if (mx.getRoom(rId)) { if (mx.getRoom(rId)) {
const roomTimeline = new RoomTimeline(rId);
setRoomInfo({ setRoomInfo({
roomTimeline: new RoomTimeline(rId), roomTimeline,
eventId: eId ?? null, eventId: eId ?? null,
}); });
} else { } else {
@ -40,10 +41,7 @@ function Room() {
} }
}; };
navigation.on(cons.events.navigation.ROOM_SELECTED, handleRoomSelected); navigation.once(cons.events.navigation.ROOM_SELECTED, handleRoomSelected);
return () => {
navigation.removeListener(cons.events.navigation.ROOM_SELECTED, handleRoomSelected);
};
}, [roomInfo]); }, [roomInfo]);
useEffect(() => { useEffect(() => {
@ -60,16 +58,11 @@ function Room() {
return <Welcome />; return <Welcome />;
} }
if ( const isJitsiChannel =
roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic === roomTimeline.room.currentState.getStateEvents('m.room.topic')[0]?.getContent().topic ===
'd38dd491fefa1cfffc27f9c57f2bdb4a' 'd38dd491fefa1cfffc27f9c57f2bdb4a';
) { if (isJitsiChannel) {
return ( return null;
<div className="room__content">
You are already in another call, do you want to switch to this one?
<Button>Join call</Button>
</div>
);
} }
return ( return (

View file

@ -27,6 +27,7 @@ function Client() {
const [isLoading, changeLoading] = useState(true); const [isLoading, changeLoading] = useState(true);
const [loadingMsg, setLoadingMsg] = useState('Heating up'); const [loadingMsg, setLoadingMsg] = useState('Heating up');
const [dragCounter, setDragCounter] = useState(0); const [dragCounter, setDragCounter] = useState(0);
const [jitsiCallId, setJitsiCallId] = useState(null);
const classNameHidden = 'client__item-hidden'; const classNameHidden = 'client__item-hidden';
const navWrapperRef = useRef(null); const navWrapperRef = useRef(null);
@ -45,19 +46,16 @@ function Client() {
navigation.on(cons.events.navigation.ROOM_SELECTED, onRoomSelected); navigation.on(cons.events.navigation.ROOM_SELECTED, onRoomSelected);
navigation.on(cons.events.navigation.NAVIGATION_OPENED, onNavigationSelected); navigation.on(cons.events.navigation.NAVIGATION_OPENED, onNavigationSelected);
return (() => { return () => {
navigation.removeListener(cons.events.navigation.ROOM_SELECTED, onRoomSelected); navigation.removeListener(cons.events.navigation.ROOM_SELECTED, onRoomSelected);
navigation.removeListener(cons.events.navigation.NAVIGATION_OPENED, onNavigationSelected); navigation.removeListener(cons.events.navigation.NAVIGATION_OPENED, onNavigationSelected);
}); };
}, []); }, []);
useEffect(() => { useEffect(() => {
let counter = 0; let counter = 0;
const iId = setInterval(() => { const iId = setInterval(() => {
const msgList = [ const msgList = ['Almost there...', 'Looks like you have a lot of stuff to heat up!'];
'Almost there...',
'Looks like you have a lot of stuff to heat up!',
];
if (counter === msgList.length - 1) { if (counter === msgList.length - 1) {
setLoadingMsg(msgList[msgList.length - 1]); setLoadingMsg(msgList[msgList.length - 1]);
clearInterval(iId); clearInterval(iId);
@ -81,22 +79,28 @@ function Client() {
<div className="loading__menu"> <div className="loading__menu">
<ContextMenu <ContextMenu
placement="bottom" placement="bottom"
content={( content={
<> <>
<MenuItem onClick={() => initMatrix.clearCacheAndReload()}> <MenuItem onClick={() => initMatrix.clearCacheAndReload()}>
Clear cache & reload Clear cache & reload
</MenuItem> </MenuItem>
<MenuItem onClick={() => initMatrix.logout()}>Logout</MenuItem> <MenuItem onClick={() => initMatrix.logout()}>Logout</MenuItem>
</> </>
}
render={(toggle) => (
<IconButton size="extra-small" onClick={toggle} src={VerticalMenuIC} />
)} )}
render={(toggle) => <IconButton size="extra-small" onClick={toggle} src={VerticalMenuIC} />}
/> />
</div> </div>
<Spinner /> <Spinner />
<Text className="loading__message" variant="b2">{loadingMsg}</Text> <Text className="loading__message" variant="b2">
{loadingMsg}
</Text>
<div className="loading__appname"> <div className="loading__appname">
<Text variant="h2" weight="medium">Cinny</Text> <Text variant="h2" weight="medium">
Cinny
</Text>
</div> </div>
</div> </div>
); );
@ -167,13 +171,13 @@ function Client() {
onDrop={handleDrop} onDrop={handleDrop}
> >
<div className="jitsi_room__wrapper"> <div className="jitsi_room__wrapper">
<JitsiRoom /> <JitsiRoom jitsiCallId={jitsiCallId} setJitsiCallId={setJitsiCallId} />
</div> </div>
<div className="navigation__wrapper" ref={navWrapperRef}> <div className="navigation__wrapper" ref={navWrapperRef}>
<Navigation /> <Navigation />
</div> </div>
<div className={`room__wrapper ${classNameHidden}`} ref={roomWrapperRef}> <div className={`room__wrapper ${classNameHidden}`} ref={roomWrapperRef}>
<Room /> <Room jitsiCallId={jitsiCallId} setJitsiCallId={setJitsiCallId} />
</div> </div>
<Windows /> <Windows />
<Dialogs /> <Dialogs />