Use go2rtc for camera config

This commit is contained in:
Nick Mowen 2022-10-13 17:06:43 -06:00
parent 82bfd8fd5d
commit 0b08c254d3
2 changed files with 35 additions and 10 deletions

View File

@ -44,7 +44,7 @@ http {
keepalive 1024; keepalive 1024;
} }
upstream go2rtc_api { upstream go2rtc {
server 127.0.0.1:1984; server 127.0.0.1:1984;
keepalive 1024; keepalive 1024;
} }
@ -178,8 +178,16 @@ http {
proxy_set_header Host $host; proxy_set_header Host $host;
} }
location /restream/ { location ~ /restream/(.*)$ {
proxy_pass http://go2rtc_api/; proxy_pass http://go2rtc/api/stream.mp4?src=$1;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /go2rtc/ {
proxy_pass http://go2rtc/;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade"; proxy_set_header Connection "Upgrade";

View File

@ -13,6 +13,7 @@ import { usePersistence } from '../context';
import { useCallback, useMemo, useState } from 'preact/hooks'; import { useCallback, useMemo, useState } from 'preact/hooks';
import { useApiHost } from '../api'; import { useApiHost } from '../api';
import useSWR from 'swr'; import useSWR from 'swr';
import VideoPlayer from '../components/VideoPlayer';
const emptyObject = Object.freeze({}); const emptyObject = Object.freeze({});
@ -93,13 +94,29 @@ export default function Camera({ camera }) {
let player; let player;
if (viewMode === 'live') { if (viewMode === 'live') {
player = ( if (cameraConfig.restream.enabled) {
<Fragment> <VideoPlayer
<div> options={{
<JSMpegPlayer camera={camera} width={liveWidth} height={cameraConfig.live.height} /> preload: 'auto',
</div> autoplay: true,
</Fragment> sources: [
); {
src: `${apiHost}/restream/${camera}`,
type: 'video/mp4',
},
],
}}
onReady={() => {}}
/>
} else {
player = (
<Fragment>
<div>
<JSMpegPlayer camera={camera} width={liveWidth} height={cameraConfig.live.height} />
</div>
</Fragment>
);
}
} else if (viewMode === 'debug') { } else if (viewMode === 'debug') {
player = ( player = (
<Fragment> <Fragment>