Use daily-react-hooks in examples#72
Conversation
51a5e2b to
4a55eaf
Compare
4a55eaf to
d68ab23
Compare
ghost
left a comment
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
This seems like it would potentially push undefined to the array, do we want that?
|
|
||
| useResize(() => { | ||
| const { width, height } = viewRef.current?.getBoundingClientRect(); | ||
| setDimensions({ |
There was a problem hiding this comment.
Seems like the dimensions here can be undefined, what would happen in that case?
There was a problem hiding this comment.
probably good to add
if (!width || !height) return;
| height: containerRef.current?.clientHeight, | ||
| }) | ||
| ); | ||
| width: Math.floor(dims.width), |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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'} |
There was a problem hiding this comment.
In general, negation is harder to parse, so I would suggest rewriting this and the other ternary operators to avoid it
| 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'; |
There was a problem hiding this comment.
Why did you rename the variable here?
|
|
||
| const MIN_TILE_WIDTH = 280; | ||
| const MAX_TILES_PER_PAGE = 12; | ||
| const MAX_TILES_PER_PAGE = 25; |
| if (disableAudio) return null; | ||
| if (isSafari() || topology === 'peer') { | ||
| return subscribedIds.map((sessionId) => ( | ||
| // @ts-ignore |
There was a problem hiding this comment.
Why are we doing a ts-ignore here?
| useEffect(() => { | ||
| if (!audioEl.current) return; | ||
| const AC = AudioContext || webkitAudioContext; | ||
| audioCtx.current = window.audioContext ?? new AC(); |
There was a problem hiding this comment.
When is window.audioContext null and not undefined?
| return ( | ||
| <div className="person-row"> | ||
| <div className="name"> | ||
| {participant.user_name} {participant.local && '(You)'} |
There was a problem hiding this comment.
I think the returned participant can be null, should probably check for that
|
|
||
| return ( | ||
| <option value={participant.session_id} key={sessionId}> | ||
| {participant.user_name} |
There was a problem hiding this comment.
same here, it might be worth adding a null check since useParticipant() can return null
| }; | ||
|
|
||
| if (layoutType === 'single-participant') | ||
| config.layout.session_id = participantId; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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'; | |||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
let's use the full word instead of s+p (can't think of what that stands for)
| }, [updateRatio]); | ||
|
|
||
| useEffect(() => updateRatio(), [updateRatio]); | ||
|
|
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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 } = |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
this can be moved into submitForm named method. (Please avoid inline functions as much as possible as a general rule👍 )
|
Looking forward to this! |
This PR is to use the
@daily-co/daily-react-hookspackage in the examples repo.