2024-02-28 07:25:11 +08:00
|
|
|
/* eslint-disable no-param-reassign */
|
2023-11-06 23:02:12 +08:00
|
|
|
import React, { useEffect, useMemo, useRef } from 'react';
|
|
|
|
import ReactPlayer from 'react-player';
|
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
import audioManager from '/imports/ui/services/audio-manager';
|
2024-01-19 22:46:11 +08:00
|
|
|
import { useReactiveVar, useMutation } from '@apollo/client';
|
2023-11-06 23:02:12 +08:00
|
|
|
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
|
2024-01-31 05:37:29 +08:00
|
|
|
import { ExternalVideoVolumeCommandsEnum } from 'bigbluebutton-html-plugin-sdk/dist/cjs/ui-commands/external-video/volume/enums';
|
|
|
|
import { SetExternalVideoVolumeCommandArguments } from 'bigbluebutton-html-plugin-sdk/dist/cjs/ui-commands/external-video/volume/types';
|
2023-11-06 23:02:12 +08:00
|
|
|
import { OnProgressProps } from 'react-player/base';
|
2024-02-28 07:25:11 +08:00
|
|
|
import * as PluginSdk from 'bigbluebutton-html-plugin-sdk';
|
|
|
|
import { UI_DATA_LISTENER_SUBSCRIBED } from 'bigbluebutton-html-plugin-sdk/dist/cjs/ui-data-hooks/consts';
|
|
|
|
import { ExternalVideoVolumeUiDataNames } from 'bigbluebutton-html-plugin-sdk';
|
|
|
|
import { ExternalVideoVolumeUiDataPayloads } from 'bigbluebutton-html-plugin-sdk/dist/cjs/ui-data-hooks/external-video/volume/types';
|
2023-11-06 23:02:12 +08:00
|
|
|
|
|
|
|
import useMeeting from '/imports/ui/core/hooks/useMeeting';
|
|
|
|
import {
|
|
|
|
layoutDispatch,
|
|
|
|
layoutSelect,
|
|
|
|
layoutSelectInput,
|
|
|
|
layoutSelectOutput,
|
|
|
|
} from '../../layout/context';
|
|
|
|
import Styled from './styles';
|
|
|
|
import {
|
|
|
|
ExternalVideo,
|
|
|
|
Input,
|
|
|
|
Layout,
|
|
|
|
Output,
|
|
|
|
} from '../../layout/layoutTypes';
|
|
|
|
import { uniqueId } from '/imports/utils/string-utils';
|
|
|
|
import useTimeSync from '/imports/ui/core/local-states/useTimeSync';
|
|
|
|
import ExternalVideoPlayerToolbar from './toolbar/component';
|
|
|
|
import deviceInfo from '/imports/utils/deviceInfo';
|
2024-03-26 05:13:57 +08:00
|
|
|
import { ACTIONS, PRESENTATION_AREA } from '../../layout/enums';
|
2024-01-19 22:46:11 +08:00
|
|
|
import { EXTERNAL_VIDEO_UPDATE } from '../mutations';
|
2023-11-06 23:02:12 +08:00
|
|
|
|
|
|
|
import PeerTube from '../custom-players/peertube';
|
|
|
|
import { ArcPlayer } from '../custom-players/arc-player';
|
|
|
|
|
|
|
|
const AUTO_PLAY_BLOCK_DETECTION_TIMEOUT_SECONDS = 5;
|
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
autoPlayWarning: {
|
|
|
|
id: 'app.externalVideo.autoPlayWarning',
|
|
|
|
description: 'Shown when user needs to interact with player to make it work',
|
|
|
|
},
|
|
|
|
refreshLabel: {
|
|
|
|
id: 'app.externalVideo.refreshLabel',
|
|
|
|
},
|
|
|
|
fullscreenLabel: {
|
|
|
|
id: 'app.externalVideo.fullscreenLabel',
|
|
|
|
},
|
|
|
|
subtitlesOn: {
|
|
|
|
id: 'app.externalVideo.subtitlesOn',
|
|
|
|
},
|
|
|
|
subtitlesOff: {
|
|
|
|
id: 'app.externalVideo.subtitlesOff',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
interface ExternalVideoPlayerProps {
|
2024-02-28 07:25:11 +08:00
|
|
|
currentVolume: React.MutableRefObject<number>;
|
|
|
|
isMuted: React.MutableRefObject<boolean>;
|
2023-11-06 23:02:12 +08:00
|
|
|
isEchoTest: boolean;
|
|
|
|
isPresenter: boolean;
|
|
|
|
videoUrl: string;
|
|
|
|
isResizing: boolean;
|
|
|
|
fullscreenContext: boolean;
|
|
|
|
externalVideo: ExternalVideo;
|
|
|
|
playing: boolean;
|
|
|
|
playerPlaybackRate: number;
|
|
|
|
currentTime: number;
|
|
|
|
key: string;
|
|
|
|
setKey: (key: string) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore - PeerTubePlayer is not typed
|
|
|
|
Styled.VideoPlayer.addCustomPlayer(PeerTube);
|
|
|
|
// @ts-ignore - ArcPlayer is not typed
|
|
|
|
Styled.VideoPlayer.addCustomPlayer(ArcPlayer);
|
|
|
|
|
|
|
|
const ExternalVideoPlayer: React.FC<ExternalVideoPlayerProps> = ({
|
2024-02-28 07:25:11 +08:00
|
|
|
currentVolume,
|
|
|
|
isMuted,
|
2023-11-06 23:02:12 +08:00
|
|
|
isResizing,
|
|
|
|
externalVideo,
|
|
|
|
fullscreenContext,
|
|
|
|
videoUrl,
|
|
|
|
isPresenter,
|
|
|
|
playing,
|
|
|
|
playerPlaybackRate,
|
|
|
|
currentTime,
|
|
|
|
isEchoTest,
|
|
|
|
key,
|
|
|
|
setKey,
|
|
|
|
}) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
const {
|
|
|
|
height,
|
|
|
|
width,
|
|
|
|
top,
|
|
|
|
left,
|
|
|
|
right,
|
|
|
|
} = externalVideo;
|
|
|
|
|
|
|
|
const hideVolume = useMemo(() => ({
|
|
|
|
Vimeo: true,
|
|
|
|
Facebook: true,
|
|
|
|
ArcPlayer: true,
|
|
|
|
// YouTube: true,
|
|
|
|
}), []);
|
|
|
|
|
|
|
|
const videoPlayConfig = useMemo(() => {
|
|
|
|
return {
|
|
|
|
// default option for all players, can be overwritten
|
|
|
|
playerOptions: {
|
|
|
|
autoplay: true,
|
|
|
|
playsinline: true,
|
|
|
|
controls: isPresenter,
|
|
|
|
},
|
|
|
|
file: {
|
|
|
|
attributes: {
|
|
|
|
controls: isPresenter ? 'controls' : '',
|
|
|
|
autoplay: 'autoplay',
|
|
|
|
playsinline: 'playsinline',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
facebook: {
|
|
|
|
controls: isPresenter,
|
|
|
|
},
|
|
|
|
dailymotion: {
|
|
|
|
params: {
|
|
|
|
controls: isPresenter,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
youtube: {
|
|
|
|
playerVars: {
|
|
|
|
autoplay: 1,
|
|
|
|
modestbranding: 1,
|
|
|
|
autohide: 1,
|
|
|
|
rel: 0,
|
|
|
|
ecver: 2,
|
|
|
|
controls: isPresenter ? 1 : 0,
|
|
|
|
cc_lang_pref: document.getElementsByTagName('html')[0].lang.substring(0, 2),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
peertube: {
|
|
|
|
isPresenter,
|
|
|
|
},
|
|
|
|
twitch: {
|
|
|
|
options: {
|
|
|
|
controls: isPresenter,
|
|
|
|
},
|
|
|
|
playerId: 'externalVideoPlayerTwitch',
|
|
|
|
},
|
|
|
|
preload: true,
|
|
|
|
showHoverToolBar: false,
|
|
|
|
};
|
|
|
|
}, [isPresenter]);
|
|
|
|
|
2024-04-17 10:33:49 +08:00
|
|
|
const [showUnsynchedMsg, setShowUnsynchedMsg] = React.useState(false);
|
2023-11-06 23:02:12 +08:00
|
|
|
const [showHoverToolBar, setShowHoverToolBar] = React.useState(false);
|
|
|
|
const [mute, setMute] = React.useState(false);
|
|
|
|
const [volume, setVolume] = React.useState(1);
|
|
|
|
const [subtitlesOn, setSubtitlesOn] = React.useState(false);
|
|
|
|
const [played, setPlayed] = React.useState(0);
|
|
|
|
const [loaded, setLoaded] = React.useState(0);
|
|
|
|
const playerRef = useRef<ReactPlayer>();
|
|
|
|
const playerParentRef = useRef<HTMLDivElement| null>(null);
|
|
|
|
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
|
2023-12-13 04:47:29 +08:00
|
|
|
const presenterRef = useRef(isPresenter);
|
2024-03-27 22:02:43 +08:00
|
|
|
const [duration, setDuration] = React.useState(0);
|
2024-04-17 10:33:49 +08:00
|
|
|
const [reactPlayerState, setReactPlayerState] = React.useState(false);
|
2024-01-19 22:46:11 +08:00
|
|
|
|
|
|
|
const [updateExternalVideo] = useMutation(EXTERNAL_VIDEO_UPDATE);
|
|
|
|
|
|
|
|
let lastMessage: {
|
|
|
|
event: string;
|
|
|
|
rate: number;
|
|
|
|
time: number;
|
|
|
|
state?: string;
|
|
|
|
} = { event: '', rate: 0, time: 0 };
|
|
|
|
|
2024-03-27 22:02:43 +08:00
|
|
|
const handleDuration = (duration: number) => {
|
|
|
|
setDuration(duration);
|
|
|
|
};
|
|
|
|
|
2024-01-19 22:46:11 +08:00
|
|
|
const sendMessage = (event: string, data: { rate: number; time: number; state?: string}) => {
|
|
|
|
// don't re-send repeated update messages
|
|
|
|
if (
|
|
|
|
lastMessage.event === event
|
|
|
|
&& lastMessage.time === data.time
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't register to redis a viewer joined message
|
|
|
|
if (event === 'viewerJoined') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastMessage = { ...data, event };
|
|
|
|
|
|
|
|
// Use an integer for playing state
|
|
|
|
// 0: stopped 1: playing
|
|
|
|
// We might use more states in the future
|
|
|
|
const state = data.state ? 1 : 0;
|
|
|
|
|
|
|
|
updateExternalVideo({
|
|
|
|
variables: {
|
|
|
|
status: event,
|
|
|
|
rate: data?.rate,
|
|
|
|
time: data?.time,
|
|
|
|
state,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-11-06 23:02:12 +08:00
|
|
|
useEffect(() => {
|
2024-04-17 10:33:49 +08:00
|
|
|
const unsynchedPlayer = reactPlayerState !== playing;
|
2024-04-19 22:08:13 +08:00
|
|
|
if (unsynchedPlayer && !!videoUrl) {
|
2024-04-17 10:33:49 +08:00
|
|
|
timeoutRef.current = setTimeout(() => {
|
|
|
|
setShowUnsynchedMsg(true);
|
|
|
|
}, AUTO_PLAY_BLOCK_DETECTION_TIMEOUT_SECONDS * 1000);
|
|
|
|
} else {
|
|
|
|
setShowUnsynchedMsg(false);
|
|
|
|
clearTimeout(timeoutRef.current);
|
|
|
|
}
|
|
|
|
}, [reactPlayerState, playing]);
|
2023-11-06 23:02:12 +08:00
|
|
|
|
2024-04-17 10:33:49 +08:00
|
|
|
useEffect(() => {
|
2024-01-31 05:37:29 +08:00
|
|
|
const handleExternalVideoVolumeSet = ((
|
|
|
|
event: CustomEvent<SetExternalVideoVolumeCommandArguments>,
|
|
|
|
) => setVolume(event.detail.volume)) as EventListener;
|
|
|
|
window.addEventListener(ExternalVideoVolumeCommandsEnum.SET, handleExternalVideoVolumeSet);
|
|
|
|
return () => {
|
|
|
|
window.addEventListener(ExternalVideoVolumeCommandsEnum.SET, handleExternalVideoVolumeSet);
|
|
|
|
};
|
2023-11-06 23:02:12 +08:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (playerRef.current && !isPresenter) {
|
|
|
|
playerRef.current.seekTo(currentTime, 'seconds');
|
|
|
|
}
|
|
|
|
}, [currentTime]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (playerRef.current) {
|
|
|
|
playerRef.current.seekTo(currentTime, 'seconds');
|
|
|
|
}
|
|
|
|
}, [playerRef.current]);
|
|
|
|
|
2024-02-28 07:25:11 +08:00
|
|
|
// --- Plugin related code ---;
|
2024-03-07 02:30:04 +08:00
|
|
|
const internalPlayer = playerRef.current?.getInternalPlayer ? playerRef.current?.getInternalPlayer() : null;
|
|
|
|
if (internalPlayer && internalPlayer?.isMuted
|
|
|
|
&& typeof internalPlayer?.isMuted === 'function'
|
|
|
|
&& internalPlayer?.isMuted() !== isMuted.current) {
|
|
|
|
isMuted.current = internalPlayer?.isMuted();
|
2024-02-28 07:25:11 +08:00
|
|
|
window.dispatchEvent(new CustomEvent(ExternalVideoVolumeUiDataNames.IS_VOLUME_MUTED, {
|
|
|
|
detail: {
|
2024-03-07 02:30:04 +08:00
|
|
|
value: internalPlayer?.isMuted(),
|
2024-02-28 07:25:11 +08:00
|
|
|
} as ExternalVideoVolumeUiDataPayloads[ExternalVideoVolumeUiDataNames.IS_VOLUME_MUTED],
|
|
|
|
}));
|
|
|
|
}
|
2024-03-07 02:30:04 +08:00
|
|
|
if (internalPlayer && internalPlayer?.getVolume
|
|
|
|
&& typeof internalPlayer?.getVolume === 'function'
|
|
|
|
&& internalPlayer?.getVolume() !== currentVolume.current) {
|
|
|
|
currentVolume.current = internalPlayer?.getVolume();
|
2024-02-28 07:25:11 +08:00
|
|
|
window.dispatchEvent(new CustomEvent(ExternalVideoVolumeUiDataNames.CURRENT_VOLUME_VALUE, {
|
|
|
|
detail: {
|
2024-03-07 02:30:04 +08:00
|
|
|
value: internalPlayer?.getVolume() / 100,
|
2024-02-28 07:25:11 +08:00
|
|
|
} as ExternalVideoVolumeUiDataPayloads[ExternalVideoVolumeUiDataNames.CURRENT_VOLUME_VALUE],
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
// --- End of plugin related code ---
|
|
|
|
|
2023-12-13 04:47:29 +08:00
|
|
|
useEffect(() => {
|
|
|
|
if (isPresenter !== presenterRef.current) {
|
|
|
|
setKey(uniqueId('react-player'));
|
|
|
|
presenterRef.current = isPresenter;
|
|
|
|
}
|
|
|
|
}, [isPresenter]);
|
|
|
|
|
2023-11-06 23:02:12 +08:00
|
|
|
const handleOnPlay = () => {
|
2024-04-17 10:33:49 +08:00
|
|
|
setReactPlayerState(true);
|
2023-11-06 23:02:12 +08:00
|
|
|
if (isPresenter) {
|
|
|
|
const rate = playerRef.current?.getInternalPlayer()?.getPlaybackRate() as number ?? 1;
|
2024-03-27 22:02:43 +08:00
|
|
|
const currentTime = played * duration;
|
2023-11-06 23:02:12 +08:00
|
|
|
sendMessage('play', {
|
|
|
|
rate,
|
|
|
|
time: currentTime,
|
|
|
|
});
|
|
|
|
} else if (!playing && !isPresenter) {
|
|
|
|
playerRef.current?.getInternalPlayer().pauseVideo();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-02-14 21:13:43 +08:00
|
|
|
const handleOnStop = () => {
|
2024-04-17 10:33:49 +08:00
|
|
|
setReactPlayerState(false);
|
2023-11-06 23:02:12 +08:00
|
|
|
if (isPresenter) {
|
|
|
|
const rate = playerRef.current?.getInternalPlayer()?.getPlaybackRate() as number ?? 1;
|
|
|
|
const currentTime = playerRef.current?.getCurrentTime() ?? 0;
|
|
|
|
sendMessage('stop', {
|
|
|
|
rate,
|
|
|
|
time: currentTime,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isPresenter && playing) {
|
|
|
|
playerRef.current?.getInternalPlayer().playVideo();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const isMinimized = width === 0 && height === 0;
|
|
|
|
|
|
|
|
// @ts-ignore accessing lib private property
|
|
|
|
const playerName = playerRef.current && playerRef.current.player
|
2024-04-17 10:33:49 +08:00
|
|
|
// @ts-ignore accessing lib private property
|
|
|
|
&& playerRef.current.player.player && playerRef.current.player.player.constructor.name as string;
|
2023-11-06 23:02:12 +08:00
|
|
|
let toolbarStyle = 'hoverToolbar';
|
|
|
|
|
|
|
|
if (deviceInfo.isMobile && !showHoverToolBar) {
|
|
|
|
toolbarStyle = 'dontShowMobileHoverToolbar';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceInfo.isMobile && showHoverToolBar) {
|
|
|
|
toolbarStyle = 'showMobileHoverToolbar';
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Styled.Container
|
|
|
|
style={{
|
|
|
|
height,
|
|
|
|
width,
|
|
|
|
top,
|
|
|
|
left,
|
|
|
|
right,
|
|
|
|
}}
|
|
|
|
isResizing={isResizing}
|
|
|
|
isMinimized={isMinimized}
|
|
|
|
>
|
|
|
|
<Styled.VideoPlayerWrapper
|
|
|
|
fullscreen={fullscreenContext}
|
|
|
|
ref={playerParentRef}
|
|
|
|
data-test="videoPlayer"
|
|
|
|
>
|
|
|
|
|
|
|
|
{
|
2024-04-17 10:33:49 +08:00
|
|
|
showUnsynchedMsg
|
2023-11-06 23:02:12 +08:00
|
|
|
? (
|
|
|
|
<Styled.AutoPlayWarning>
|
|
|
|
{intl.formatMessage(intlMessages.autoPlayWarning)}
|
|
|
|
</Styled.AutoPlayWarning>
|
|
|
|
)
|
|
|
|
: ''
|
|
|
|
}
|
|
|
|
<Styled.VideoPlayer
|
|
|
|
config={videoPlayConfig}
|
|
|
|
autoPlay
|
|
|
|
playsInline
|
|
|
|
url={videoUrl}
|
|
|
|
playing={playing}
|
|
|
|
playbackRate={playerPlaybackRate}
|
|
|
|
key={key}
|
|
|
|
height="100%"
|
|
|
|
width="100%"
|
|
|
|
ref={playerRef}
|
|
|
|
volume={volume}
|
|
|
|
onPlay={handleOnPlay}
|
2024-03-27 22:02:43 +08:00
|
|
|
onDuration={handleDuration}
|
2023-11-06 23:02:12 +08:00
|
|
|
onProgress={(state: OnProgressProps) => {
|
|
|
|
setPlayed(state.played);
|
|
|
|
setLoaded(state.loaded);
|
|
|
|
}}
|
2024-02-14 21:13:43 +08:00
|
|
|
onPause={handleOnStop}
|
|
|
|
onEnded={handleOnStop}
|
2024-03-01 20:36:18 +08:00
|
|
|
muted={mute || isEchoTest}
|
2023-11-06 23:02:12 +08:00
|
|
|
/>
|
|
|
|
{
|
|
|
|
!isPresenter ? (
|
|
|
|
<ExternalVideoPlayerToolbar
|
|
|
|
handleOnMuted={(m: boolean) => { setMute(m); }}
|
|
|
|
handleReload={() => setKey(uniqueId('react-player'))}
|
|
|
|
setShowHoverToolBar={setShowHoverToolBar}
|
|
|
|
toolbarStyle={toolbarStyle}
|
|
|
|
handleVolumeChanged={setVolume}
|
|
|
|
volume={volume}
|
|
|
|
muted={mute || isEchoTest}
|
|
|
|
mutedByEchoTest={isEchoTest}
|
|
|
|
playing={playing}
|
|
|
|
playerName={playerName}
|
|
|
|
toggleSubtitle={() => setSubtitlesOn(!subtitlesOn)}
|
|
|
|
playerParent={playerParentRef.current}
|
|
|
|
played={played}
|
|
|
|
loaded={loaded}
|
|
|
|
subtitlesOn={subtitlesOn}
|
|
|
|
hideVolume={hideVolume[playerName as keyof typeof hideVolume]}
|
|
|
|
/>
|
|
|
|
) : null
|
2024-04-17 10:33:49 +08:00
|
|
|
}
|
2023-11-06 23:02:12 +08:00
|
|
|
</Styled.VideoPlayerWrapper>
|
|
|
|
</Styled.Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const ExternalVideoPlayerContainer: React.FC = () => {
|
|
|
|
/* eslint no-underscore-dangle: "off" */
|
|
|
|
// @ts-ignore - temporary while hybrid (meteor+GraphQl)
|
|
|
|
const isEchoTest = useReactiveVar(audioManager._isEchoTest.value) as boolean;
|
2023-11-15 21:38:50 +08:00
|
|
|
const theresNoExternalVideo = useRef(true);
|
2023-11-14 02:10:41 +08:00
|
|
|
const { data: currentUser } = useCurrentUser((user) => ({
|
2023-11-06 23:02:12 +08:00
|
|
|
presenter: user.presenter,
|
|
|
|
}));
|
2024-02-28 07:25:11 +08:00
|
|
|
const currentVolume = React.useRef(0);
|
|
|
|
const isMuted = React.useRef(false);
|
2023-11-06 23:02:12 +08:00
|
|
|
|
2023-11-14 02:10:41 +08:00
|
|
|
const { data: currentMeeting } = useMeeting((m) => ({
|
2023-11-06 23:02:12 +08:00
|
|
|
externalVideo: m.externalVideo,
|
|
|
|
}));
|
|
|
|
|
2023-11-15 21:38:50 +08:00
|
|
|
useEffect(() => {
|
|
|
|
if (!currentMeeting?.externalVideo?.externalVideoUrl && !theresNoExternalVideo.current) {
|
|
|
|
layoutContextDispatch({
|
2024-03-26 05:13:57 +08:00
|
|
|
type: ACTIONS.SET_PILE_CONTENT_FOR_PRESENTATION_AREA,
|
|
|
|
value: {
|
|
|
|
content: PRESENTATION_AREA.EXTERNAL_VIDEO,
|
|
|
|
open: false,
|
|
|
|
},
|
2023-11-15 21:38:50 +08:00
|
|
|
});
|
2024-03-26 05:13:57 +08:00
|
|
|
theresNoExternalVideo.current = true;
|
|
|
|
} else if (currentMeeting?.externalVideo?.externalVideoUrl && theresNoExternalVideo.current) {
|
2023-11-15 21:38:50 +08:00
|
|
|
layoutContextDispatch({
|
2024-03-26 05:13:57 +08:00
|
|
|
type: ACTIONS.SET_PILE_CONTENT_FOR_PRESENTATION_AREA,
|
|
|
|
value: {
|
|
|
|
content: PRESENTATION_AREA.EXTERNAL_VIDEO,
|
|
|
|
open: true,
|
|
|
|
},
|
2023-11-15 21:38:50 +08:00
|
|
|
});
|
|
|
|
theresNoExternalVideo.current = false;
|
|
|
|
}
|
|
|
|
}, [currentMeeting]);
|
|
|
|
|
2024-02-28 07:25:11 +08:00
|
|
|
// --- Plugin related code ---
|
|
|
|
useEffect(() => {
|
|
|
|
// Define functions to first inform ui data hooks that subscribe to these events
|
|
|
|
const updateUiDataHookCurrentVolumeForPlugin = () => {
|
|
|
|
window.dispatchEvent(new CustomEvent(PluginSdk.ExternalVideoVolumeUiDataNames.CURRENT_VOLUME_VALUE, {
|
|
|
|
detail: {
|
|
|
|
value: currentVolume.current,
|
|
|
|
} as ExternalVideoVolumeUiDataPayloads[PluginSdk.ExternalVideoVolumeUiDataNames.CURRENT_VOLUME_VALUE],
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
const updateUiDataHookIsMutedPlugin = () => {
|
|
|
|
window.dispatchEvent(new CustomEvent(PluginSdk.ExternalVideoVolumeUiDataNames.IS_VOLUME_MUTED, {
|
|
|
|
detail: {
|
|
|
|
value: isMuted.current,
|
|
|
|
} as ExternalVideoVolumeUiDataPayloads[PluginSdk.ExternalVideoVolumeUiDataNames.IS_VOLUME_MUTED],
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
// When component mount, add event listener to send first information
|
|
|
|
// about these ui data hooks to plugin
|
|
|
|
window.addEventListener(
|
|
|
|
`${UI_DATA_LISTENER_SUBSCRIBED}-${PluginSdk.ExternalVideoVolumeUiDataNames.CURRENT_VOLUME_VALUE}`,
|
|
|
|
updateUiDataHookCurrentVolumeForPlugin,
|
|
|
|
);
|
|
|
|
window.addEventListener(
|
|
|
|
`${UI_DATA_LISTENER_SUBSCRIBED}-${PluginSdk.ExternalVideoVolumeUiDataNames.IS_VOLUME_MUTED}`,
|
|
|
|
updateUiDataHookIsMutedPlugin,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Before component unmount, remove event listeners for plugin ui data hooks
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener(
|
|
|
|
`${UI_DATA_LISTENER_SUBSCRIBED}-${PluginSdk.ExternalVideoVolumeUiDataNames.CURRENT_VOLUME_VALUE}`,
|
|
|
|
updateUiDataHookCurrentVolumeForPlugin,
|
|
|
|
);
|
|
|
|
window.removeEventListener(
|
|
|
|
`${UI_DATA_LISTENER_SUBSCRIBED}-${PluginSdk.ExternalVideoVolumeUiDataNames.IS_VOLUME_MUTED}`,
|
|
|
|
updateUiDataHookIsMutedPlugin,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
// --- End of plugin related code ---
|
|
|
|
|
2023-11-06 23:02:12 +08:00
|
|
|
const [timeSync] = useTimeSync();
|
|
|
|
|
|
|
|
const fullscreenElementId = 'ExternalVideo';
|
|
|
|
const externalVideo: ExternalVideo = layoutSelectOutput((i: Output) => i.externalVideo);
|
2023-11-15 21:38:50 +08:00
|
|
|
const hasExternalVideoOnLayout: boolean = layoutSelectInput((i: Input) => i.externalVideo.hasExternalVideo);
|
2023-11-06 23:02:12 +08:00
|
|
|
const cameraDock = layoutSelectInput((i: Input) => i.cameraDock);
|
|
|
|
const { isResizing } = cameraDock;
|
|
|
|
const layoutContextDispatch = layoutDispatch();
|
|
|
|
const fullscreen = layoutSelect((i: Layout) => i.fullscreen);
|
|
|
|
const { element } = fullscreen;
|
|
|
|
const fullscreenContext = (element === fullscreenElementId);
|
|
|
|
const [key, setKey] = React.useState(uniqueId('react-player'));
|
|
|
|
if (!currentUser || !currentMeeting) return null;
|
2023-11-15 21:38:50 +08:00
|
|
|
if (!hasExternalVideoOnLayout) return null;
|
2023-11-06 23:02:12 +08:00
|
|
|
const playerCurrentTime = currentMeeting.externalVideo?.playerCurrentTime ?? 0;
|
|
|
|
const playerPlaybackRate = currentMeeting.externalVideo?.playerPlaybackRate ?? 1;
|
|
|
|
const playerUpdatedAt = currentMeeting.externalVideo?.updatedAt ?? Date.now();
|
|
|
|
const playerUpdatedAtDate = new Date(playerUpdatedAt);
|
|
|
|
const currentDate = new Date(Date.now() + timeSync);
|
2024-03-18 22:37:47 +08:00
|
|
|
const isPaused = !currentMeeting.externalVideo?.playerPlaying ?? false;
|
|
|
|
const currentTime = isPaused ? playerCurrentTime : (((currentDate.getTime() - playerUpdatedAtDate.getTime()) / 1000)
|
2024-04-17 10:33:49 +08:00
|
|
|
+ playerCurrentTime) * playerPlaybackRate;
|
2024-03-06 00:33:29 +08:00
|
|
|
const isPresenter = currentUser.presenter ?? false;
|
2023-11-06 23:02:12 +08:00
|
|
|
|
2024-05-01 21:21:28 +08:00
|
|
|
console.log('currentTime', currentTime);
|
|
|
|
|
2023-11-06 23:02:12 +08:00
|
|
|
return (
|
|
|
|
<ExternalVideoPlayer
|
2024-02-28 07:25:11 +08:00
|
|
|
currentVolume={currentVolume}
|
|
|
|
isMuted={isMuted}
|
2023-11-06 23:02:12 +08:00
|
|
|
isEchoTest={isEchoTest}
|
2024-03-06 00:33:29 +08:00
|
|
|
isPresenter={isPresenter ?? false}
|
2023-11-06 23:02:12 +08:00
|
|
|
videoUrl={currentMeeting.externalVideo?.externalVideoUrl ?? ''}
|
|
|
|
playing={currentMeeting.externalVideo?.playerPlaying ?? false}
|
|
|
|
playerPlaybackRate={currentMeeting.externalVideo?.playerPlaybackRate ?? 1}
|
|
|
|
isResizing={isResizing}
|
|
|
|
fullscreenContext={fullscreenContext}
|
|
|
|
externalVideo={externalVideo}
|
2024-05-01 21:21:28 +08:00
|
|
|
currentTime={currentTime}
|
2023-11-06 23:02:12 +08:00
|
|
|
key={key}
|
|
|
|
setKey={setKey}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ExternalVideoPlayerContainer;
|