1
1
import * as React from 'react' ;
2
2
3
- import { Image , StyleSheet , ViewStyle } from 'react-native' ;
3
+ import { Image , StyleSheet , type ViewStyle } from 'react-native' ;
4
4
import {
5
5
isTrackReference ,
6
- TrackReferenceOrPlaceholder ,
6
+ type TrackReferenceOrPlaceholder ,
7
7
useEnsureTrackRef ,
8
8
useIsMuted ,
9
9
useIsSpeaking ,
@@ -14,63 +14,71 @@ import { View } from 'react-native';
14
14
import { Text } from 'react-native' ;
15
15
import { useTheme } from '@react-navigation/native' ;
16
16
import { Track } from 'livekit-client' ;
17
+ import { Component , forwardRef } from 'react' ;
17
18
export type Props = {
18
19
trackRef : TrackReferenceOrPlaceholder ;
19
20
style ?: ViewStyle ;
20
21
zOrder ?: number ;
21
22
mirror ?: boolean ;
23
+ useIOSPIP ?: boolean ;
22
24
} ;
23
- export const ParticipantView = ( {
24
- style = { } ,
25
- trackRef,
26
- zOrder,
27
- mirror,
28
- } : Props ) => {
29
- const trackReference = useEnsureTrackRef ( trackRef ) ;
30
- const { identity, name } = useParticipantInfo ( {
31
- participant : trackReference . participant ,
32
- } ) ;
33
- const isSpeaking = useIsSpeaking ( trackRef . participant ) ;
34
- const isVideoMuted = useIsMuted ( trackRef ) ;
35
- const { colors } = useTheme ( ) ;
36
- let videoView ;
37
- if ( isTrackReference ( trackRef ) && ! isVideoMuted ) {
38
- videoView = (
39
- < VideoTrack
40
- style = { styles . videoView }
41
- trackRef = { trackRef }
42
- zOrder = { zOrder }
43
- mirror = { mirror }
44
- />
45
- ) ;
46
- } else {
47
- videoView = (
48
- < View style = { styles . videoView } >
49
- < View style = { styles . spacer } />
50
- < Image
51
- style = { styles . icon }
52
- source = { require ( './icons/baseline_videocam_off_white_24dp.png' ) }
25
+ export const ParticipantView = forwardRef < Component , Props > (
26
+ ( { style = { } , trackRef, zOrder, mirror, useIOSPIP = false } : Props , ref ) => {
27
+ const trackReference = useEnsureTrackRef ( trackRef ) ;
28
+ const { identity, name } = useParticipantInfo ( {
29
+ participant : trackReference . participant ,
30
+ } ) ;
31
+ const isSpeaking = useIsSpeaking ( trackRef . participant ) ;
32
+ const isVideoMuted = useIsMuted ( trackRef ) ;
33
+ const { colors } = useTheme ( ) ;
34
+ let videoView ;
35
+ if ( isTrackReference ( trackRef ) && ! isVideoMuted ) {
36
+ videoView = (
37
+ < VideoTrack
38
+ style = { styles . videoView }
39
+ trackRef = { trackRef }
40
+ zOrder = { zOrder }
41
+ mirror = { mirror }
42
+ ref = { ref }
43
+ iosPIP = { {
44
+ enabled : useIOSPIP ,
45
+ startAutomatically : true ,
46
+ preferredSize : {
47
+ width : 800 ,
48
+ height : 800 ,
49
+ } ,
50
+ } }
53
51
/>
54
- < View style = { styles . spacer } />
55
- </ View >
56
- ) ;
57
- }
52
+ ) ;
53
+ } else {
54
+ videoView = (
55
+ < View style = { styles . videoView } >
56
+ < View style = { styles . spacer } />
57
+ < Image
58
+ style = { styles . icon }
59
+ source = { require ( './icons/baseline_videocam_off_white_24dp.png' ) }
60
+ />
61
+ < View style = { styles . spacer } />
62
+ </ View >
63
+ ) ;
64
+ }
58
65
59
- let displayName = name ? name : identity ;
60
- if ( trackRef . source === Track . Source . ScreenShare ) {
61
- displayName = displayName + "'s screen" ;
62
- }
66
+ let displayName = name ? name : identity ;
67
+ if ( trackRef . source === Track . Source . ScreenShare ) {
68
+ displayName = displayName + "'s screen" ;
69
+ }
63
70
64
- return (
65
- < View style = { [ styles . container , style ] } >
66
- { videoView }
67
- < View style = { styles . identityBar } >
68
- < Text style = { { color : colors . text } } > { displayName } </ Text >
71
+ return (
72
+ < View style = { [ styles . container , style ] } >
73
+ { videoView }
74
+ < View style = { styles . identityBar } >
75
+ < Text style = { { color : colors . text } } > { displayName } </ Text >
76
+ </ View >
77
+ { isSpeaking && < View style = { styles . speakingIndicator } /> }
69
78
</ View >
70
- { isSpeaking && < View style = { styles . speakingIndicator } /> }
71
- </ View >
72
- ) ;
73
- } ;
79
+ ) ;
80
+ }
81
+ ) ;
74
82
75
83
const styles = StyleSheet . create ( {
76
84
container : {
0 commit comments