fix player fullscreen

This commit is contained in:
Baltazar Gomez 2019-10-10 17:31:21 -06:00 committed by Sean Yesmunt
parent 65598b42a1
commit 4916a443ed

View file

@ -5,6 +5,7 @@ import videojs from 'video.js';
import 'video.js/dist/video-js.css'; import 'video.js/dist/video-js.css';
import isUserTyping from 'util/detect-typing'; import isUserTyping from 'util/detect-typing';
const F11_KEYCODE = 122;
const SPACE_BAR_KEYCODE = 32; const SPACE_BAR_KEYCODE = 32;
const SMALL_F_KEYCODE = 70; const SMALL_F_KEYCODE = 70;
const SMALL_M_KEYCODE = 77; const SMALL_M_KEYCODE = 77;
@ -45,6 +46,7 @@ function VideoViewer(props: Props) {
const { contentType, source, setPlayingUri, onEndedCB, changeVolume, changeMute, volume, muted } = props; const { contentType, source, setPlayingUri, onEndedCB, changeVolume, changeMute, volume, muted } = props;
const videoRef = useRef(); const videoRef = useRef();
const [requireRedraw, setRequireRedraw] = useState(false); const [requireRedraw, setRequireRedraw] = useState(false);
let player = null;
useEffect(() => { useEffect(() => {
const currentVideo: HTMLVideoElement | null = document.querySelector('video'); const currentVideo: HTMLVideoElement | null = document.querySelector('video');
@ -91,12 +93,11 @@ function VideoViewer(props: Props) {
], ],
}; };
let player;
if (!requireRedraw) { if (!requireRedraw) {
player = videojs(videoNode, videoJsOptions, function() { player = videojs(videoNode, videoJsOptions, function() {
const player = this; const self = this;
player.volume(volume); self.volume(volume);
player.muted(muted); self.muted(muted);
}); });
} }
@ -136,9 +137,13 @@ function VideoViewer(props: Props) {
videoNode.paused ? videoNode.play() : videoNode.pause(); videoNode.paused ? videoNode.play() : videoNode.pause();
} }
// Fullscreen Shortcut // Fullscreen toggle shotcuts
if (e.keyCode === FULLSCREEN_KEYCODE) { if (e.keyCode === FULLSCREEN_KEYCODE || e.keyCode === F11_KEYCODE) {
videoNode.webkitEnterFullscreen && videoNode.webkitEnterFullscreen(); if(!player.isFullscreen()) {
player.requestFullscreen();
} else {
player.exitFullscreen();
}
} }
// Mute/Unmute Shortcuts // Mute/Unmute Shortcuts