2021-06-12 17:55:40 +03:00
|
|
|
import { h } from 'preact';
|
|
|
|
|
import { baseUrl } from '../api/baseUrl';
|
|
|
|
|
import { useRef, useEffect } from 'preact/hooks';
|
|
|
|
|
import JSMpeg from '@cycjimmy/jsmpeg-player';
|
|
|
|
|
|
|
|
|
|
export default function JSMpegPlayer({ camera }) {
|
|
|
|
|
const playerRef = useRef();
|
|
|
|
|
const url = `${baseUrl.replace(/^http/, 'ws')}/live/${camera}`
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const video = new JSMpeg.VideoElement(
|
|
|
|
|
playerRef.current,
|
|
|
|
|
url,
|
2021-06-13 22:21:20 +03:00
|
|
|
{},
|
2021-06-12 17:59:18 +03:00
|
|
|
{protocols: [], audio: false}
|
2021-06-12 17:55:40 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
video.destroy();
|
|
|
|
|
};
|
|
|
|
|
}, [url]);
|
|
|
|
|
|
|
|
|
|
return (
|
2021-06-13 22:21:20 +03:00
|
|
|
<div ref={playerRef} class="jsmpeg">
|
2021-06-12 17:55:40 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|