import React from 'react'; import { type HostComponent, Platform, requireNativeComponent, StyleSheet, UIManager, } from 'react-native'; import { videoLoggerSystem } from '@stream-io/video-client'; const COMPONENT_NAME = 'RTCViewPip'; export type PiPChangeEvent = { active: boolean; }; export type PiPBoundsChangeEvent = { /** the laid out width of the native window, in logical points */ width: number; /** the laid out height of the native window, in logical points */ height: number; }; type RTCViewPipNativeProps = { streamURL?: string; mirror?: boolean; onPiPChange?: (event: { nativeEvent: PiPChangeEvent }) => void; /** * Reports the actual laid out bounds of the native Picture in Picture window. */ onPiPBoundsChange?: (event: { nativeEvent: PiPBoundsChangeEvent }) => void; /** The participant's name for the avatar placeholder when video is disabled */ participantName?: string; /** The URL string for the participant's profile image */ participantImageURL?: string; /** Whether the call is reconnecting - when true, shows reconnection view */ isReconnecting?: boolean; /** Whether screen sharing is active (used for content state tracking) */ isScreenSharing?: boolean; /** Whether the participant has audio enabled (shown in participant overlay) */ hasAudio?: boolean; /** Whether the video track is paused (shown in participant overlay) */ isTrackPaused?: boolean; /** Whether the participant is pinned (shown in participant overlay) */ isPinned?: boolean; /** Whether the participant is currently speaking (shows border highlight) */ isSpeaking?: boolean; /** The connection quality level (0: unknown, 1: poor, 2: good, 3: excellent) */ connectionQuality?: number; }; const NativeComponent: HostComponent = requireNativeComponent(COMPONENT_NAME); export function onNativeCallClosed(reactTag: number) { videoLoggerSystem.getLogger('RTCViewPipNative').debug('onNativeCallClosed'); const commandId = UIManager.getViewManagerConfig(COMPONENT_NAME).Commands.onCallClosed; if (!commandId) return; UIManager.dispatchViewManagerCommand(reactTag, commandId, []); } export function onNativeDimensionsUpdated( reactTag: number, width: number, height: number, ) { videoLoggerSystem .getLogger('RTCViewPipNative') .debug('onNativeDimensionsUpdated', { width, height, }); const commandId = UIManager.getViewManagerConfig(COMPONENT_NAME).Commands .setPreferredContentSize; if (!commandId) return; UIManager.dispatchViewManagerCommand(reactTag, commandId, [width, height]); } /** Wrapper for the native view * meant to stay private and not exposed */ export const RTCViewPipNative = React.memo( React.forwardRef, RTCViewPipNativeProps>((props, ref) => { if (Platform.OS !== 'ios') return null; return ( ); }), );