diff --git a/src/components/hooks/__mocks__/useMeeting.js b/src/components/hooks/__mocks__/useMeeting.js index 06f1ad0a2..79a6d2fde 100644 --- a/src/components/hooks/__mocks__/useMeeting.js +++ b/src/components/hooks/__mocks__/useMeeting.js @@ -1,14 +1,7 @@ import {useContext} from 'react'; -export default function useMeeting(meetingID, meetingDestination) { +export default function useMeeting(meetingID) { const datasource = useContext(); - let result = {}; - if (meetingID in datasource.meetingsAdapter) { - result = datasource.meetingsAdapter[meetingID]; - } else if (meetingDestination) { - result = datasource.meetingsAdapter[meetingDestination]; - } - - return result; + return meetingID ? datasource.meetingsAdapter[meetingID] : {}; } diff --git a/src/components/hooks/useMeeting.js b/src/components/hooks/useMeeting.js index e924ed428..6035895a6 100644 --- a/src/components/hooks/useMeeting.js +++ b/src/components/hooks/useMeeting.js @@ -1,56 +1,47 @@ import {useEffect, useContext, useState} from 'react'; -import {from} from 'rxjs'; -import {delayWhen, flatMap, take} from 'rxjs/operators'; import {AdapterContext} from '../../components/'; /** * Custom hook that returns meeting data of the given ID. - * If no ID is given, a `meetingDestination` must be provided to - * create a new meeting. * - * @param {string} meetingID ID of the meeting for which to return data. - * @param {string} meetingDestination Virtual location where the meeting should take place. + * @param {string} meetingID ID of the meeting for which to get data * @returns {Meeting} Data of the meeting */ -export default function useMeeting(meetingID, meetingDestination) { - const [meeting, setMeeting] = useState({}); +export default function useMeeting(meetingID) { + const emptyMeeting = { + ID: null, + title: null, + localAudio: null, + localVideo: null, + remoteAudio: null, + remoteVideo: null, + }; + + const [meeting, setMeeting] = useState(emptyMeeting); const {meetingsAdapter} = useContext(AdapterContext); useEffect(() => { - let subscription; + // React won't recognize the meeting attributes have been updated + // since the state is the meeting object itself. We need to create a new + // meeting object trigger the state change + const onMeeting = (newMeeting) => { + setMeeting({...newMeeting}); + }; const onError = (error) => { throw error; }; - const onMeeting = (newMeeting) => { - // React won't recognize the meeting attributes have been updated - // since the state is the meeting object itself. We need to create a new - // meeting object trigger the state change - setMeeting({...newMeeting}); + const onComplete = () => { + setMeeting(emptyMeeting); }; - if (meetingID) { - subscription = meetingsAdapter.getMeeting(meetingID).subscribe(onMeeting, onError); - } else if (meetingDestination) { - // Create a meeting, start event listeners by subscribing to getMeeting, - // wait for local media to get added and complete - subscription = meetingsAdapter - .createMeeting(meetingDestination) - .pipe( - flatMap(({ID}) => meetingsAdapter.getMeeting(ID)), - take(1), - delayWhen(({ID}) => from(meetingsAdapter.addLocalMedia(ID))) - ) - .subscribe(onMeeting, onError); - } + const subscription = meetingsAdapter.getMeeting(meetingID).subscribe(onMeeting, onError, onComplete); return () => { - if (subscription) { - subscription.unsubscribe(); - } + subscription.unsubscribe(); }; // eslint-disable-next-line react-hooks/exhaustive-deps - }, [meetingID, meetingDestination]); + }, [meetingID]); return meeting; }