-
Notifications
You must be signed in to change notification settings - Fork 18
/
CallParticipantsGrid.tsx
120 lines (111 loc) · 3.7 KB
/
CallParticipantsGrid.tsx
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
115
116
117
118
119
120
import React from 'react';
import { StyleSheet, View, ViewStyle } from 'react-native';
import { useCallStateHooks } from '@stream-io/video-react-bindings';
import { useDebouncedValue } from '../../../utils/hooks/useDebouncedValue';
import {
CallParticipantsList as DefaultCallParticipantsList,
CallParticipantsListComponentProps,
} from '../CallParticipantsList/CallParticipantsList';
import { ComponentTestIds } from '../../../constants/TestIds';
import { useTheme } from '../../../contexts/ThemeContext';
import { CallContentProps } from '../CallContent';
import { ParticipantViewComponentProps } from '../../Participant';
import { useIsInPiPMode } from '../../../hooks';
import { StreamVideoParticipant } from '@stream-io/video-client';
/**
* Props for the CallParticipantsGrid component.
*/
export type CallParticipantsGridProps = ParticipantViewComponentProps &
Pick<CallContentProps, 'supportedReactions' | 'CallParticipantsList'> &
Pick<CallParticipantsListComponentProps, 'ParticipantView'> & {
/**
* Boolean to decide if local participant will be visible in the grid when there is 1:1 call.
*/
showLocalParticipant?: boolean;
/**
* Check if device is in landscape mode.
* This will apply the landscape mode styles to the component.
*/
landscape?: boolean;
};
/**
* Component used to display the list of participants in a grid mode.
*/
export const CallParticipantsGrid = ({
CallParticipantsList = DefaultCallParticipantsList,
ParticipantLabel,
ParticipantNetworkQualityIndicator,
ParticipantReaction,
ParticipantVideoFallback,
ParticipantView,
VideoRenderer,
showLocalParticipant = false,
supportedReactions,
landscape,
}: CallParticipantsGridProps) => {
const {
theme: { colors, callParticipantsGrid },
} = useTheme();
const { useRemoteParticipants, useParticipants, useLocalParticipant } =
useCallStateHooks();
const _remoteParticipants = useRemoteParticipants();
const localParticipant = useLocalParticipant();
const _allParticipants = useParticipants();
// we debounce the participants arrays to avoid unnecessary rerenders that happen when participant tracks are all subscribed simultaneously
const remoteParticipants = useDebouncedValue(_remoteParticipants, 300);
const allParticipants = useDebouncedValue(_allParticipants, 300);
const landscapeStyles: ViewStyle = {
flexDirection: landscape ? 'row' : 'column',
};
const isInPiPMode = useIsInPiPMode();
const showFloatingView =
!isInPiPMode &&
remoteParticipants.length > 0 &&
remoteParticipants.length < 3;
let participants = showFloatingView
? showLocalParticipant && localParticipant
? [localParticipant]
: remoteParticipants
: allParticipants;
if (isInPiPMode) {
participants =
remoteParticipants.length > 0
? [remoteParticipants[0] as StreamVideoParticipant]
: localParticipant
? [localParticipant]
: [];
}
const participantViewProps: CallParticipantsListComponentProps = {
ParticipantView,
ParticipantLabel,
ParticipantNetworkQualityIndicator,
ParticipantReaction,
ParticipantVideoFallback,
VideoRenderer,
};
return (
<View
style={[
styles.container,
landscapeStyles,
{ backgroundColor: colors.dark_gray },
callParticipantsGrid.container,
]}
testID={ComponentTestIds.CALL_PARTICIPANTS_GRID}
>
{CallParticipantsList && (
<CallParticipantsList
participants={participants}
supportedReactions={supportedReactions}
landscape={landscape}
{...participantViewProps}
/>
)}
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
});