Skip to content

Commit a99de4c

Browse files
santhoshvaiCopilot
andauthored
fix: keep objectfit as cover for floating video view (#1849)
### 💡 Overview In this PR, - we make sure that floating participant view is always cover, because its always a small view - we also remove usage of track.getSettings() for local participant as it was incorrect ### ⏩ Next iteration - TODO Next, We should wait for dimensions to be valid to render the video element. If we wait now, the delay is 2 seconds for rtc stats to appear, this makes the video component render after an unnecessary delay. We will next add a native event listener webrtc level to send dimensions change update. Then add this mechanism. --------- Co-authored-by: Copilot <[email protected]>
1 parent 8eaa6bf commit a99de4c

File tree

3 files changed

+9
-33
lines changed

3 files changed

+9
-33
lines changed

packages/react-native-sdk/src/components/Call/CallContent/CallContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export const CallContent = ({
221221
}
222222
onPressHandler={handleFloatingViewParticipantSwitch}
223223
supportedReactions={supportedReactions}
224+
objectFit="cover"
224225
{...participantViewProps}
225226
/>
226227
)}

packages/react-native-sdk/src/components/Participant/ParticipantView/VideoRenderer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ export const VideoRenderer = ({
7272
deregister: deregisterIosScreenshot,
7373
} = useScreenshotIosContext();
7474

75-
const videoDimensions = useTrackDimensions(participant, trackType);
75+
const videoDimensions = useTrackDimensions(participant);
76+
7677
const {
7778
isLocalParticipant,
7879
sessionId,

packages/react-native-sdk/src/hooks/useTrackDimensions.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
type StreamVideoParticipant,
3-
type VideoTrackType,
4-
} from '@stream-io/video-client';
1+
import { type StreamVideoParticipant } from '@stream-io/video-client';
52
import { useCall } from '@stream-io/video-react-bindings';
63
import { useEffect, useState } from 'react';
74

@@ -10,48 +7,25 @@ import { useEffect, useState } from 'react';
107
* Note: the `tracktype` is used only for local participants.
118
* `tracktype` should be 'videoTrack' for video track and 'screenShareTrack' for screen share track.
129
*/
13-
export function useTrackDimensions(
14-
participant: StreamVideoParticipant,
15-
trackType: VideoTrackType,
16-
) {
10+
export function useTrackDimensions(participant: StreamVideoParticipant) {
1711
const [trackDimensions, setTrackDimensions] = useState({
1812
width: 0,
1913
height: 0,
2014
});
2115
const call = useCall();
22-
const { isLocalParticipant, sessionId, videoStream, screenShareStream } =
23-
participant;
16+
const { sessionId } = participant;
2417

25-
// for local participant we can get from track.getSettings()
26-
useEffect(() => {
27-
if (call && isLocalParticipant) {
28-
const stream =
29-
trackType === 'screenShareTrack' ? screenShareStream : videoStream;
30-
if (!stream) return;
31-
const [track] = stream.getVideoTracks();
32-
if (!track) return;
33-
const { width = 0, height = 0 } = track.getSettings();
34-
setTrackDimensions((prev) => {
35-
if (prev.width !== width || prev.height !== height) {
36-
return { width, height };
37-
}
38-
return prev;
39-
});
40-
}
41-
}, [call, isLocalParticipant, screenShareStream, trackType, videoStream]);
42-
43-
// start reporting stats for the remote participant
4418
useEffect(() => {
4519
if (!call) return;
46-
if (isLocalParticipant) return;
4720
call.startReportingStatsFor(sessionId);
4821
return () => {
4922
call.stopReportingStatsFor(sessionId);
5023
};
51-
}, [call, sessionId, isLocalParticipant]);
24+
}, [call, sessionId]);
5225

5326
// for remote participants track.getSettings() is not supported it returns an empty object
54-
// so we need to rely on call stats to get the dimensions
27+
// and for local participants we can get from track.getSettings() but it reports the wrong dimensions as it sends the constraints
28+
// so we need to rely on call stats for all participants to get the dimensions
5529
useEffect(() => {
5630
if (!call) return;
5731
const sub = call.state.callStatsReport$.subscribe((report) => {

0 commit comments

Comments
 (0)