-
Notifications
You must be signed in to change notification settings - Fork 8
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general the code in the Room screen is too complicated and too nested.
Consider doing it like this:
Move the participants part to another component.
Then calculate participantsWithTracks
like you're doing it now and keep the focused participant+track in state.
Now you have two cases:
- If there is a focused track then return the rendered focused track+non-focused participants (you can have multiple return statements in one component!)
- Else return the participants in a grid.
And extract the logic of getting the tracks etc from the views to functions. That should take care of most of the nesting.
Also it would be nice if the RoomParticipant just took the whole available space and didn't care about aspect ratios etc.
About my Android device bug: the focused participant takes the whole width of the screen and the height according to aspect ratio. Then the not focused participants take the available height and they have aspect ration set to 1 so they take the same width. Probably my device is taller than yours. RN reports window size 411x936px, my model is xperia 10 III
.
In my opinion the non focused participants should have 128x128px and the the focused participant takes the rest of available space. I'd fix that but right now the code is too complicated for me :D
@@ -171,6 +190,13 @@ const styles = StyleSheet.create({ | |||
aspectRatio: 1, | |||
alignSelf: 'center', | |||
}, | |||
videoTrackScreencast: { | |||
flex: 1, | |||
aspectRatio: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we manage the aspect ratio in the parent component? that way would be simpler and we can get rid of the focused
prop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The focused prop will have to stay either way since it is used to determine not only the style but also pin button behaviour and moving it to the parent would make it less readable in my opinion. Also managing aspect ratio in the parent isn't as simple as it may seem, since I want to keep the displayName / muted / pin icons in fixed positions whatever the aspect ratio is, and managing thet from the parent would affect that. That's also why I don't like the idea of room participant taking the entire space as it would depend on the parent aspect ratio.
I did a fair bit of refactoring and in my opinion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a couple of simple code style fixes this time 👍
|
||
return ( | ||
<View style={styles.focusedParticipantContainer}> | ||
<View style={styles.focusedParticipant}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again those two views can be merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple copy pasting won't work here, so I think it would be best to leave it as it is for now especially since MV-395 will be reworking it's styling anyway.
const videoTrack = tracks.find((t) => t.id === trackId); | ||
const videoTrackType = videoTrack?.metadata.type; | ||
const audioTrack = | ||
!videoTrack || videoTrackType === 'camera' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear what are you doing here: if there is no video track or the videotrack is from camera then search for audio track? Why? You already have a check if the track is screenshared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never realised I could just that screenshared check from before, good point. Should be simpler now.
example/src/screens/Room.tsx
Outdated
@@ -106,74 +113,25 @@ export const Room = () => { | |||
<View style={{ flex: 1 }}> | |||
{shouldShowParticipants && ( | |||
<> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer need the outer fragment (<>
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. I tried removing that and it gives an error, which the editor constantly recommends to fix by wrapping in empty jsx tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
const videoTrack = trackId ? tracks.find((t) => t.id === trackId) : null; | ||
const videoTrackType = videoTrack?.metadata.type; | ||
const audioTrack = | ||
videoTrackType !== 'screensharing' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think this check is unecessary (though it's simpler). You literally have the same one lower in the code (videoTrackType !== 'screensharing' &&
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
2f728ab
to
9b12076
Compare
I think useEffect in the |
example/src/screens/Room.tsx
Outdated
focusedParticipantData?.participant !== curretStateOfFocusedParticipant | ||
) { | ||
setFocusedParticipantData({ | ||
participant: curretStateOfFocusedParticipant!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if pinned participant exits the call? I've got a crash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks. I haven't realised that the participant that is being focused could disappear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and get rid of this ! now, it's not necessary
and it caused the crash again, I'm considering adding a lint rule to prohibit using ! :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok now it looks pretty good 👏
Maybe putting the whole focused participant instead of just id wasn't a good idea after all - now I see we now have kind of double state but we'll think that out and refactor this later. Sorry for that 😅
No description provided.