From f037103a10ec23bf7538fd1a5e93bff79ee389de Mon Sep 17 00:00:00 2001 From: harshithpabbati Date: Mon, 4 Apr 2022 14:27:17 +0530 Subject: [PATCH 1/3] Use waitingParticipants hook --- custom/shared/contexts/WaitingRoomProvider.js | 84 ++----------------- 1 file changed, 8 insertions(+), 76 deletions(-) diff --git a/custom/shared/contexts/WaitingRoomProvider.js b/custom/shared/contexts/WaitingRoomProvider.js index f6498de..b705f95 100644 --- a/custom/shared/contexts/WaitingRoomProvider.js +++ b/custom/shared/contexts/WaitingRoomProvider.js @@ -1,42 +1,24 @@ import React, { createContext, - useCallback, useContext, useEffect, useMemo, useState, } from 'react'; +import { useWaitingParticipants } from '@daily-co/daily-react-hooks'; import PropTypes from 'prop-types'; -import { useCallState } from './CallProvider'; const WaitingRoomContext = createContext(null); export const WaitingRoomProvider = ({ children }) => { - const { callObject } = useCallState(); - const [waitingParticipants, setWaitingParticipants] = useState([]); + const { waitingParticipants, grantAccess, denyAccess } = + useWaitingParticipants(); const [showModal, setShowModal] = useState(false); - const handleWaitingParticipantEvent = useCallback(() => { - if (!callObject) return; - - const waiting = Object.entries(callObject.waitingParticipants()); - - console.log(`🚪 ${waiting.length} participant(s) waiting for access`); - - setWaitingParticipants((wp) => - waiting.map(([pid, p]) => { - const prevWP = wp.find(({ id }) => id === pid); - return { - ...p, - joinDate: prevWP?.joinDate ?? new Date(), - }; - }) - ); - }, [callObject]); - - const multipleWaiting = useMemo(() => waitingParticipants.length > 1, [ - waitingParticipants, - ]); + const multipleWaiting = useMemo( + () => waitingParticipants.length > 1, + [waitingParticipants] + ); useEffect(() => { if (waitingParticipants.length === 0) { @@ -44,56 +26,6 @@ export const WaitingRoomProvider = ({ children }) => { } }, [waitingParticipants]); - useEffect(() => { - if (!callObject) return false; - - console.log('🚪 Waiting room provider listening for requests'); - - const events = [ - 'waiting-participant-added', - 'waiting-participant-updated', - 'waiting-participant-removed', - ]; - - events.forEach((e) => callObject.on(e, handleWaitingParticipantEvent)); - - return () => - events.forEach((e) => callObject.off(e, handleWaitingParticipantEvent)); - }, [callObject, handleWaitingParticipantEvent]); - - const updateWaitingParticipant = (id, grantRequestedAccess) => { - if (!waitingParticipants.some((p) => p.id === id)) return; - callObject.updateWaitingParticipant(id, { - grantRequestedAccess, - }); - setWaitingParticipants((wp) => wp.filter((p) => p.id !== id)); - }; - - const updateAllWaitingParticipants = (grantRequestedAccess) => { - if (!waitingParticipants.length) return; - callObject.updateWaitingParticipants({ - '*': { - grantRequestedAccess, - }, - }); - setWaitingParticipants([]); - }; - - const grantAccess = (id = 'all') => { - if (id === 'all') { - updateAllWaitingParticipants(true); - return; - } - updateWaitingParticipant(id, true); - }; - const denyAccess = (id = 'all') => { - if (id === 'all') { - updateAllWaitingParticipants(false); - return; - } - updateWaitingParticipant(id, false); - }; - return ( useContext(WaitingRoomContext); +export const useWaitingRoom = () => useContext(WaitingRoomContext); \ No newline at end of file From 77f602b17b596465e6f62a81a3171db1bc2c62fa Mon Sep 17 00:00:00 2001 From: harshithpabbati Date: Fri, 8 Apr 2022 12:57:46 +0530 Subject: [PATCH 2/3] fix not found page back button --- custom/basic-call/pages/not-found.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom/basic-call/pages/not-found.js b/custom/basic-call/pages/not-found.js index 1d25fb7..1e9a56c 100644 --- a/custom/basic-call/pages/not-found.js +++ b/custom/basic-call/pages/not-found.js @@ -1,10 +1,13 @@ import React from 'react'; import MessageCard from '@custom/shared/components/MessageCard'; +import { useRouter } from 'next/router'; export default function RoomNotFound() { + const router = useRouter(); + return (
- + router.push('/')}> The room you are trying to join does not exist. Have you created the room using the Daily REST API or the dashboard? From 9a926286c3e90677cf2d31fd349295cdaa6aa90b Mon Sep 17 00:00:00 2001 From: harshithpabbati Date: Tue, 12 Apr 2022 12:04:19 +0530 Subject: [PATCH 3/3] Address changes --- custom/basic-call/pages/not-found.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom/basic-call/pages/not-found.js b/custom/basic-call/pages/not-found.js index 1e9a56c..45d5408 100644 --- a/custom/basic-call/pages/not-found.js +++ b/custom/basic-call/pages/not-found.js @@ -5,9 +5,11 @@ import { useRouter } from 'next/router'; export default function RoomNotFound() { const router = useRouter(); + const returnToHomePage = () => router.push('/'); + return (
- router.push('/')}> + The room you are trying to join does not exist. Have you created the room using the Daily REST API or the dashboard?