Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Use daily-react-hooks in examples#72

Open
harshithpabbati wants to merge 1 commit into
mainfrom
daily-react-hooks
Open

Use daily-react-hooks in examples#72
harshithpabbati wants to merge 1 commit into
mainfrom
daily-react-hooks

Conversation

@harshithpabbati

Copy link
Copy Markdown
Contributor

This PR is to use the @daily-co/daily-react-hooks package in the examples repo.

@vercel

vercel Bot commented Mar 10, 2022

Copy link
Copy Markdown

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

custom-basic-call – ./custom/basic-call

🔍 Inspect: https://vercel.com/daily-co/custom-basic-call/3HszgbCP8vQfiJagf1bzxfGm4ygj
✅ Preview: https://custom-basic-call-git-daily-react-hooks-daily-co.vercel.app

custom-flying-emojis – ./custom/flying-emojis

🔍 Inspect: https://vercel.com/daily-co/custom-flying-emojis/3RijBRbUxn7ztXXnZpBRoT5DGJJE
✅ Preview: https://custom-flying-emojis-git-daily-react-hooks-daily-co.vercel.app

custom-pagination – ./custom/pagination

🔍 Inspect: https://vercel.com/daily-co/custom-pagination/FuobYjb5XCoKRzLjzCoKAey1bjEp
✅ Preview: https://custom-pagination-git-daily-react-hooks-daily-co.vercel.app

custom-text-chat – ./custom/text-chat

🔍 Inspect: https://vercel.com/daily-co/custom-text-chat/26WNNidG8nMQWiDaYWB2EJQHUyv2
✅ Preview: https://custom-text-chat-git-daily-react-hooks-daily-co.vercel.app

custom-live-streaming – ./custom/live-streaming

🔍 Inspect: https://vercel.com/daily-co/custom-live-streaming/Da5dAVKhcBXkrPrJUyzpqDc6BsyN
✅ Preview: https://custom-live-streaming-git-daily-react-hooks-daily-co.vercel.app

prebuilt-basic-embed – ./prebuilt/basic-embed

🔍 Inspect: https://vercel.com/daily-co/prebuilt-basic-embed/AJ1f5yWPe7icZPDc8XYT452gHB3M
✅ Preview: https://prebuilt-basic-embed-git-daily-react-hooks-daily-co.vercel.app

examples – ./custom/live-transcription

🔍 Inspect: https://vercel.com/daily-co/examples/Cw12A6QHByvjbWNiW1UUbkRTLVAR
✅ Preview: https://examples-git-daily-react-hooks-daily-co.vercel.app

custom-live-transcription – ./custom/live-transcription

🔍 Inspect: https://vercel.com/daily-co/custom-live-transcription/Dn4rNduTbXC11HqqR3XnjsSRHeRE
✅ Preview: https://custom-live-transcription-git-daily-react-hooks-daily-co.vercel.app

custom-active-speaker – ./custom/active-speaker

🔍 Inspect: https://vercel.com/daily-co/custom-active-speaker/5NBeSFj4ojrZ7cs9e1JE1eTSF8n6
✅ Preview: https://custom-active-speaker-git-daily-react-hooks-daily-co.vercel.app

fitness – ./custom/fitness-demo

🔍 Inspect: https://vercel.com/daily-co/fitness/BiN1H2iecwZTzftLZBn898dCF3zT
✅ Preview: https://fitness-git-daily-react-hooks-daily-co.vercel.app

@harshithpabbati harshithpabbati marked this pull request as draft March 10, 2022 13:07

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just made a small start, adding some initial comments!

setRatio(rect.width / rect.height);
setScreenHeight(rect.height);
if (!screenRef.current) return;
const { height, width } = screenRef.current.getBoundingClientRect();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, will this work as expected if the aspect ratio is <1?

}
if (hasScreenshares && otherParticipants.length > 0) {
items.push(otherParticipants[0]);
items.push(localParticipant?.session_id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it would potentially push undefined to the array, do we want that?


useResize(() => {
const { width, height } = viewRef.current?.getBoundingClientRect();
setDimensions({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the dimensions here can be undefined, what would happen in that case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably good to add
if (!width || !height) return;

height: containerRef.current?.clientHeight,
})
);
width: Math.floor(dims.width),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a chance that this will result in an unhandled TypeError, since dims can be undefined above. Should we handle that case before trying to use dims.width and dims.height here?

);
const rowCount = Math.ceil(tileCount / columnCount);
const rowGap = rowCount - 1;
if (rowCount * maxHeightPerTile + rowGap > height) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just confirming: are we expecting to only be adding one count of rowGap here? Or is the rowGap intended to be per tile? (ie should this be rowCount * (maxHeightPerTile + rowGap)?

@jayne-mast jayne-mast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't gone through the full thing yet, but here are just a few minor comments. I think in the future it would be better to split this up into multiple PRs

{!isOwner ? (
<>
<span
className={!participant.video ? 'state error' : 'state success'}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, negation is harder to parse, so I would suggest rewriting this and the other ternary operators to avoid it

Suggested change
className={!participant.video ? 'state error' : 'state success'}
className={participant.video ? 'state success' : 'state error'}

import { useCallState } from '@custom/shared/contexts/CallProvider';
import React, { createContext, useContext } from 'react';
import { useUIState } from '@custom/shared/contexts/UIStateProvider';
import { useLiveStreaming as useDailyLiveStreaming } from '@daily-co/daily-react-hooks';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you rename the variable here?


const MIN_TILE_WIDTH = 280;
const MAX_TILES_PER_PAGE = 12;
const MAX_TILES_PER_PAGE = 25;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed?

if (disableAudio) return null;
if (isSafari() || topology === 'peer') {
return subscribedIds.map((sessionId) => (
// @ts-ignore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we doing a ts-ignore here?

useEffect(() => {
if (!audioEl.current) return;
const AC = AudioContext || webkitAudioContext;
audioCtx.current = window.audioContext ?? new AC();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is window.audioContext null and not undefined?

return (
<div className="person-row">
<div className="name">
{participant.user_name} {participant.local && '(You)'}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the returned participant can be null, should probably check for that


return (
<option value={participant.session_id} key={sessionId}>
{participant.user_name}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, it might be worth adding a null check since useParticipant() can return null

};

if (layoutType === 'single-participant')
config.layout.session_id = participantId;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I get that sometimes single-line conditionals without braces read smoother, but imo multiline conditionals usually read easier and more consistently with braces around them.

// Get the sender's current display name or the local name
const sender =
e.data?.session_id !== participants.local.session_id
? participants[e.data.session_id].user_name

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance of e.data being undefined or null when we get here (since we have optional chaining for it right above) and running into a TypeError while trying to access it on this line?

swapParticipantPosition(sortedVisibleRemoteParticipants[0].id, peerId);
},
[page, swapParticipantPosition, visibleParticipants]
const sortedVisibleRemoteParticipantIds = useDeepCompareMemo(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing it doesn't make sense to use/showcase the hooks useParticipantIds() sort parameter here?

@@ -27,32 +31,34 @@ export const RECORDING_IDLE = 'idle';

export const RECORDING_TYPE_CLOUD = 'cloud';
export const RECORDING_TYPE_CLOUD_BETA = 'cloud-beta';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that the cloud-beta recording type is a thing anymore, do you know? The docs specify cloud, local, output-byte-stream, and rtp-tracks

@jessmitch42 jessmitch42 Mar 21, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct - cloud is now what was previously referred to as cloud-beta

const { aspectRatio, height, maxWidth } = useMemo(() => {
/**
* We're relying on calculating what there is room for
* the total number of s+p tiles instead of using

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use the full word instead of s+p (can't think of what that stands for)

}, [updateRatio]);

useEffect(() => updateRatio(), [updateRatio]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this? it looks like it needs to be called on render from the looks of it but maybe it's unnecessary?

<Tile
aspectRatio={finalRatio}
participant={participant}
sessionId={sessionId}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these changes only converting to daily hooks or are there additional changes?


export const SpeakerView = () => {
const { currentSpeaker, localParticipant, participants, screens } =
const { currentSpeakerId, localParticipant, screens, orderedParticipantIds } =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it's confusing to use localParticipant from the useParticipants provider still. Why not the Daily Hook? Is there a use case where we would need it from the participants provider? If not, it can be removed

onJoin(roomName, owner, fetchToken);
}}>
<form
onSubmit={(e) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be moved into submitForm named method. (Please avoid inline functions as much as possible as a general rule👍 )

@rememberlenny

Copy link
Copy Markdown

Looking forward to this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants