2018-04-06 21:11:01 +00:00
|
|
|
// @flow
|
2017-06-05 18:00:02 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { RTCView } from 'react-native-webrtc';
|
|
|
|
|
2018-04-17 22:35:48 +00:00
|
|
|
import { Pressable } from '../../../react';
|
|
|
|
|
2018-04-07 07:52:38 +00:00
|
|
|
import VideoTransform from './VideoTransform';
|
2020-05-20 10:57:03 +00:00
|
|
|
import styles from './styles';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of {@link Video}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
type Props = {
|
|
|
|
mirror: boolean,
|
2018-04-06 21:11:01 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
onPlaying: Function,
|
2018-04-06 21:11:01 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Callback to invoke when the {@code Video} is clicked/pressed.
|
|
|
|
*/
|
|
|
|
onPress: Function,
|
2018-04-06 21:11:01 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
stream: Object,
|
2016-12-01 01:52:39 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Similarly to the CSS property z-index, specifies the z-order of this
|
|
|
|
* Video in the stacking space of all Videos. When Videos overlap,
|
|
|
|
* zOrder determines which one covers the other. A Video with a larger
|
|
|
|
* zOrder generally covers a Video with a lower one.
|
|
|
|
*
|
|
|
|
* Non-overlapping Videos may safely share a z-order (because one does
|
|
|
|
* not have to cover the other).
|
|
|
|
*
|
|
|
|
* The support for zOrder is platform-dependent and/or
|
|
|
|
* implementation-specific. Thus, specifying a value for zOrder is to be
|
|
|
|
* thought of as giving a hint rather than as imposing a requirement.
|
|
|
|
* For example, video renderers such as Video are commonly implemented
|
|
|
|
* using OpenGL and OpenGL views may have different numbers of layers in
|
|
|
|
* their stacking space. Android has three: a layer bellow the window
|
|
|
|
* (aka default), a layer bellow the window again but above the previous
|
|
|
|
* layer (aka media overlay), and above the window. Consequently, it is
|
|
|
|
* advisable to limit the number of utilized layers in the stacking
|
|
|
|
* space to the minimum sufficient for the desired display. For example,
|
|
|
|
* a video call application usually needs a maximum of two zOrder
|
|
|
|
* values: 0 for the remote video(s) which appear in the background, and
|
|
|
|
* 1 for the local video(s) which appear above the remote video(s).
|
|
|
|
*/
|
|
|
|
zOrder: number,
|
2018-04-07 07:52:38 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Indicates whether zooming (pinch to zoom and/or drag) is enabled.
|
|
|
|
*/
|
|
|
|
zoomEnabled: boolean
|
|
|
|
};
|
2016-12-01 01:52:39 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The React Native {@link Component} which is similar to Web's
|
|
|
|
* {@code HTMLVideoElement} and wraps around react-native-webrtc's
|
|
|
|
* {@link RTCView}.
|
|
|
|
*/
|
|
|
|
export default class Video extends Component<Props> {
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* React Component method that executes once component is mounted.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
|
|
|
// RTCView currently does not support media events, so just fire
|
|
|
|
// onPlaying callback when <RTCView> is rendered.
|
2017-03-24 14:06:54 +00:00
|
|
|
const { onPlaying } = this.props;
|
|
|
|
|
|
|
|
onPlaying && onPlaying();
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement|null}
|
|
|
|
*/
|
|
|
|
render() {
|
2018-04-17 22:35:48 +00:00
|
|
|
const { onPress, stream, zoomEnabled } = this.props;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
if (stream) {
|
2018-04-17 22:35:48 +00:00
|
|
|
// RTCView
|
2016-10-05 14:36:59 +00:00
|
|
|
const style = styles.video;
|
2018-04-07 07:52:38 +00:00
|
|
|
const objectFit
|
|
|
|
= zoomEnabled
|
|
|
|
? 'contain'
|
|
|
|
: (style && style.objectFit) || 'cover';
|
2018-04-17 22:35:48 +00:00
|
|
|
const rtcView
|
2018-08-06 16:09:32 +00:00
|
|
|
= (
|
2018-04-06 21:11:01 +00:00
|
|
|
<RTCView
|
|
|
|
mirror = { this.props.mirror }
|
|
|
|
objectFit = { objectFit }
|
2018-04-17 22:35:48 +00:00
|
|
|
streamURL = { stream.toURL() }
|
2018-04-06 21:11:01 +00:00
|
|
|
style = { style }
|
|
|
|
zOrder = { this.props.zOrder } />
|
2018-04-17 22:35:48 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// VideoTransform implements "pinch to zoom". As part of "pinch to
|
|
|
|
// zoom", it implements onPress, of course.
|
|
|
|
if (zoomEnabled) {
|
|
|
|
return (
|
|
|
|
<VideoTransform
|
|
|
|
enabled = { zoomEnabled }
|
|
|
|
onPress = { onPress }
|
|
|
|
streamId = { stream.id }
|
|
|
|
style = { style }>
|
|
|
|
{ rtcView }
|
|
|
|
</VideoTransform>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Unfortunately, VideoTransform implements a custom press
|
|
|
|
// detection which has been observed to be very picky about the
|
|
|
|
// precision of the press unlike the builtin/default/standard press
|
|
|
|
// detection which is forgiving to imperceptible movements while
|
|
|
|
// pressing. It's not acceptable to be so picky, especially when
|
|
|
|
// "pinch to zoom" is not enabled.
|
|
|
|
return (
|
|
|
|
<Pressable onPress = { onPress }>
|
|
|
|
{ rtcView }
|
|
|
|
</Pressable>
|
2016-10-05 14:36:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// RTCView has peculiarities which may or may not be platform specific.
|
|
|
|
// For example, it doesn't accept an empty streamURL. If the execution
|
|
|
|
// reached here, it means that we explicitly chose to not initialize an
|
|
|
|
// RTCView as a way of dealing with its idiosyncrasies.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|