Files
frigate/web/src/components/JSMpegPlayer.jsx
T

38 lines
976 B
React
Raw Normal View History

2021-06-12 09:55:40 -05:00
import { h } from 'preact';
import { baseUrl } from '../api/baseUrl';
import { useRef, useEffect } from 'preact/hooks';
import JSMpeg from '@cycjimmy/jsmpeg-player';
2021-10-17 07:39:23 -05:00
export default function JSMpegPlayer({ camera, width, height }) {
2021-06-12 09:55:40 -05:00
const playerRef = useRef();
2022-05-19 07:31:02 -05:00
const url = `${baseUrl.replace(/^http/, 'ws')}live/${camera}`;
2021-06-12 09:55:40 -05:00
useEffect(() => {
const video = new JSMpeg.VideoElement(
playerRef.current,
url,
2021-06-13 14:21:20 -05:00
{},
2021-07-21 08:11:16 -05:00
{protocols: [], audio: false, videoBufferSize: 1024*1024*4}
2021-06-12 09:55:40 -05:00
);
2021-06-19 09:16:00 -05:00
const fullscreen = () => {
2022-02-26 13:11:00 -06:00
if (video.els.canvas.webkitRequestFullScreen) {
2021-06-19 09:16:00 -05:00
video.els.canvas.webkitRequestFullScreen();
}
else {
video.els.canvas.mozRequestFullScreen();
}
2022-02-26 13:11:00 -06:00
};
2021-06-19 09:16:00 -05:00
2022-02-26 13:11:00 -06:00
video.els.canvas.addEventListener('click',fullscreen);
2021-06-19 09:16:00 -05:00
2021-06-12 09:55:40 -05:00
return () => {
video.destroy();
};
}, [url]);
return (
2021-10-17 07:39:23 -05:00
<div ref={playerRef} class="jsmpeg" style={`max-height: ${height}px; max-width: ${width}px`} />
2021-06-12 09:55:40 -05:00
);
}