Skip to content

Commit 69c4694

Browse files
authored
fix: handle undefined participant in iOS pip (#1878)
### 💡 Overview Fixes a bug caused by #1876 There could be 0 participants when rendering RTCIOSPiP, this was not handled ### 📝 Implementation notes Added a null defaulter
1 parent 4e8eeaa commit 69c4694

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export const RTCViewPipIOS = React.memo((props: Props) => {
3939

4040
// show the dominant remote speaker in PiP mode
4141
// local speaker is shown only if remote doesn't exist
42-
let participantInSpotlight = dominantSpeaker;
42+
let participantInSpotlight: StreamVideoParticipant | undefined =
43+
dominantSpeaker;
4344
if (dominantSpeaker?.isLocalParticipant && dominantSpeaker2) {
4445
participantInSpotlight = dominantSpeaker2;
4546
}
@@ -94,9 +95,11 @@ export const RTCViewPipIOS = React.memo((props: Props) => {
9495
}
9596
}, []);
9697

97-
const { videoStream, screenShareStream } = participantInSpotlight;
98+
const { videoStream, screenShareStream } = participantInSpotlight || {};
9899

99-
const isScreenSharing = hasScreenShare(participantInSpotlight);
100+
const isScreenSharing = participantInSpotlight
101+
? hasScreenShare(participantInSpotlight)
102+
: false;
100103

101104
const videoStreamToRender = (isScreenSharing
102105
? screenShareStream
@@ -112,12 +115,14 @@ export const RTCViewPipIOS = React.memo((props: Props) => {
112115
return (
113116
<>
114117
<RTCViewPipNative streamURL={streamURL} ref={nativeRef} />
115-
<DimensionsUpdatedRenderless
116-
participant={participantInSpotlight}
117-
trackType={isScreenSharing ? 'screenShareTrack' : 'videoTrack'}
118-
onDimensionsUpdated={onDimensionsUpdated}
119-
key={streamURL}
120-
/>
118+
{participantInSpotlight && (
119+
<DimensionsUpdatedRenderless
120+
participant={participantInSpotlight}
121+
trackType={isScreenSharing ? 'screenShareTrack' : 'videoTrack'}
122+
onDimensionsUpdated={onDimensionsUpdated}
123+
key={streamURL}
124+
/>
125+
)}
121126
</>
122127
);
123128
});

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ const NativeComponent: HostComponent<RTCViewPipNativeProps> =
1919

2020
export function onNativeCallClosed(reactTag: number) {
2121
getLogger(['RTCViewPipNative'])('debug', 'onNativeCallClosed');
22-
UIManager.dispatchViewManagerCommand(
23-
reactTag,
24-
UIManager.getViewManagerConfig(COMPONENT_NAME).Commands.onCallClosed,
25-
[],
26-
);
22+
const commandId =
23+
UIManager.getViewManagerConfig(COMPONENT_NAME).Commands.onCallClosed;
24+
if (!commandId) return;
25+
UIManager.dispatchViewManagerCommand(reactTag, commandId, []);
2726
}
2827

2928
export function onNativeDimensionsUpdated(
@@ -35,12 +34,11 @@ export function onNativeDimensionsUpdated(
3534
width,
3635
height,
3736
});
38-
UIManager.dispatchViewManagerCommand(
39-
reactTag,
37+
const commandId =
4038
UIManager.getViewManagerConfig(COMPONENT_NAME).Commands
41-
.setPreferredContentSize,
42-
[width, height],
43-
);
39+
.setPreferredContentSize;
40+
if (!commandId) return;
41+
UIManager.dispatchViewManagerCommand(reactTag, commandId, [width, height]);
4442
}
4543

4644
/** Wrapper for the native view

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useIsIosScreenshareBroadcastStarted } from './useIsIosScreenshareBroadc
1212
// ios >= 14.0 or android - platform restrictions
1313
const CanDeviceScreenShare =
1414
(Platform.OS === 'ios' &&
15-
Number.parseInt(Platform.Version.split('.')[0], 10) >= 14) ||
15+
Number.parseInt(Platform.Version?.split('.')[0] ?? '0', 10) >= 14) ||
1616
Platform.OS === 'android';
1717

1818
export const useScreenShareButton = (

packages/react-native-sdk/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"skipLibCheck": true,
1313
"strict": true,
1414
"strictNullChecks": true,
15+
"noUncheckedIndexedAccess": true,
1516
"jsx": "react"
1617
},
1718
"include": ["src"]

0 commit comments

Comments
 (0)