2019-01-16 04:44:41 +08:00
|
|
|
import React, { Component } from 'react';
|
2018-11-30 01:24:02 +08:00
|
|
|
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
|
2019-10-08 01:45:16 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2019-09-11 02:04:42 +08:00
|
|
|
import ReactPlayer from 'react-player';
|
2019-09-11 03:35:58 +08:00
|
|
|
import { sendMessage, onMessage, removeAllListeners } from './service';
|
2019-05-30 03:06:41 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-07-27 04:59:14 +08:00
|
|
|
import ArcPlayer from './custom-players/arc-player';
|
2020-11-27 04:30:37 +08:00
|
|
|
import PeerTubePlayer from './custom-players/peertube';
|
2019-07-27 04:59:14 +08:00
|
|
|
|
2019-07-17 04:56:07 +08:00
|
|
|
import { styles } from './styles';
|
|
|
|
|
2019-10-08 01:45:16 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
autoPlayWarning: {
|
|
|
|
id: 'app.externalVideo.autoPlayWarning',
|
|
|
|
description: 'Shown when user needs to interact with player to make it work',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-10-24 04:29:06 +08:00
|
|
|
const SYNC_INTERVAL_SECONDS = 5;
|
2020-02-28 03:42:07 +08:00
|
|
|
const THROTTLE_INTERVAL_SECONDS = 0.5;
|
2019-10-08 01:45:16 +08:00
|
|
|
const AUTO_PLAY_BLOCK_DETECTION_TIMEOUT_SECONDS = 5;
|
2019-05-30 03:06:41 +08:00
|
|
|
|
2020-11-27 04:30:37 +08:00
|
|
|
ReactPlayer.addCustomPlayer(PeerTubePlayer);
|
2019-07-27 04:59:14 +08:00
|
|
|
ReactPlayer.addCustomPlayer(ArcPlayer);
|
|
|
|
|
2018-11-30 01:24:02 +08:00
|
|
|
class VideoPlayer extends Component {
|
2019-01-16 04:44:41 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2019-09-11 02:04:42 +08:00
|
|
|
const { isPresenter } = props;
|
2019-07-16 04:12:07 +08:00
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
this.player = null;
|
|
|
|
this.syncInterval = null;
|
2019-10-08 01:45:16 +08:00
|
|
|
this.autoPlayTimeout = null;
|
2020-02-11 04:09:59 +08:00
|
|
|
this.hasPlayedBefore = false;
|
|
|
|
this.playerIsReady = false;
|
2020-02-11 05:09:03 +08:00
|
|
|
|
|
|
|
this.lastMessage = null;
|
2020-02-28 03:42:07 +08:00
|
|
|
this.lastMessageTimestamp = Date.now();
|
|
|
|
|
|
|
|
this.throttleTimeout = null;
|
2020-02-11 05:09:03 +08:00
|
|
|
|
2019-02-28 03:59:45 +08:00
|
|
|
this.state = {
|
|
|
|
mutedByEchoTest: false,
|
2019-07-16 04:12:07 +08:00
|
|
|
playing: false,
|
2019-10-08 01:45:16 +08:00
|
|
|
autoPlayBlocked: false,
|
2019-07-17 06:04:20 +08:00
|
|
|
playbackRate: 1,
|
2019-02-28 03:59:45 +08:00
|
|
|
};
|
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
this.opts = {
|
2020-06-10 03:41:51 +08:00
|
|
|
// default option for all players, can be overwritten
|
|
|
|
playerOptions: {
|
|
|
|
autoplay: true,
|
|
|
|
playsinline: true,
|
|
|
|
controls: true,
|
|
|
|
},
|
2019-10-09 22:52:26 +08:00
|
|
|
file: {
|
|
|
|
attributes: {
|
2020-12-26 23:01:54 +08:00
|
|
|
controls: true,
|
|
|
|
autoPlay: true,
|
|
|
|
playsInline: true,
|
2019-10-09 22:52:26 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
dailymotion: {
|
|
|
|
params: {
|
2019-10-11 05:15:32 +08:00
|
|
|
controls: true,
|
2019-10-09 22:52:26 +08:00
|
|
|
},
|
|
|
|
},
|
2019-07-16 04:12:07 +08:00
|
|
|
youtube: {
|
|
|
|
playerVars: {
|
|
|
|
autoplay: 1,
|
|
|
|
modestbranding: 1,
|
|
|
|
autohide: 1,
|
|
|
|
rel: 0,
|
|
|
|
ecver: 2,
|
2019-09-11 02:04:42 +08:00
|
|
|
controls: isPresenter ? 1 : 2,
|
2019-07-16 04:12:07 +08:00
|
|
|
},
|
2019-01-16 04:44:41 +08:00
|
|
|
},
|
2020-11-27 04:30:37 +08:00
|
|
|
peertube: {
|
|
|
|
isPresenter,
|
|
|
|
},
|
2020-06-13 02:01:15 +08:00
|
|
|
twitch: {
|
|
|
|
options: {
|
|
|
|
controls: true,
|
|
|
|
},
|
2020-06-13 02:06:58 +08:00
|
|
|
playerId: 'externalVideoPlayerTwitch',
|
2020-06-13 02:01:15 +08:00
|
|
|
},
|
2019-07-16 04:12:07 +08:00
|
|
|
preload: true,
|
2019-01-16 04:44:41 +08:00
|
|
|
};
|
|
|
|
|
2019-09-11 03:35:58 +08:00
|
|
|
this.registerVideoListeners = this.registerVideoListeners.bind(this);
|
2019-10-08 01:45:16 +08:00
|
|
|
this.autoPlayBlockDetected = this.autoPlayBlockDetected.bind(this);
|
2019-09-11 03:35:58 +08:00
|
|
|
this.clearVideoListeners = this.clearVideoListeners.bind(this);
|
2019-10-08 02:42:01 +08:00
|
|
|
this.handleFirstPlay = this.handleFirstPlay.bind(this);
|
2019-01-16 04:44:41 +08:00
|
|
|
this.handleResize = this.handleResize.bind(this);
|
|
|
|
this.handleOnReady = this.handleOnReady.bind(this);
|
2019-07-13 04:08:55 +08:00
|
|
|
this.handleOnPlay = this.handleOnPlay.bind(this);
|
|
|
|
this.handleOnPause = this.handleOnPause.bind(this);
|
2020-02-11 05:09:03 +08:00
|
|
|
this.sendSyncMessage = this.sendSyncMessage.bind(this);
|
2020-02-11 23:05:01 +08:00
|
|
|
this.getCurrentPlaybackRate = this.getCurrentPlaybackRate.bind(this);
|
2020-02-12 01:50:28 +08:00
|
|
|
this.getCurrentTime = this.getCurrentTime.bind(this);
|
2020-02-11 23:05:01 +08:00
|
|
|
this.setPlaybackRate = this.setPlaybackRate.bind(this);
|
2019-01-16 04:44:41 +08:00
|
|
|
this.resizeListener = () => {
|
|
|
|
setTimeout(this.handleResize, 0);
|
|
|
|
};
|
2020-01-11 05:38:52 +08:00
|
|
|
this.onBeforeUnload = this.onBeforeUnload.bind(this);
|
2019-01-16 04:44:41 +08:00
|
|
|
}
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-01-16 04:58:59 +08:00
|
|
|
componentDidMount() {
|
|
|
|
window.addEventListener('resize', this.resizeListener);
|
2020-08-27 20:44:41 +08:00
|
|
|
window.addEventListener('layoutSizesSets', this.resizeListener);
|
2020-01-11 05:38:52 +08:00
|
|
|
window.addEventListener('beforeunload', this.onBeforeUnload);
|
2019-07-13 04:08:55 +08:00
|
|
|
|
|
|
|
clearInterval(this.syncInterval);
|
2020-02-11 03:36:14 +08:00
|
|
|
clearTimeout(this.autoPlayTimeout);
|
|
|
|
|
|
|
|
this.clearVideoListeners();
|
2019-09-11 03:35:58 +08:00
|
|
|
this.registerVideoListeners();
|
2019-01-16 04:58:59 +08:00
|
|
|
}
|
|
|
|
|
2020-01-11 05:38:52 +08:00
|
|
|
onBeforeUnload() {
|
|
|
|
const { isPresenter } = this.props;
|
|
|
|
|
|
|
|
if (isPresenter) {
|
2020-02-11 05:09:03 +08:00
|
|
|
this.sendSyncMessage('stop');
|
2020-01-11 05:38:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 01:24:02 +08:00
|
|
|
componentWillUnmount() {
|
2019-01-16 04:44:41 +08:00
|
|
|
window.removeEventListener('resize', this.resizeListener);
|
2020-01-11 05:38:52 +08:00
|
|
|
window.removeEventListener('beforeunload', this.onBeforeUnload);
|
2020-02-11 03:36:14 +08:00
|
|
|
|
2019-09-11 03:35:58 +08:00
|
|
|
this.clearVideoListeners();
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
clearInterval(this.syncInterval);
|
2019-10-08 01:45:16 +08:00
|
|
|
clearTimeout(this.autoPlayTimeout);
|
2020-01-11 05:38:52 +08:00
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
this.player = null;
|
2019-02-28 03:59:45 +08:00
|
|
|
}
|
|
|
|
|
2019-09-13 01:15:35 +08:00
|
|
|
componentDidUpdate(prevProp, prevState) {
|
|
|
|
// Detect presenter change and redo the sync and listeners to reassign video to the new one
|
|
|
|
if (this.props.isPresenter !== prevProp.isPresenter) {
|
|
|
|
this.clearVideoListeners();
|
2020-02-11 03:36:14 +08:00
|
|
|
|
2019-09-13 01:15:35 +08:00
|
|
|
clearInterval(this.syncInterval);
|
2020-02-11 03:36:14 +08:00
|
|
|
clearTimeout(this.autoPlayTimeout);
|
|
|
|
|
2019-09-13 01:15:35 +08:00
|
|
|
this.registerVideoListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 03:36:14 +08:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
const { isPresenter } = this.props;
|
|
|
|
const { playing } = this.state;
|
|
|
|
|
|
|
|
// If user is presenter we don't re-render playing state changes
|
|
|
|
// Because he's in control of the play/pause status
|
|
|
|
if (nextProps.isPresenter && isPresenter && nextState.playing !== playing) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-11 04:15:25 +08:00
|
|
|
static getDerivedStateFromProps(props) {
|
|
|
|
const { inEchoTest } = props;
|
|
|
|
|
|
|
|
return { mutedByEchoTest: inEchoTest };
|
|
|
|
}
|
|
|
|
|
2020-02-11 05:09:03 +08:00
|
|
|
sendSyncMessage(msg, params) {
|
2020-02-28 03:42:07 +08:00
|
|
|
const timestamp = Date.now();
|
|
|
|
|
|
|
|
// If message is just a quick pause/un-pause just send nothing
|
2020-05-26 01:32:24 +08:00
|
|
|
const sinceLastMessage = (timestamp - this.lastMessageTimestamp) / 1000;
|
|
|
|
if ((msg === 'play' && this.lastMessage === 'stop'
|
|
|
|
|| msg === 'stop' && this.lastMessage === 'play')
|
|
|
|
&& sinceLastMessage < THROTTLE_INTERVAL_SECONDS) {
|
|
|
|
return clearTimeout(this.throttleTimeout);
|
2020-02-28 03:42:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore repeat presenter ready messages
|
2020-02-11 05:09:03 +08:00
|
|
|
if (this.lastMessage === msg && msg === 'presenterReady') {
|
2020-05-26 01:32:24 +08:00
|
|
|
logger.debug('Ignoring a repeated presenterReady message');
|
2020-02-11 05:09:03 +08:00
|
|
|
} else {
|
2020-02-28 03:42:07 +08:00
|
|
|
// Play/pause messages are sent with a delay, to permit cancelling it in case of
|
|
|
|
// quick sucessive play/pauses
|
|
|
|
const messageDelay = (msg === 'play' || msg === 'stop') ? THROTTLE_INTERVAL_SECONDS : 0;
|
|
|
|
|
|
|
|
this.throttleTimeout = setTimeout(() => {
|
2020-05-19 00:16:03 +08:00
|
|
|
sendMessage(msg, { ...params });
|
2020-05-26 01:32:24 +08:00
|
|
|
}, messageDelay * 1000);
|
2020-02-28 03:42:07 +08:00
|
|
|
|
2020-02-11 05:09:03 +08:00
|
|
|
this.lastMessage = msg;
|
2020-02-28 03:42:07 +08:00
|
|
|
this.lastMessageTimestamp = timestamp;
|
2020-02-11 05:09:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-08 01:45:16 +08:00
|
|
|
autoPlayBlockDetected() {
|
2019-10-24 04:29:06 +08:00
|
|
|
this.setState({ autoPlayBlocked: true });
|
2019-10-08 01:45:16 +08:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:42:01 +08:00
|
|
|
handleFirstPlay() {
|
2019-10-17 01:47:22 +08:00
|
|
|
const { isPresenter } = this.props;
|
2020-02-11 04:09:59 +08:00
|
|
|
const { hasPlayedBefore } = this;
|
2019-10-08 02:42:01 +08:00
|
|
|
|
2019-10-17 01:47:22 +08:00
|
|
|
if (!hasPlayedBefore) {
|
2020-02-11 04:09:59 +08:00
|
|
|
this.hasPlayedBefore = true;
|
|
|
|
this.setState({ autoPlayBlocked: false });
|
|
|
|
|
2019-10-08 02:42:01 +08:00
|
|
|
clearTimeout(this.autoPlayTimeout);
|
|
|
|
|
|
|
|
if (isPresenter) {
|
2020-02-11 05:09:03 +08:00
|
|
|
this.sendSyncMessage('presenterReady');
|
2019-10-08 02:42:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-12 01:50:28 +08:00
|
|
|
getCurrentTime() {
|
|
|
|
if (this.player && this.player.getCurrentTime) {
|
2020-05-18 23:11:12 +08:00
|
|
|
return Math.round(this.player.getCurrentTime());
|
2020-02-12 01:50:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 02:04:42 +08:00
|
|
|
getCurrentPlaybackRate() {
|
2020-02-12 01:50:28 +08:00
|
|
|
const intPlayer = this.player && this.player.getInternalPlayer();
|
2019-09-11 02:04:42 +08:00
|
|
|
|
|
|
|
return (intPlayer && intPlayer.getPlaybackRate && intPlayer.getPlaybackRate()) || 1;
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:05:01 +08:00
|
|
|
setPlaybackRate(rate) {
|
2020-02-12 01:50:28 +08:00
|
|
|
const intPlayer = this.player && this.player.getInternalPlayer();
|
2020-06-10 03:54:19 +08:00
|
|
|
const currentRate = this.getCurrentPlaybackRate();
|
|
|
|
|
|
|
|
if (currentRate === rate) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-11 23:05:01 +08:00
|
|
|
|
|
|
|
this.setState({ playbackRate: rate });
|
|
|
|
if (intPlayer && intPlayer.setPlaybackRate) {
|
|
|
|
intPlayer.setPlaybackRate(rate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
handleResize() {
|
2019-07-13 04:08:55 +08:00
|
|
|
if (!this.player || !this.playerParent) {
|
2018-11-30 01:24:02 +08:00
|
|
|
return;
|
2019-01-16 04:44:41 +08:00
|
|
|
}
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-07-13 04:08:55 +08:00
|
|
|
const par = this.playerParent.parentElement;
|
|
|
|
const w = par.clientWidth;
|
|
|
|
const h = par.clientHeight;
|
2019-01-16 04:44:41 +08:00
|
|
|
const idealW = h * 16 / 9;
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-09-11 02:04:42 +08:00
|
|
|
const style = {};
|
2018-11-30 01:24:02 +08:00
|
|
|
if (idealW > w) {
|
2019-07-13 04:08:55 +08:00
|
|
|
style.width = w;
|
|
|
|
style.height = w * 9 / 16;
|
2018-11-30 01:24:02 +08:00
|
|
|
} else {
|
2019-07-13 04:08:55 +08:00
|
|
|
style.width = idealW;
|
|
|
|
style.height = h;
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
2019-07-13 04:08:55 +08:00
|
|
|
|
2019-09-11 02:04:42 +08:00
|
|
|
const styleStr = `width: ${style.width}px; height: ${style.height}px;`;
|
2019-07-13 04:08:55 +08:00
|
|
|
this.player.wrapper.style = styleStr;
|
|
|
|
this.playerParent.style = styleStr;
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
|
|
|
|
2019-09-11 03:35:58 +08:00
|
|
|
clearVideoListeners() {
|
|
|
|
removeAllListeners('play');
|
|
|
|
removeAllListeners('stop');
|
|
|
|
removeAllListeners('playerUpdate');
|
2020-01-11 05:32:32 +08:00
|
|
|
removeAllListeners('presenterReady');
|
2019-09-11 03:35:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
registerVideoListeners() {
|
2019-01-16 04:44:41 +08:00
|
|
|
const { isPresenter } = this.props;
|
2018-11-30 01:24:02 +08:00
|
|
|
|
|
|
|
if (isPresenter) {
|
|
|
|
this.syncInterval = setInterval(() => {
|
2020-02-11 04:09:59 +08:00
|
|
|
const { playing } = this.state;
|
2020-02-12 01:50:28 +08:00
|
|
|
const curTime = this.getCurrentTime();
|
2019-07-17 06:04:20 +08:00
|
|
|
const rate = this.getCurrentPlaybackRate();
|
|
|
|
|
2019-10-17 00:31:37 +08:00
|
|
|
// Always pause video if presenter is has not started sharing, e.g., blocked by autoplay
|
2020-02-11 04:09:59 +08:00
|
|
|
const playingState = this.hasPlayedBefore ? playing : false;
|
2019-10-17 00:31:37 +08:00
|
|
|
|
2020-02-11 05:09:03 +08:00
|
|
|
this.sendSyncMessage('playerUpdate', { rate, time: curTime, state: playingState });
|
2019-05-30 03:06:41 +08:00
|
|
|
}, SYNC_INTERVAL_SECONDS * 1000);
|
2018-11-30 01:24:02 +08:00
|
|
|
} else {
|
2020-05-19 00:16:03 +08:00
|
|
|
onMessage('play', ({ time }) => {
|
2020-02-11 04:09:59 +08:00
|
|
|
const { hasPlayedBefore, player } = this;
|
2019-10-17 01:47:22 +08:00
|
|
|
|
2020-02-11 04:09:59 +08:00
|
|
|
if (!player || !hasPlayedBefore) {
|
2019-07-13 04:08:55 +08:00
|
|
|
return;
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
2020-05-19 00:16:03 +08:00
|
|
|
this.seekTo(time);
|
2019-09-11 02:04:42 +08:00
|
|
|
this.setState({ playing: true });
|
2019-07-13 04:08:55 +08:00
|
|
|
|
2019-05-30 23:02:51 +08:00
|
|
|
logger.debug({ logCode: 'external_video_client_play' }, 'Play external video');
|
2018-11-30 01:24:02 +08:00
|
|
|
});
|
|
|
|
|
2020-05-19 00:16:03 +08:00
|
|
|
onMessage('stop', ({ time }) => {
|
2020-02-11 04:09:59 +08:00
|
|
|
const { hasPlayedBefore, player } = this;
|
2019-10-17 01:47:22 +08:00
|
|
|
|
2020-02-11 04:09:59 +08:00
|
|
|
if (!player || !hasPlayedBefore) {
|
2019-07-13 04:08:55 +08:00
|
|
|
return;
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
2020-05-19 00:16:03 +08:00
|
|
|
this.seekTo(time);
|
2019-09-11 02:04:42 +08:00
|
|
|
this.setState({ playing: false });
|
2019-07-13 04:08:55 +08:00
|
|
|
|
2019-05-30 23:02:51 +08:00
|
|
|
logger.debug({ logCode: 'external_video_client_stop' }, 'Stop external video');
|
2018-11-30 01:24:02 +08:00
|
|
|
});
|
|
|
|
|
2019-10-08 02:42:01 +08:00
|
|
|
onMessage('presenterReady', (data) => {
|
2020-02-11 04:09:59 +08:00
|
|
|
const { hasPlayedBefore } = this;
|
2019-10-17 01:47:22 +08:00
|
|
|
|
2019-10-08 02:42:01 +08:00
|
|
|
logger.debug({ logCode: 'external_video_presenter_ready' }, 'Presenter is ready to sync');
|
|
|
|
|
2019-10-17 01:47:22 +08:00
|
|
|
if (!hasPlayedBefore) {
|
2019-10-24 04:29:06 +08:00
|
|
|
this.setState({ playing: true });
|
2019-10-08 02:42:01 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-01-16 04:44:41 +08:00
|
|
|
onMessage('playerUpdate', (data) => {
|
2020-02-11 04:09:59 +08:00
|
|
|
const { hasPlayedBefore, player } = this;
|
|
|
|
const { playing } = this.state;
|
2020-05-19 00:16:03 +08:00
|
|
|
const { time, rate, state } = data;
|
2019-10-17 01:47:22 +08:00
|
|
|
|
2020-02-11 04:09:59 +08:00
|
|
|
if (!player || !hasPlayedBefore) {
|
2018-11-30 01:24:02 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-27 05:57:16 +08:00
|
|
|
if (rate !== this.getCurrentPlaybackRate()) {
|
|
|
|
this.setPlaybackRate(rate);
|
2019-06-29 05:45:50 +08:00
|
|
|
logger.debug({
|
|
|
|
logCode: 'external_video_client_update_rate',
|
|
|
|
extraInfo: {
|
2020-02-27 05:57:16 +08:00
|
|
|
newRate: rate,
|
2019-06-29 05:45:50 +08:00
|
|
|
},
|
2019-07-03 00:54:10 +08:00
|
|
|
}, 'Change external video playback rate.');
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
|
|
|
|
2020-05-19 00:16:03 +08:00
|
|
|
this.seekTo(time);
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2020-02-27 05:57:16 +08:00
|
|
|
if (playing !== state) {
|
|
|
|
this.setState({ playing: state });
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 00:16:03 +08:00
|
|
|
seekTo(time) {
|
2020-02-27 05:57:16 +08:00
|
|
|
const { player } = this;
|
|
|
|
|
|
|
|
if (!player) {
|
2020-05-26 01:32:24 +08:00
|
|
|
return logger.error('No player on seek');
|
2020-02-27 05:57:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-28 02:01:04 +08:00
|
|
|
// Seek if viewer has drifted too far away from presenter
|
2020-05-26 01:32:24 +08:00
|
|
|
if (Math.abs(this.getCurrentTime() - time) > SYNC_INTERVAL_SECONDS * 0.75) {
|
2020-05-19 00:16:03 +08:00
|
|
|
player.seekTo(time, true);
|
2020-02-27 05:57:16 +08:00
|
|
|
logger.debug({
|
|
|
|
logCode: 'external_video_client_update_seek',
|
2020-05-26 01:32:24 +08:00
|
|
|
extraInfo: { time },
|
2020-03-03 04:51:51 +08:00
|
|
|
}, `Seek external video to: ${time}`);
|
2020-02-27 05:57:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 02:04:42 +08:00
|
|
|
handleOnReady() {
|
2020-02-11 04:09:59 +08:00
|
|
|
const { hasPlayedBefore, playerIsReady } = this;
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2020-01-11 05:32:32 +08:00
|
|
|
if (hasPlayedBefore || playerIsReady) {
|
2019-10-11 05:56:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-11 04:09:59 +08:00
|
|
|
this.playerIsReady = true;
|
2020-01-11 05:32:32 +08:00
|
|
|
|
2018-11-30 01:24:02 +08:00
|
|
|
this.handleResize();
|
2019-10-08 01:45:16 +08:00
|
|
|
|
|
|
|
this.autoPlayTimeout = setTimeout(this.autoPlayBlockDetected, AUTO_PLAY_BLOCK_DETECTION_TIMEOUT_SECONDS * 1000);
|
2019-01-16 04:44:41 +08:00
|
|
|
}
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-07-13 04:08:55 +08:00
|
|
|
handleOnPlay() {
|
2019-01-16 04:44:41 +08:00
|
|
|
const { isPresenter } = this.props;
|
2020-02-11 03:36:14 +08:00
|
|
|
const { playing } = this.state;
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2020-02-12 01:50:28 +08:00
|
|
|
const curTime = this.getCurrentTime();
|
2020-02-11 03:36:14 +08:00
|
|
|
|
|
|
|
if (isPresenter && !playing) {
|
2020-02-11 05:09:03 +08:00
|
|
|
this.sendSyncMessage('play', { time: curTime });
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
2019-09-11 02:04:42 +08:00
|
|
|
this.setState({ playing: true });
|
2019-10-08 01:45:16 +08:00
|
|
|
|
2019-10-08 02:42:01 +08:00
|
|
|
this.handleFirstPlay();
|
2021-04-08 02:59:24 +08:00
|
|
|
|
|
|
|
if (!isPresenter && !playing) {
|
|
|
|
this.setState({ playing: false });
|
|
|
|
}
|
2019-07-13 04:08:55 +08:00
|
|
|
}
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2019-07-13 04:08:55 +08:00
|
|
|
handleOnPause() {
|
|
|
|
const { isPresenter } = this.props;
|
2020-02-11 03:36:14 +08:00
|
|
|
const { playing } = this.state;
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2020-02-12 01:50:28 +08:00
|
|
|
const curTime = this.getCurrentTime();
|
2020-02-11 03:36:14 +08:00
|
|
|
|
|
|
|
if (isPresenter && playing) {
|
2020-02-11 05:09:03 +08:00
|
|
|
this.sendSyncMessage('stop', { time: curTime });
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
2019-09-11 02:04:42 +08:00
|
|
|
this.setState({ playing: false });
|
2019-10-08 01:45:16 +08:00
|
|
|
|
2019-10-08 02:42:01 +08:00
|
|
|
this.handleFirstPlay();
|
2021-04-08 02:59:24 +08:00
|
|
|
|
|
|
|
if (!isPresenter && playing) {
|
|
|
|
this.setState({ playing: true });
|
|
|
|
}
|
2018-12-11 07:07:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-18 01:12:32 +08:00
|
|
|
render() {
|
2019-10-08 01:45:16 +08:00
|
|
|
const { videoUrl, intl } = this.props;
|
2019-10-24 04:29:06 +08:00
|
|
|
const {
|
|
|
|
playing, playbackRate, mutedByEchoTest, autoPlayBlocked,
|
|
|
|
} = this.state;
|
2019-01-16 04:44:41 +08:00
|
|
|
|
2018-11-30 01:24:02 +08:00
|
|
|
return (
|
|
|
|
<div
|
2019-07-13 04:08:55 +08:00
|
|
|
id="video-player"
|
2018-11-30 01:24:02 +08:00
|
|
|
data-test="videoPlayer"
|
2019-07-13 04:08:55 +08:00
|
|
|
ref={(ref) => { this.playerParent = ref; }}
|
2018-11-30 01:24:02 +08:00
|
|
|
>
|
2019-10-24 04:29:06 +08:00
|
|
|
{autoPlayBlocked
|
|
|
|
? (
|
|
|
|
<p className={styles.autoPlayWarning}>
|
|
|
|
{intl.formatMessage(intlMessages.autoPlayWarning)}
|
|
|
|
</p>
|
|
|
|
)
|
2019-10-08 01:45:16 +08:00
|
|
|
: ''
|
|
|
|
}
|
2019-07-13 04:08:55 +08:00
|
|
|
<ReactPlayer
|
2019-07-17 04:56:07 +08:00
|
|
|
className={styles.videoPlayer}
|
2019-07-13 04:08:55 +08:00
|
|
|
url={videoUrl}
|
2019-07-16 04:12:07 +08:00
|
|
|
config={this.opts}
|
2019-07-13 04:08:55 +08:00
|
|
|
muted={mutedByEchoTest}
|
|
|
|
playing={playing}
|
2019-07-17 06:04:20 +08:00
|
|
|
playbackRate={playbackRate}
|
2019-07-13 04:08:55 +08:00
|
|
|
onReady={this.handleOnReady}
|
|
|
|
onPlay={this.handleOnPlay}
|
|
|
|
onPause={this.handleOnPause}
|
|
|
|
ref={(ref) => { this.player = ref; }}
|
2019-01-16 04:44:41 +08:00
|
|
|
/>
|
2018-11-30 01:24:02 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-08 01:45:16 +08:00
|
|
|
export default injectIntl(injectWbResizeEvent(VideoPlayer));
|