import React, { FunctionComponent, useEffect, useState } from 'react'; import { ImageStyle, Platform, StyleSheet, Text, TextStyle, View, ViewStyle, } from 'react-native'; import { Logger } from '../../../utils/Log'; import { IStyledProps } from '../../common/types'; import { IConference, IConferenceParticipants } from '../../../store/conference/types'; import RTCView from '../RTCView'; import { eventEmitter, EventType } from '../../../services/EventEmitter'; import { IImageHolderStyle, ImageHolder } from '../../common/ImageHolder'; import Icon from 'react-native-vector-icons/Ionicons'; const logger = new Logger('ParticipantConferenceView'); export interface IParticipantViewStyleProps { participantViewStyle?: ImageStyle; ParticipantDetailContainer?: ViewStyle; participantBackgroundViewStyle?: ViewStyle; miceIconStyle?: TextStyle; userNameStyle?: TextStyle; container?: ViewStyle; participantImageStyle?: IImageHolderStyle; } interface IProps extends IStyledProps { participant: IConferenceParticipants; renderParticipantDetailView?: () => React.ReactNode; renderParticipantProfileView?: () => React.ReactNode; } export const ParticipantConferenceView: FunctionComponent = (props: IProps) => { const { participant, style } = props const [conferenceParticipant, setConferenceParticipant] = useState(participant); const mergedStyle = { ...defaultStyle, ...style }; const mergedParticipantImageStyle = { ...participantImageStyle, ...style?.participantImageStyle }; useEffect(() => { setConferenceParticipant(participant) const conferenceParticipantStatusUpdate = eventEmitter.addListener(EventType.ConferenceParticipantStatusUpdate, (updatedParticipant: IConferenceParticipants) => { logger.info(`ConferenceParticipantStatusUpdate with name ${updatedParticipant.name}`); if (updatedParticipant.jId === conferenceParticipant.jId) { setConferenceParticipant(updatedParticipant); } }); return () => { conferenceParticipantStatusUpdate.remove(); } }, [conferenceParticipant, participant.isVideoSubscribed, participant]); const ParticipantDetail = () => { if (props.renderParticipantDetailView) { return props.renderParticipantDetailView(); } else { return ( {conferenceParticipant.name} ); } }; const renderUserView = () => { if (props.renderParticipantProfileView) { return props.renderParticipantProfileView(); } else { return ( conferenceParticipant.isVideoSubscribed ? : ) } } return ( {renderUserView()} {ParticipantDetail()} ); }; const participantImageStyle: IImageHolderStyle = { thumbnail: { width: 150, height: 150, position: 'absolute', zIndex: 2, borderRadius: 50 }, imageTextStyle: { color: 'white', fontSize: 45, fontWeight: 'bold' } } const defaultStyle: IParticipantViewStyleProps = StyleSheet.create({ container: { flex: 1, flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'center' }, participantViewStyle: { width: 150, height: 150, zIndex: 0 }, participantBackgroundViewStyle: { justifyContent: 'center', }, ParticipantDetailContainer: { marginTop: 10, backgroundColor: '#707680', flexDirection: 'row', alignItems:'center', }, userNameStyle: { color: 'white', fontSize: 20, marginLeft: 5, width: 130, maxWidth: 130, textAlign: 'center' } });