2019-01-16 04:44:41 +08:00
|
|
|
import React, { Component } from 'react';
|
2021-10-29 04:08:47 +08:00
|
|
|
import PropTypes from 'prop-types';
|
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';
|
2021-08-06 04:19:27 +08:00
|
|
|
import {
|
|
|
|
sendMessage,
|
|
|
|
onMessage,
|
|
|
|
removeAllListeners,
|
|
|
|
getPlayingState,
|
|
|
|
} from './service';
|
2021-12-15 00:51:12 +08:00
|
|
|
import deviceInfo from '/imports/utils/deviceInfo';
|
2021-08-06 04:19:27 +08:00
|
|
|
|
2019-05-30 03:06:41 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2022-04-26 04:13:48 +08:00
|
|
|
import Subtitles from './subtitles/component';
|
2021-02-23 01:33:00 +08:00
|
|
|
import VolumeSlider from './volume-slider/component';
|
2021-08-06 04:40:30 +08:00
|
|
|
import ReloadButton from '/imports/ui/components/reload-button/component';
|
2022-02-15 22:42:02 +08:00
|
|
|
import FullscreenButtonContainer from '/imports/ui/components/common/fullscreen-button/container';
|
2021-02-23 01:33:00 +08:00
|
|
|
|
2021-08-09 22:24:02 +08:00
|
|
|
import ArcPlayer from '/imports/ui/components/external-video-player/custom-players/arc-player';
|
|
|
|
import PeerTubePlayer from '/imports/ui/components/external-video-player/custom-players/peertube';
|
2021-09-28 03:57:02 +08:00
|
|
|
import { ACTIONS } from '/imports/ui/components/layout/enums';
|
2023-02-23 22:23:51 +08:00
|
|
|
import { uniqueId } from '/imports/utils/string-utils';
|
2023-03-01 21:39:04 +08:00
|
|
|
import { throttle } from 'radash';
|
2019-07-27 04:59:14 +08:00
|
|
|
|
2021-11-04 00:37:17 +08:00
|
|
|
import Styled from './styles';
|
2019-07-17 04:56:07 +08:00
|
|
|
|
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',
|
|
|
|
},
|
2021-03-17 03:18:21 +08:00
|
|
|
refreshLabel: {
|
|
|
|
id: 'app.externalVideo.refreshLabel',
|
|
|
|
},
|
2021-10-29 04:08:47 +08:00
|
|
|
fullscreenLabel: {
|
|
|
|
id: 'app.externalVideo.fullscreenLabel',
|
|
|
|
},
|
2022-04-26 04:13:48 +08:00
|
|
|
subtitlesOn: {
|
|
|
|
id: 'app.externalVideo.subtitlesOn',
|
|
|
|
},
|
|
|
|
subtitlesOff: {
|
|
|
|
id: 'app.externalVideo.subtitlesOff',
|
|
|
|
},
|
2019-10-08 01:45:16 +08:00
|
|
|
});
|
|
|
|
|
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;
|
2021-10-29 04:08:47 +08:00
|
|
|
const ALLOW_FULLSCREEN = Meteor.settings.public.app.allowFullscreen;
|
2023-03-01 21:39:04 +08:00
|
|
|
const THROTTLE_RELOAD_INTERVAL = 5000;
|
2019-05-30 03:06:41 +08:00
|
|
|
|
2021-11-04 00:37:17 +08:00
|
|
|
Styled.VideoPlayer.addCustomPlayer(PeerTubePlayer);
|
|
|
|
Styled.VideoPlayer.addCustomPlayer(ArcPlayer);
|
2019-07-27 04:59:14 +08:00
|
|
|
|
2018-11-30 01:24:02 +08:00
|
|
|
class VideoPlayer extends Component {
|
2021-08-06 04:19:27 +08:00
|
|
|
static clearVideoListeners() {
|
|
|
|
removeAllListeners('play');
|
|
|
|
removeAllListeners('stop');
|
|
|
|
removeAllListeners('playerUpdate');
|
|
|
|
removeAllListeners('presenterReady');
|
|
|
|
}
|
|
|
|
|
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 = {
|
2022-04-26 04:13:48 +08:00
|
|
|
subtitlesOn: false,
|
2021-02-23 01:33:00 +08:00
|
|
|
muted: false,
|
2019-07-16 04:12:07 +08:00
|
|
|
playing: false,
|
2019-10-08 01:45:16 +08:00
|
|
|
autoPlayBlocked: false,
|
2021-02-23 01:33:00 +08:00
|
|
|
volume: 1,
|
2019-07-17 06:04:20 +08:00
|
|
|
playbackRate: 1,
|
2021-03-17 00:56:12 +08:00
|
|
|
key: 0,
|
2022-03-16 04:01:21 +08:00
|
|
|
played:0,
|
|
|
|
loaded:0,
|
2019-02-28 03:59:45 +08:00
|
|
|
};
|
|
|
|
|
2021-09-29 04:15:58 +08:00
|
|
|
this.hideVolume = {
|
|
|
|
Vimeo: true,
|
|
|
|
Facebook: true,
|
|
|
|
ArcPlayer: true,
|
2022-04-26 04:13:48 +08:00
|
|
|
//YouTube: true,
|
2021-09-29 04:15:58 +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,
|
2021-02-23 01:33:00 +08:00
|
|
|
controls: isPresenter,
|
2020-06-10 03:41:51 +08:00
|
|
|
},
|
2019-10-09 22:52:26 +08:00
|
|
|
file: {
|
|
|
|
attributes: {
|
2021-02-23 01:33:00 +08:00
|
|
|
controls: isPresenter ? 'controls' : '',
|
2020-07-01 03:56:15 +08:00
|
|
|
autoplay: 'autoplay',
|
|
|
|
playsinline: 'playsinline',
|
2019-10-09 22:52:26 +08:00
|
|
|
},
|
|
|
|
},
|
2021-09-29 04:15:58 +08:00
|
|
|
facebook: {
|
|
|
|
controls: isPresenter,
|
|
|
|
},
|
2019-10-09 22:52:26 +08:00
|
|
|
dailymotion: {
|
|
|
|
params: {
|
2021-02-23 01:33:00 +08:00
|
|
|
controls: isPresenter,
|
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,
|
2021-02-23 01:33:00 +08:00
|
|
|
controls: isPresenter ? 1 : 0,
|
2022-04-26 04:13:48 +08:00
|
|
|
cc_lang_pref: document.getElementsByTagName('html')[0].lang.substring(0, 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: {
|
2021-02-23 01:33:00 +08:00
|
|
|
controls: isPresenter,
|
2020-06-13 02:01:15 +08:00
|
|
|
},
|
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,
|
2021-08-06 04:19:27 +08:00
|
|
|
showHoverToolBar: false,
|
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-10-08 02:42:01 +08:00
|
|
|
this.handleFirstPlay = this.handleFirstPlay.bind(this);
|
2023-03-01 21:39:04 +08:00
|
|
|
this.handleReload = throttle({ interval: THROTTLE_RELOAD_INTERVAL }, this.handleReload.bind(this));
|
2021-02-23 01:33:00 +08:00
|
|
|
this.handleOnProgress = this.handleOnProgress.bind(this);
|
2019-01-16 04:44:41 +08:00
|
|
|
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);
|
2021-02-23 01:33:00 +08:00
|
|
|
this.handleVolumeChanged = this.handleVolumeChanged.bind(this);
|
|
|
|
this.handleOnMuted = this.handleOnMuted.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);
|
2021-02-23 01:33:00 +08:00
|
|
|
this.getCurrentVolume = this.getCurrentVolume.bind(this);
|
|
|
|
this.getMuted = this.getMuted.bind(this);
|
2020-02-11 23:05:01 +08:00
|
|
|
this.setPlaybackRate = this.setPlaybackRate.bind(this);
|
2020-01-11 05:38:52 +08:00
|
|
|
this.onBeforeUnload = this.onBeforeUnload.bind(this);
|
2022-04-26 04:13:48 +08:00
|
|
|
this.toggleSubtitle = this.toggleSubtitle.bind(this);
|
2021-08-06 04:19:27 +08:00
|
|
|
|
|
|
|
this.mobileHoverSetTimeout = null;
|
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() {
|
2021-08-10 03:06:31 +08:00
|
|
|
const {
|
|
|
|
layoutContextDispatch,
|
|
|
|
} = this.props;
|
|
|
|
|
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);
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
VideoPlayer.clearVideoListeners();
|
2019-09-11 03:35:58 +08:00
|
|
|
this.registerVideoListeners();
|
2021-08-10 03:06:31 +08:00
|
|
|
|
2022-02-08 03:29:27 +08:00
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_HAS_EXTERNAL_VIDEO,
|
|
|
|
value: true,
|
|
|
|
});
|
2022-02-26 01:56:03 +08:00
|
|
|
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_PRESENTATION_IS_OPEN,
|
|
|
|
value: true,
|
|
|
|
});
|
2019-01-16 04:58:59 +08:00
|
|
|
}
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2020-01-11 05:38:52 +08:00
|
|
|
const { isPresenter } = this.props;
|
2021-08-06 04:19:27 +08:00
|
|
|
const { playing } = this.state;
|
2020-01-11 05:38:52 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProp) {
|
|
|
|
// Detect presenter change and redo the sync and listeners to reassign video to the new one
|
|
|
|
const { isPresenter } = this.props;
|
|
|
|
if (isPresenter !== prevProp.isPresenter) {
|
|
|
|
VideoPlayer.clearVideoListeners();
|
|
|
|
|
|
|
|
clearInterval(this.syncInterval);
|
|
|
|
clearTimeout(this.autoPlayTimeout);
|
|
|
|
|
|
|
|
this.registerVideoListeners();
|
2020-01-11 05:38:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 01:24:02 +08:00
|
|
|
componentWillUnmount() {
|
2021-11-04 00:37:17 +08:00
|
|
|
const {
|
|
|
|
layoutContextDispatch,
|
2023-02-18 01:59:39 +08:00
|
|
|
hidePresentationOnJoin,
|
2021-11-04 00:37:17 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2020-01-11 05:38:52 +08:00
|
|
|
window.removeEventListener('beforeunload', this.onBeforeUnload);
|
2020-02-11 03:36:14 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
VideoPlayer.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;
|
2021-09-28 03:57:02 +08:00
|
|
|
|
2022-02-08 03:29:27 +08:00
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_HAS_EXTERNAL_VIDEO,
|
|
|
|
value: false,
|
|
|
|
});
|
2023-04-11 03:25:19 +08:00
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_PRESENTATION_IS_OPEN,
|
|
|
|
value: Session.get('presentationLastState'),
|
|
|
|
});
|
2022-02-08 03:29:27 +08:00
|
|
|
|
2023-02-18 01:59:39 +08:00
|
|
|
if (hidePresentationOnJoin) {
|
2021-09-28 03:57:02 +08:00
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_PRESENTATION_IS_OPEN,
|
|
|
|
value: false,
|
|
|
|
});
|
|
|
|
}
|
2019-02-28 03:59:45 +08:00
|
|
|
}
|
|
|
|
|
2022-04-26 04:13:48 +08:00
|
|
|
toggleSubtitle() {
|
|
|
|
this.setState((state) => {
|
|
|
|
return { subtitlesOn: !state.subtitlesOn };
|
|
|
|
}, () => {
|
|
|
|
const { subtitlesOn } = this.state;
|
|
|
|
const { isPresenter } = this.props;
|
2024-05-01 01:49:41 +08:00
|
|
|
const internalPlayer = this?.player?.getInternalPlayer();
|
|
|
|
if (!internalPlayer) return;
|
2022-04-26 04:13:48 +08:00
|
|
|
if (!isPresenter && subtitlesOn) {
|
2024-05-01 01:49:41 +08:00
|
|
|
if (typeof internalPlayer.setOption === 'function') {
|
|
|
|
internalPlayer.setOption('captions', 'reload', true);
|
|
|
|
}
|
|
|
|
} else if (typeof internalPlayer.unloadModule === 'function') {
|
|
|
|
internalPlayer.unloadModule('captions');
|
2022-04-26 04:13:48 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
handleOnReady() {
|
|
|
|
const { hasPlayedBefore, playerIsReady } = this;
|
2021-07-28 21:21:20 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
if (hasPlayedBefore || playerIsReady) {
|
|
|
|
return;
|
2021-07-28 21:21:20 +08:00
|
|
|
}
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
this.playerIsReady = true;
|
|
|
|
|
|
|
|
this.autoPlayTimeout = setTimeout(
|
|
|
|
this.autoPlayBlockDetected,
|
|
|
|
AUTO_PLAY_BLOCK_DETECTION_TIMEOUT_SECONDS * 1000,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleFirstPlay() {
|
|
|
|
const { isPresenter } = this.props;
|
|
|
|
const { hasPlayedBefore } = this;
|
|
|
|
|
|
|
|
if (!hasPlayedBefore) {
|
|
|
|
this.hasPlayedBefore = true;
|
|
|
|
this.setState({ autoPlayBlocked: false });
|
2020-02-11 03:36:14 +08:00
|
|
|
|
|
|
|
clearTimeout(this.autoPlayTimeout);
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
if (isPresenter) {
|
|
|
|
this.sendSyncMessage('presenterReady');
|
|
|
|
}
|
2019-09-13 01:15:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
handleOnPlay() {
|
2020-02-11 03:36:14 +08:00
|
|
|
const { isPresenter } = this.props;
|
|
|
|
const { playing } = this.state;
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
const curTime = this.getCurrentTime();
|
|
|
|
|
|
|
|
if (isPresenter && !playing) {
|
|
|
|
this.sendSyncMessage('play', { time: curTime });
|
2020-02-11 03:36:14 +08:00
|
|
|
}
|
2021-08-06 04:19:27 +08:00
|
|
|
this.setState({ playing: true });
|
2020-02-11 03:36:14 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
this.handleFirstPlay();
|
|
|
|
|
|
|
|
if (!isPresenter && !playing) {
|
|
|
|
this.setState({ playing: false });
|
|
|
|
}
|
2020-02-11 03:36:14 +08:00
|
|
|
}
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
handleOnPause() {
|
|
|
|
const { isPresenter } = this.props;
|
|
|
|
const { playing } = this.state;
|
2019-09-11 04:15:25 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
const curTime = this.getCurrentTime();
|
2019-09-11 04:15:25 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
if (isPresenter && playing) {
|
|
|
|
this.sendSyncMessage('stop', { time: curTime });
|
|
|
|
}
|
|
|
|
this.setState({ playing: false });
|
2020-02-28 03:42:07 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
this.handleFirstPlay();
|
|
|
|
|
|
|
|
if (!isPresenter && playing) {
|
|
|
|
this.setState({ playing: true });
|
2020-02-28 03:42:07 +08:00
|
|
|
}
|
2021-08-06 04:19:27 +08:00
|
|
|
}
|
2020-02-28 03:42:07 +08:00
|
|
|
|
2022-03-16 04:01:21 +08:00
|
|
|
handleOnProgress(data) {
|
2022-02-10 02:22:45 +08:00
|
|
|
const { mutedByEchoTest } = this.state;
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
const volume = this.getCurrentVolume();
|
|
|
|
const muted = this.getMuted();
|
2020-02-28 03:42:07 +08:00
|
|
|
|
2022-03-16 04:01:21 +08:00
|
|
|
const { played, loaded } = data;
|
|
|
|
|
|
|
|
this.setState({played, loaded});
|
|
|
|
|
2022-02-10 02:22:45 +08:00
|
|
|
if (!mutedByEchoTest) {
|
|
|
|
this.setState({ volume, muted });
|
|
|
|
}
|
2021-08-06 04:19:27 +08:00
|
|
|
}
|
2020-02-28 03:42:07 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
handleVolumeChanged(volume) {
|
|
|
|
this.setState({ volume });
|
2020-02-11 05:09:03 +08:00
|
|
|
}
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
handleOnMuted(muted) {
|
2022-02-08 21:24:42 +08:00
|
|
|
const { mutedByEchoTest } = this.state;
|
|
|
|
|
|
|
|
if (!mutedByEchoTest) {
|
|
|
|
this.setState({ muted });
|
|
|
|
}
|
2019-10-08 01:45:16 +08:00
|
|
|
}
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
handleReload() {
|
|
|
|
const { key } = this.state;
|
|
|
|
// increment key and force a re-render of the video component
|
|
|
|
this.setState({ key: key + 1 });
|
|
|
|
}
|
2020-02-11 04:09:59 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
onBeforeUnload() {
|
|
|
|
const { isPresenter } = this.props;
|
2019-10-08 02:42:01 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
if (isPresenter) {
|
|
|
|
this.sendSyncMessage('stop');
|
2019-10-08 02:42:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
static getDerivedStateFromProps(props) {
|
|
|
|
const { inEchoTest } = props;
|
|
|
|
|
|
|
|
return { mutedByEchoTest: inEchoTest };
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2021-08-06 04:19:27 +08:00
|
|
|
return 0;
|
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();
|
2021-09-30 03:45:01 +08:00
|
|
|
const rate = (intPlayer && intPlayer.getPlaybackRate && intPlayer.getPlaybackRate());
|
2019-09-11 02:04:42 +08:00
|
|
|
|
2021-11-04 00:37:17 +08:00
|
|
|
return typeof (rate) === 'number' ? rate : 1;
|
2019-09-11 02:04:42 +08:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
getCurrentVolume() {
|
|
|
|
const { volume } = this.state;
|
|
|
|
const intPlayer = this.player && this.player.getInternalPlayer();
|
2021-06-17 00:05:42 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
return (intPlayer && intPlayer.getVolume && intPlayer.getVolume() / 100.0) || volume;
|
|
|
|
}
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
getMuted() {
|
2022-10-06 22:45:52 +08:00
|
|
|
const { isPresenter } = this.props;
|
|
|
|
const { muted } = this.state;
|
|
|
|
const intPlayer = this?.player?.getInternalPlayer?.();
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2022-10-06 22:45:52 +08:00
|
|
|
return isPresenter ? intPlayer?.isMuted?.() : muted;
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
autoPlayBlockDetected() {
|
|
|
|
this.setState({ autoPlayBlocked: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
sendSyncMessage(msg, params) {
|
|
|
|
const timestamp = Date.now();
|
|
|
|
|
|
|
|
// If message is just a quick pause/un-pause just send nothing
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore repeat presenter ready messages
|
|
|
|
if (this.lastMessage === msg && msg === 'presenterReady') {
|
|
|
|
logger.debug('Ignoring a repeated presenterReady message');
|
|
|
|
} else {
|
|
|
|
// 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(() => {
|
|
|
|
sendMessage(msg, { ...params });
|
|
|
|
}, messageDelay * 1000);
|
|
|
|
|
|
|
|
this.lastMessage = msg;
|
|
|
|
this.lastMessageTimestamp = timestamp;
|
|
|
|
}
|
2021-08-09 22:24:02 +08:00
|
|
|
return true;
|
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
|
|
|
});
|
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
onMessage('presenterReady', () => {
|
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
|
|
|
|
2021-08-06 04:19:27 +08:00
|
|
|
const playingState = getPlayingState(state);
|
2021-06-03 02:07:03 +08:00
|
|
|
if (playing !== playingState) {
|
|
|
|
this.setState({ playing: playingState });
|
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
|
|
|
}
|
2021-08-09 22:24:02 +08:00
|
|
|
return true;
|
2020-02-27 05:57:16 +08:00
|
|
|
}
|
|
|
|
|
2021-10-29 04:08:47 +08:00
|
|
|
renderFullscreenButton() {
|
|
|
|
const { intl, fullscreenElementId, fullscreenContext } = this.props;
|
|
|
|
|
|
|
|
if (!ALLOW_FULLSCREEN) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FullscreenButtonContainer
|
2023-02-23 22:23:51 +08:00
|
|
|
key={uniqueId('fullscreenButton-')}
|
2021-10-29 04:08:47 +08:00
|
|
|
elementName={intl.formatMessage(intlMessages.fullscreenLabel)}
|
|
|
|
fullscreenRef={this.playerParent}
|
|
|
|
elementId={fullscreenElementId}
|
|
|
|
isFullscreen={fullscreenContext}
|
|
|
|
dark
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-18 01:12:32 +08:00
|
|
|
render() {
|
2021-08-06 04:19:27 +08:00
|
|
|
const {
|
|
|
|
videoUrl,
|
|
|
|
isPresenter,
|
|
|
|
intl,
|
|
|
|
top,
|
|
|
|
left,
|
2021-08-11 00:45:06 +08:00
|
|
|
right,
|
2021-08-06 04:19:27 +08:00
|
|
|
height,
|
|
|
|
width,
|
2021-10-29 04:08:47 +08:00
|
|
|
fullscreenContext,
|
2021-08-13 21:47:19 +08:00
|
|
|
isResizing,
|
2024-07-09 19:38:56 +08:00
|
|
|
zIndex,
|
2021-08-06 04:19:27 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2019-10-24 04:29:06 +08:00
|
|
|
const {
|
|
|
|
playing, playbackRate, mutedByEchoTest, autoPlayBlocked,
|
2022-04-26 04:13:48 +08:00
|
|
|
volume, muted, key, showHoverToolBar, played, loaded, subtitlesOn
|
2019-10-24 04:29:06 +08:00
|
|
|
} = this.state;
|
2019-01-16 04:44:41 +08:00
|
|
|
|
2021-09-29 04:15:58 +08:00
|
|
|
// This looks weird, but I need to get this nested player
|
|
|
|
const playerName = this.player && this.player.player
|
|
|
|
&& this.player.player.player && this.player.player.player.constructor.name;
|
|
|
|
|
2021-11-04 00:37:17 +08:00
|
|
|
let toolbarStyle = 'hoverToolbar';
|
|
|
|
|
2022-01-13 00:40:45 +08:00
|
|
|
if (deviceInfo.isMobile && !showHoverToolBar) {
|
2021-11-04 00:37:17 +08:00
|
|
|
toolbarStyle = 'dontShowMobileHoverToolbar';
|
|
|
|
}
|
|
|
|
|
2022-01-13 00:40:45 +08:00
|
|
|
if (deviceInfo.isMobile && showHoverToolBar) {
|
2021-11-04 00:37:17 +08:00
|
|
|
toolbarStyle = 'showMobileHoverToolbar';
|
|
|
|
}
|
2021-12-10 02:05:08 +08:00
|
|
|
const isMinimized = width === 0 && height === 0;
|
2021-08-06 04:19:27 +08:00
|
|
|
|
2018-11-30 01:24:02 +08:00
|
|
|
return (
|
2021-08-06 04:19:27 +08:00
|
|
|
<span
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
top,
|
|
|
|
left,
|
2021-08-11 00:45:06 +08:00
|
|
|
right,
|
2021-08-06 04:19:27 +08:00
|
|
|
height,
|
|
|
|
width,
|
2021-08-13 21:47:19 +08:00
|
|
|
pointerEvents: isResizing ? 'none' : 'inherit',
|
2021-12-10 02:05:08 +08:00
|
|
|
display: isMinimized && 'none',
|
2022-04-21 21:01:58 +08:00
|
|
|
background: 'var(--color-black)',
|
2024-07-09 19:38:56 +08:00
|
|
|
overflow: 'hidden',
|
|
|
|
zIndex,
|
2021-08-06 04:19:27 +08:00
|
|
|
}}
|
2018-11-30 01:24:02 +08:00
|
|
|
>
|
2021-11-04 00:37:17 +08:00
|
|
|
<Styled.VideoPlayerWrapper
|
2021-08-06 04:19:27 +08:00
|
|
|
id="video-player"
|
|
|
|
data-test="videoPlayer"
|
2021-12-10 22:55:37 +08:00
|
|
|
fullscreen={fullscreenContext}
|
2021-08-06 04:19:27 +08:00
|
|
|
ref={(ref) => { this.playerParent = ref; }}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
autoPlayBlocked
|
|
|
|
? (
|
2021-11-04 00:37:17 +08:00
|
|
|
<Styled.AutoPlayWarning>
|
2021-08-06 04:19:27 +08:00
|
|
|
{intl.formatMessage(intlMessages.autoPlayWarning)}
|
2021-11-04 00:37:17 +08:00
|
|
|
</Styled.AutoPlayWarning>
|
2021-08-06 04:19:27 +08:00
|
|
|
)
|
|
|
|
: ''
|
|
|
|
}
|
|
|
|
|
2021-11-04 00:37:17 +08:00
|
|
|
<Styled.VideoPlayer
|
2021-08-06 04:19:27 +08:00
|
|
|
url={videoUrl}
|
|
|
|
config={this.opts}
|
|
|
|
volume={(muted || mutedByEchoTest) ? 0 : volume}
|
|
|
|
muted={muted || mutedByEchoTest}
|
|
|
|
playing={playing}
|
|
|
|
playbackRate={playbackRate}
|
|
|
|
onProgress={this.handleOnProgress}
|
|
|
|
onReady={this.handleOnReady}
|
|
|
|
onPlay={this.handleOnPlay}
|
|
|
|
onPause={this.handleOnPause}
|
2021-09-29 04:15:58 +08:00
|
|
|
controls={isPresenter}
|
2021-08-06 04:19:27 +08:00
|
|
|
key={`react-player${key}`}
|
|
|
|
ref={(ref) => { this.player = ref; }}
|
|
|
|
height="100%"
|
|
|
|
width="100%"
|
|
|
|
/>
|
|
|
|
{
|
|
|
|
!isPresenter
|
|
|
|
? [
|
|
|
|
(
|
2022-04-09 04:30:21 +08:00
|
|
|
<Styled.HoverToolbar key="hover-toolbar-external-video">
|
2021-08-06 04:19:27 +08:00
|
|
|
<VolumeSlider
|
2021-09-29 04:15:58 +08:00
|
|
|
hideVolume={this.hideVolume[playerName]}
|
2021-08-06 04:19:27 +08:00
|
|
|
volume={volume}
|
|
|
|
muted={muted || mutedByEchoTest}
|
|
|
|
onMuted={this.handleOnMuted}
|
|
|
|
onVolumeChanged={this.handleVolumeChanged}
|
|
|
|
/>
|
2022-04-26 04:13:48 +08:00
|
|
|
<Styled.ButtonsWrapper>
|
|
|
|
<ReloadButton
|
|
|
|
handleReload={this.handleReload}
|
|
|
|
label={intl.formatMessage(intlMessages.refreshLabel)}
|
|
|
|
/>
|
|
|
|
{playerName === 'YouTube' && (
|
|
|
|
<Subtitles
|
|
|
|
toggleSubtitle={this.toggleSubtitle}
|
|
|
|
label={subtitlesOn
|
|
|
|
? intl.formatMessage(intlMessages.subtitlesOn)
|
|
|
|
: intl.formatMessage(intlMessages.subtitlesOff)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Styled.ButtonsWrapper>
|
2021-10-29 04:08:47 +08:00
|
|
|
{this.renderFullscreenButton()}
|
2022-04-09 02:39:05 +08:00
|
|
|
|
2022-05-07 01:30:41 +08:00
|
|
|
<Styled.ProgressBar>
|
|
|
|
<Styled.Loaded
|
2022-04-09 02:39:05 +08:00
|
|
|
style={{ width: loaded * 100 + '%' }}
|
|
|
|
>
|
2022-05-07 01:30:41 +08:00
|
|
|
<Styled.Played
|
2022-04-09 02:39:05 +08:00
|
|
|
style={{ width: played * 100 / loaded + '%'}}
|
2022-04-28 21:01:02 +08:00
|
|
|
/>
|
2022-05-07 01:30:41 +08:00
|
|
|
</Styled.Loaded>
|
|
|
|
</Styled.ProgressBar>
|
2021-12-10 22:55:37 +08:00
|
|
|
</Styled.HoverToolbar>
|
2021-08-06 04:19:27 +08:00
|
|
|
),
|
2021-12-15 00:51:12 +08:00
|
|
|
(deviceInfo.isMobile && playing) && (
|
2021-11-04 00:37:17 +08:00
|
|
|
<Styled.MobileControlsOverlay
|
2021-08-06 20:28:42 +08:00
|
|
|
key="mobile-overlay-external-video"
|
2021-08-06 04:19:27 +08:00
|
|
|
ref={(ref) => { this.overlay = ref; }}
|
|
|
|
onTouchStart={() => {
|
|
|
|
clearTimeout(this.mobileHoverSetTimeout);
|
|
|
|
this.setState({ showHoverToolBar: true });
|
|
|
|
}}
|
|
|
|
onTouchEnd={() => {
|
|
|
|
this.mobileHoverSetTimeout = setTimeout(
|
|
|
|
() => this.setState({ showHoverToolBar: false }),
|
|
|
|
5000,
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
]
|
|
|
|
: null
|
|
|
|
}
|
2021-11-04 00:37:17 +08:00
|
|
|
</Styled.VideoPlayerWrapper>
|
2021-08-06 04:19:27 +08:00
|
|
|
</span>
|
2018-11-30 01:24:02 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-29 04:08:47 +08:00
|
|
|
VideoPlayer.propTypes = {
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
fullscreenElementId: PropTypes.string.isRequired,
|
|
|
|
fullscreenContext: PropTypes.bool.isRequired,
|
|
|
|
};
|
|
|
|
|
2022-02-15 06:17:14 +08:00
|
|
|
export default injectIntl(injectWbResizeEvent(VideoPlayer));
|