-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathParticipantView.tsx
More file actions
114 lines (110 loc) · 2.83 KB
/
ParticipantView.tsx
File metadata and controls
114 lines (110 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import * as React from 'react';
import { Image, StyleSheet, type ViewStyle } from 'react-native';
import {
isTrackReference,
type TrackReferenceOrPlaceholder,
useEnsureTrackRef,
useIsMuted,
useIsSpeaking,
useParticipantInfo,
VideoTrack,
} from '@livekit/react-native';
import { View } from 'react-native';
import { Text } from 'react-native';
import { useTheme } from '@react-navigation/native';
import { Track } from 'livekit-client';
import { Component, forwardRef } from 'react';
export type Props = {
trackRef: TrackReferenceOrPlaceholder;
style?: ViewStyle;
zOrder?: number;
mirror?: boolean;
useIOSPIP?: boolean;
};
export const ParticipantView = forwardRef<Component, Props>(
({ style = {}, trackRef, zOrder, mirror, useIOSPIP = false }: Props, ref) => {
const trackReference = useEnsureTrackRef(trackRef);
const { identity, name } = useParticipantInfo({
participant: trackReference.participant,
});
const isSpeaking = useIsSpeaking(trackRef.participant);
const isVideoMuted = useIsMuted(trackRef);
const { colors } = useTheme();
let videoView;
if (isTrackReference(trackRef) && !isVideoMuted) {
videoView = (
<VideoTrack
style={styles.videoView}
trackRef={trackRef}
zOrder={zOrder}
mirror={mirror}
ref={ref}
iosPIP={{
enabled: useIOSPIP,
startAutomatically: true,
preferredSize: {
width: 800,
height: 800,
},
}}
/>
);
} else {
videoView = (
<View style={styles.videoView}>
<View style={styles.spacer} />
<Image
style={styles.icon}
source={require('./icons/baseline_videocam_off_white_24dp.png')}
/>
<View style={styles.spacer} />
</View>
);
}
let displayName = name ? name : identity;
if (trackRef.source === Track.Source.ScreenShare) {
displayName = displayName + "'s screen";
}
return (
<View style={[styles.container, style]}>
{videoView}
<View style={styles.identityBar}>
<Text style={{ color: colors.text }}>{displayName}</Text>
</View>
{isSpeaking && <View style={styles.speakingIndicator} />}
</View>
);
}
);
const styles = StyleSheet.create({
container: {
backgroundColor: '#00153C',
},
speakingIndicator: {
position: 'absolute',
bottom: 0,
width: '100%',
height: '100%',
borderColor: '#007DFF',
borderWidth: 3,
},
spacer: {
flex: 1,
},
videoView: {
width: '100%',
height: '100%',
},
identityBar: {
position: 'absolute',
bottom: 0,
width: '100%',
padding: 2,
backgroundColor: 'rgba(0,0,0,0.5)',
},
icon: {
width: 40,
height: 40,
alignSelf: 'center',
},
});