import React, { FunctionComponent } from 'react'; import { ImageStyle, StyleSheet, View, ViewStyle } from 'react-native'; import { CallState, IP2PCall } from '../../../store/webrtc/types'; import { Logger } from '../../../utils/Log'; import { IImageHolderStyle, ImageHolder } from '../../common/ImageHolder'; import { IStyledProps } from '../../common/types'; import RTCView from '../RTCView'; const logger = new Logger('CallView'); export interface ICallViewStyleProps { localVideo?: ViewStyle; remoteVideo?: ViewStyle; shareVideo?: ViewStyle; thumbnail?: ImageStyle; } interface IProps extends IStyledProps { call: IP2PCall; renderIncomingCallView?: (call: IP2PCall) => React.ReactNode; renderOutgoingCallView?: (call: IP2PCall) => React.ReactNode; renderActiveCallView?: (call: IP2PCall) => React.ReactNode; } export const MyLocalWebrtcVideo: FunctionComponent<{ style?: ViewStyle }> = (props) => { const mergedLocalVideoStyle = { ...defaultStyle.localVideo, ...props.style } return ( ) } export const RemoteWebrtcVideo: FunctionComponent<{ style?: ViewStyle, call: IP2PCall }> = (props) => { const mergedRemoteVideo = { ...defaultStyle.remoteVideo, ...props.style } return ( ) } export const SharingVideo: FunctionComponent<{ style?: ViewStyle, call: IP2PCall }> = (props) => { const mergedSharingVideo = { ...defaultStyle.shareVideo, ...props.style } return ( ) } export const P2PCallView: FunctionComponent = ({ call, renderIncomingCallView, renderOutgoingCallView, renderActiveCallView }) => { const { callState, videoRemoteStreamCount, isLocalVideoEnabled, wasInitiatedWithVideo, isRemoteVideoEnabled, wasInitiatedWithShare } = call; const profilePictureView = (videoRemoteStreamCount === 0) && ; if (!call) { logger.error('Null call or null contact received'); return null; } const renderIncomingCallComponent = () => { if (callState === CallState.RINGING_INCOMING) { if (renderIncomingCallView) return renderIncomingCallView(call); else { return profilePictureView; } } else { return null; } } const renderOutgoingCallComponent = () => { if (callState === CallState.RINGING_OUTGOING) { if (renderOutgoingCallView) return renderOutgoingCallView(call); else { return profilePictureView; } } else { return null; } } const renderActiveCallComponent = () => { if (callState !== CallState.ACTIVE) { return null; } if (renderActiveCallView) { return renderActiveCallView(call) } const remoteVideoDynamicStyle = wasInitiatedWithShare ? { width:150, height: 150, top:10 } : {}; const remoteCombinedStyle = { ...defaultStyle.remoteVideo,...remoteVideoDynamicStyle }; return ( <> {!wasInitiatedWithVideo && profilePictureView} { wasInitiatedWithShare && } { isRemoteVideoEnabled && } {isLocalVideoEnabled && } ) } return ( {renderIncomingCallComponent()} {renderOutgoingCallComponent()} {renderActiveCallComponent()} ); }; const participantImageStyle: IImageHolderStyle = { thumbnail: { top: 100, alignSelf: 'center', width: 140, height: 140, borderRadius: 100 }, thumbnailContainer: { position: 'absolute', top: 100, alignSelf: 'center', width: 140, height: 140, borderWidth: 1, borderColor: 'rgba(0,0,0,0.2)', borderRadius: 100, justifyContent: 'center', alignItems: 'center', backgroundColor: '#cf0071' }, imageTextStyle: { fontSize: 50, } } const defaultStyle = StyleSheet.create({ shareVideo: { position: 'absolute', top: 20, width: '100%', height: 250, alignSelf: 'center', }, localVideo: { position: 'absolute', top: 10, end: 10, width: 150, height: 150, }, remoteVideo: { position: 'absolute',width: '100%', height: 250, top :50}, thumbnail: { position: 'absolute', top: 100, alignSelf: 'center', width: 140, height: 140, }, });