2021-04-16 09:43:34 +00:00
|
|
|
/* @flow */
|
|
|
|
/* eslint-disable no-invalid-this */
|
2021-11-10 10:11:29 +00:00
|
|
|
import Logger from '@jitsi/logger';
|
2021-04-16 09:43:34 +00:00
|
|
|
import throttle from 'lodash/throttle';
|
2021-08-02 12:55:52 +00:00
|
|
|
import { PureComponent } from 'react';
|
2021-04-16 09:43:34 +00:00
|
|
|
|
|
|
|
import { sendAnalytics, createSharedVideoEvent as createEvent } from '../../../analytics';
|
|
|
|
import { getCurrentConference } from '../../../base/conference';
|
|
|
|
import { MEDIA_TYPE } from '../../../base/media';
|
|
|
|
import { getLocalParticipant } from '../../../base/participants';
|
|
|
|
import { isLocalTrackMuted } from '../../../base/tracks';
|
2021-11-24 11:05:27 +00:00
|
|
|
import { NOTIFICATION_TIMEOUT_TYPE } from '../../../notifications';
|
2021-07-09 14:16:35 +00:00
|
|
|
import { showWarningNotification } from '../../../notifications/actions';
|
2021-04-16 09:43:34 +00:00
|
|
|
import { dockToolbox } from '../../../toolbox/actions.web';
|
|
|
|
import { muteLocal } from '../../../video-menu/actions.any';
|
2021-07-09 14:16:35 +00:00
|
|
|
import { setSharedVideoStatus, stopSharedVideo } from '../../actions.any';
|
2021-08-02 12:55:52 +00:00
|
|
|
import { PLAYBACK_STATUSES } from '../../constants';
|
2021-04-16 09:43:34 +00:00
|
|
|
|
2021-07-09 14:16:35 +00:00
|
|
|
const logger = Logger.getLogger(__filename);
|
|
|
|
|
2021-04-16 09:43:34 +00:00
|
|
|
/**
|
|
|
|
* Return true if the diffenrece between the two timees is larger than 5.
|
|
|
|
*
|
|
|
|
* @param {number} newTime - The current time.
|
|
|
|
* @param {number} previousTime - The previous time.
|
|
|
|
* @private
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
function shouldSeekToPosition(newTime, previousTime) {
|
|
|
|
return Math.abs(newTime - previousTime) > 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-02 12:55:52 +00:00
|
|
|
* The type of the React {@link PureComponent} props of {@link AbstractVideoManager}.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
export type Props = {
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* The current coference.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
_conference: Object,
|
|
|
|
|
2021-07-09 14:16:35 +00:00
|
|
|
/**
|
2022-07-14 07:10:08 +00:00
|
|
|
* Warning that indicates an incorrect video url.
|
2021-07-09 14:16:35 +00:00
|
|
|
*/
|
|
|
|
_displayWarning: Function,
|
|
|
|
|
2021-04-16 09:43:34 +00:00
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Docks the toolbox.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
_dockToolbox: Function,
|
|
|
|
|
2021-07-09 14:16:35 +00:00
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Action to stop video sharing.
|
2021-07-09 14:16:35 +00:00
|
|
|
*/
|
|
|
|
_stopSharedVideo: Function,
|
|
|
|
|
2021-04-16 09:43:34 +00:00
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Indicates whether the local audio is muted.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
_isLocalAudioMuted: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the video shared by the local user.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_isOwner: boolean,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Store flag for muted state.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
_muted: boolean,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Mutes local audio track.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
_muteLocal: Function,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* The shared video owner id.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
_ownerId: string,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Updates the shared video status.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
_setSharedVideoStatus: Function,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* The shared video status.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
_status: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Seek time in seconds.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
_time: number,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* The video url.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
_videoUrl: string,
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* The video id.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
videoId: string
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manager of shared video.
|
|
|
|
*/
|
2021-08-02 12:55:52 +00:00
|
|
|
class AbstractVideoManager extends PureComponent<Props> {
|
2021-04-16 09:43:34 +00:00
|
|
|
throttledFireUpdateSharedVideoEvent: Function;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new instance of AbstractVideoManager.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.throttledFireUpdateSharedVideoEvent = throttle(this.fireUpdateSharedVideoEvent.bind(this), 5000);
|
|
|
|
|
|
|
|
// selenium tests handler
|
|
|
|
window._sharedVideoPlayer = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React Component's componentDidMount.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
|
|
|
this.props._dockToolbox(true);
|
|
|
|
this.processUpdatedProps();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React Component's componentDidUpdate.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentDidUpdate(prevProps: Props) {
|
|
|
|
const { _videoUrl } = this.props;
|
|
|
|
|
|
|
|
if (prevProps._videoUrl !== _videoUrl) {
|
|
|
|
sendAnalytics(createEvent('started'));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.processUpdatedProps();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React Component's componentWillUnmount.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
|
|
|
sendAnalytics(createEvent('stopped'));
|
|
|
|
|
|
|
|
if (this.dispose) {
|
|
|
|
this.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.props._dockToolbox(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes new properties.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
processUpdatedProps() {
|
|
|
|
const { _status, _time, _isOwner, _muted } = this.props;
|
|
|
|
|
|
|
|
if (_isOwner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const playerTime = this.getTime();
|
|
|
|
|
|
|
|
if (shouldSeekToPosition(_time, playerTime)) {
|
|
|
|
this.seek(_time);
|
|
|
|
}
|
|
|
|
|
2021-08-02 12:55:52 +00:00
|
|
|
if (this.getPlaybackStatus() !== _status) {
|
|
|
|
if (_status === PLAYBACK_STATUSES.PLAYING) {
|
2021-04-16 09:43:34 +00:00
|
|
|
this.play();
|
|
|
|
}
|
|
|
|
|
2021-08-02 12:55:52 +00:00
|
|
|
if (_status === PLAYBACK_STATUSES.PAUSED) {
|
2021-04-16 09:43:34 +00:00
|
|
|
this.pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isMuted() !== _muted) {
|
|
|
|
if (_muted) {
|
|
|
|
this.mute();
|
|
|
|
} else {
|
|
|
|
this.unMute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-09 14:16:35 +00:00
|
|
|
/**
|
|
|
|
* Handle video error.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
onError() {
|
|
|
|
logger.error('Error in the video player');
|
|
|
|
this.props._stopSharedVideo();
|
|
|
|
this.props._displayWarning();
|
|
|
|
}
|
|
|
|
|
2021-04-16 09:43:34 +00:00
|
|
|
/**
|
|
|
|
* Handle video playing.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
onPlay() {
|
|
|
|
this.smartAudioMute();
|
|
|
|
sendAnalytics(createEvent('play'));
|
|
|
|
this.fireUpdateSharedVideoEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle video paused.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
onPause() {
|
|
|
|
sendAnalytics(createEvent('paused'));
|
|
|
|
this.fireUpdateSharedVideoEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle volume changed.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
onVolumeChange() {
|
|
|
|
const volume = this.getVolume();
|
|
|
|
const muted = this.isMuted();
|
|
|
|
|
|
|
|
if (volume > 0 && !muted) {
|
|
|
|
this.smartAudioMute();
|
|
|
|
}
|
|
|
|
|
|
|
|
sendAnalytics(createEvent(
|
|
|
|
'volume.changed',
|
|
|
|
{
|
|
|
|
volume,
|
|
|
|
muted
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.fireUpdatePlayingVideoEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle changes to the shared playing video.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
fireUpdatePlayingVideoEvent() {
|
2021-08-02 12:55:52 +00:00
|
|
|
if (this.getPlaybackStatus() === PLAYBACK_STATUSES.PLAYING) {
|
2021-04-16 09:43:34 +00:00
|
|
|
this.fireUpdateSharedVideoEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches an update action for the shared video.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
fireUpdateSharedVideoEvent() {
|
|
|
|
const { _isOwner } = this.props;
|
|
|
|
|
|
|
|
if (!_isOwner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-02 12:55:52 +00:00
|
|
|
const status = this.getPlaybackStatus();
|
2021-04-16 09:43:34 +00:00
|
|
|
|
2021-08-02 12:55:52 +00:00
|
|
|
if (!Object.values(PLAYBACK_STATUSES).includes(status)) {
|
2021-04-16 09:43:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
_ownerId,
|
|
|
|
_setSharedVideoStatus,
|
|
|
|
_videoUrl
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
_setSharedVideoStatus({
|
|
|
|
videoUrl: _videoUrl,
|
|
|
|
status,
|
|
|
|
time: this.getTime(),
|
|
|
|
ownerId: _ownerId,
|
|
|
|
muted: this.isMuted()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates if the player volume is currently on. This will return true if
|
|
|
|
* we have an available player, which is currently in a PLAYING state,
|
|
|
|
* which isn't muted and has it's volume greater than 0.
|
|
|
|
*
|
|
|
|
* @returns {boolean} Indicating if the volume of the shared video is
|
|
|
|
* currently on.
|
|
|
|
*/
|
|
|
|
isSharedVideoVolumeOn() {
|
2021-08-02 12:55:52 +00:00
|
|
|
return this.getPlaybackStatus() === PLAYBACK_STATUSES.PLAYING
|
2021-04-16 09:43:34 +00:00
|
|
|
&& !this.isMuted()
|
|
|
|
&& this.getVolume() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Smart mike mute. If the mike isn't currently muted and the shared video
|
|
|
|
* volume is on we mute the mike.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
smartAudioMute() {
|
|
|
|
const { _isLocalAudioMuted, _muteLocal } = this.props;
|
|
|
|
|
|
|
|
if (!_isLocalAudioMuted
|
|
|
|
&& this.isSharedVideoVolumeOn()) {
|
|
|
|
sendAnalytics(createEvent('audio.muted'));
|
|
|
|
_muteLocal(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Seeks video to provided time.
|
|
|
|
*
|
2021-04-16 09:43:34 +00:00
|
|
|
* @param {number} time
|
|
|
|
*/
|
|
|
|
seek: (time: number) => void;
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Indicates the playback state of the video.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
2021-08-02 12:55:52 +00:00
|
|
|
getPlaybackStatus: () => boolean;
|
2021-04-16 09:43:34 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Indicates whether the video is muted.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
isMuted: () => boolean;
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Retrieves current volume.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
getVolume: () => number;
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Plays video.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
play: () => void;
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Pauses video.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
pause: () => void;
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Mutes video.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
mute: () => void;
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Unmutes video.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
unMute: () => void;
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Retrieves current time.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
getTime: () => number;
|
|
|
|
|
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Disposes current video player.
|
2021-04-16 09:43:34 +00:00
|
|
|
*/
|
|
|
|
dispose: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default AbstractVideoManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps part of the Redux store to the props of this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
export function _mapStateToProps(state: Object): $Shape<Props> {
|
|
|
|
const { ownerId, status, time, videoUrl, muted } = state['features/shared-video'];
|
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
const _isLocalAudioMuted = isLocalTrackMuted(state['features/base/tracks'], MEDIA_TYPE.AUDIO);
|
|
|
|
|
|
|
|
return {
|
|
|
|
_conference: getCurrentConference(state),
|
|
|
|
_isLocalAudioMuted,
|
|
|
|
_isOwner: ownerId === localParticipant.id,
|
|
|
|
_muted: muted,
|
|
|
|
_ownerId: ownerId,
|
|
|
|
_status: status,
|
|
|
|
_time: time,
|
|
|
|
_videoUrl: videoUrl
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps part of the props of this component to Redux actions.
|
|
|
|
*
|
|
|
|
* @param {Function} dispatch - The Redux dispatch function.
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
export function _mapDispatchToProps(dispatch: Function): $Shape<Props> {
|
|
|
|
return {
|
2021-07-09 14:16:35 +00:00
|
|
|
_displayWarning: () => {
|
|
|
|
dispatch(showWarningNotification({
|
|
|
|
titleKey: 'dialog.shareVideoLinkError'
|
2021-11-24 11:05:27 +00:00
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.LONG));
|
2021-07-09 14:16:35 +00:00
|
|
|
},
|
2021-04-16 09:43:34 +00:00
|
|
|
_dockToolbox: value => {
|
|
|
|
dispatch(dockToolbox(value));
|
|
|
|
},
|
2021-07-09 14:16:35 +00:00
|
|
|
_stopSharedVideo: () => {
|
|
|
|
dispatch(stopSharedVideo());
|
|
|
|
},
|
2021-04-16 09:43:34 +00:00
|
|
|
_muteLocal: value => {
|
|
|
|
dispatch(muteLocal(value, MEDIA_TYPE.AUDIO));
|
|
|
|
},
|
|
|
|
_setSharedVideoStatus: ({ videoUrl, status, time, ownerId, muted }) => {
|
|
|
|
dispatch(setSharedVideoStatus({
|
|
|
|
videoUrl,
|
|
|
|
status,
|
|
|
|
time,
|
|
|
|
ownerId,
|
|
|
|
muted
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|