2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
import React, { Component } from 'react';
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
import { trackVideoStarted } from '../../tracks';
|
|
|
|
|
|
|
|
import { shouldRenderVideoTrack } from '../functions';
|
|
|
|
import { Video } from './_';
|
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of {@link AbstractVideoTrack}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
export type Props = {
|
|
|
|
|
2016-12-01 01:52:39 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The Redux dispatch function.
|
2016-12-01 01:52:39 +00:00
|
|
|
*/
|
2019-03-19 15:42:25 +00:00
|
|
|
dispatch: Dispatch<any>,
|
2017-07-14 19:22:27 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Callback to invoke when the {@link Video} of {@code AbstractVideoTrack}
|
|
|
|
* is clicked/pressed.
|
|
|
|
*/
|
|
|
|
onPress?: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Redux representation of the participant's video track.
|
|
|
|
*/
|
|
|
|
videoTrack?: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not video should be rendered after knowing video playback has
|
|
|
|
* started.
|
|
|
|
*/
|
|
|
|
waitForVideoStarted?: boolean,
|
2018-04-06 21:11:01 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The z-order of the Video of AbstractVideoTrack in the stacking space of
|
|
|
|
* all Videos. For more details, refer to the zOrder property of the Video
|
|
|
|
* class for React Native.
|
|
|
|
*/
|
|
|
|
zOrder?: number,
|
2017-07-14 19:22:27 +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
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} that renders video element for a
|
|
|
|
* specific video track.
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
*/
|
2018-12-01 19:50:33 +00:00
|
|
|
export default class AbstractVideoTrack<P: Props> extends Component<P> {
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new AbstractVideoTrack instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: P) {
|
2016-10-05 14:36:59 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
|
|
|
this._onVideoPlaying = this._onVideoPlaying.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2018-12-01 19:50:33 +00:00
|
|
|
const videoTrack = _falsy2null(this.props.videoTrack);
|
2016-10-05 14:36:59 +00:00
|
|
|
let render;
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
if (this.props.waitForVideoStarted && videoTrack) {
|
2016-10-05 14:36:59 +00:00
|
|
|
// That's the complex case: we have to wait for onPlaying before we
|
|
|
|
// render videoTrack. The complexity comes from the fact that
|
|
|
|
// onPlaying will come after we render videoTrack.
|
|
|
|
if (shouldRenderVideoTrack(videoTrack, true)) {
|
|
|
|
// It appears that onPlaying has come for videoTrack already.
|
|
|
|
// Most probably, another render has already passed through the
|
|
|
|
// else clause bellow already.
|
|
|
|
render = true;
|
|
|
|
} else if (shouldRenderVideoTrack(videoTrack, false)
|
|
|
|
&& !videoTrack.videoStarted) {
|
|
|
|
// XXX Unfortunately, onPlaying has not come for videoTrack yet.
|
|
|
|
// We have to render in order to give onPlaying a chance to
|
|
|
|
// come.
|
|
|
|
render = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// That's the simple case: we don't have to wait for onPlaying
|
|
|
|
// before we render videoTrack
|
|
|
|
render = shouldRenderVideoTrack(videoTrack, false);
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
const stream = render && videoTrack
|
|
|
|
? videoTrack.jitsiTrack.getOriginalStream() : null;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-04-07 07:52:38 +00:00
|
|
|
// Actual zoom is currently only enabled if the stream is a desktop
|
|
|
|
// stream.
|
|
|
|
const zoomEnabled
|
|
|
|
= this.props.zoomEnabled
|
|
|
|
&& stream
|
2018-10-30 05:02:23 +00:00
|
|
|
&& videoTrack
|
2018-04-07 07:52:38 +00:00
|
|
|
&& videoTrack.videoType === 'desktop';
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
return (
|
|
|
|
<Video
|
2017-04-05 05:18:41 +00:00
|
|
|
mirror = { videoTrack && videoTrack.mirror }
|
2016-10-05 14:36:59 +00:00
|
|
|
onPlaying = { this._onVideoPlaying }
|
2018-04-06 21:11:01 +00:00
|
|
|
onPress = { this.props.onPress }
|
2016-10-05 14:36:59 +00:00
|
|
|
stream = { stream }
|
2018-04-07 07:52:38 +00:00
|
|
|
zOrder = { this.props.zOrder }
|
|
|
|
zoomEnabled = { zoomEnabled } />
|
2016-10-05 14:36:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onVideoPlaying: () => void;
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Handler for case when video starts to play.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onVideoPlaying() {
|
2018-04-07 07:52:38 +00:00
|
|
|
const { videoTrack } = this.props;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-04-06 21:11:01 +00:00
|
|
|
if (videoTrack && !videoTrack.videoStarted) {
|
2016-10-05 14:36:59 +00:00
|
|
|
this.props.dispatch(trackVideoStarted(videoTrack.jitsiTrack));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns null if a specific value is falsy; otherwise, returns the specified
|
|
|
|
* value.
|
|
|
|
*
|
|
|
|
* @param {*} value - The value to return if it is not falsy.
|
|
|
|
* @returns {*} If the specified value is falsy, null; otherwise, the specified
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
function _falsy2null(value) {
|
|
|
|
return value || null;
|
|
|
|
}
|