From f8bd543a432e79565e4609702521097ddf5541c6 Mon Sep 17 00:00:00 2001 From: Jessica Mitchell Date: Mon, 6 Dec 2021 16:04:04 -0500 Subject: [PATCH] return is remote participants is empty array --- custom/shared/hooks/useSharedState.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/custom/shared/hooks/useSharedState.js b/custom/shared/hooks/useSharedState.js index a1ebce7..d4ada7a 100644 --- a/custom/shared/hooks/useSharedState.js +++ b/custom/shared/hooks/useSharedState.js @@ -72,6 +72,9 @@ export const useSharedState = ({ initialValues = {}, broadcast = true }) => { new Date(p.joined_at) < new Date(localParticipant.joined_at) ); + // avoid sending message if no remote participants are available + if (remoteParticipants?.length === 0) return; + const randomPeer = remoteParticipants[ Math.floor(Math.random() * remoteParticipants.length)