Merge pull request #51 from daily-demos/dev-1107-useSharedState-add-early-return

Add early return in case remote participant array is empty (useSharedState)
This commit is contained in:
Jess Mitchell 2021-12-07 15:25:28 -05:00 committed by GitHub
commit 17e022dbc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -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)