Support webrtc

This commit is contained in:
Nick Mowen 2022-10-15 14:04:54 -06:00
parent a3b21d448a
commit f1499f7811
3 changed files with 15 additions and 10 deletions

View File

@ -170,6 +170,14 @@ http {
proxy_set_header Host $host; proxy_set_header Host $host;
} }
location /restream-ws/ {
proxy_pass http://go2rtc/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
location /live/ { location /live/ {
proxy_pass http://jsmpeg/; proxy_pass http://jsmpeg/;
proxy_http_version 1.1; proxy_http_version 1.1;

View File

@ -3,11 +3,11 @@ import { useRef, useEffect } from 'preact/hooks';
let ws; let ws;
function initStream() { function initStream(camera) {
console.log('Doing a thing'); //ws = new WebSocket('ws://127.0.0.1:1984/api/ws?src=garage_cam');
ws = new WebSocket('ws://127.0.0.1:1984/api/ws?src=garage_cam'); ws = new WebSocket(`ws://${window.location.hostname}:${window.location.port}/restream-ws/api/ws?src=${camera}`);
ws.onopen = () => { ws.onopen = () => {
console.log('ws.onopen'); console.debug('ws.onopen');
pc.createOffer().then(offer => { pc.createOffer().then(offer => {
pc.setLocalDescription(offer).then(() => { pc.setLocalDescription(offer).then(() => {
console.log(offer.sdp); console.log(offer.sdp);
@ -16,12 +16,9 @@ function initStream() {
}); });
}); });
} }
ws.onerror = e => {
console.log("There was a ws error " + e.type);
}
ws.onmessage = ev => { ws.onmessage = ev => {
const msg = JSON.parse(ev.data); const msg = JSON.parse(ev.data);
console.log('ws.onmessage', msg); console.debug('ws.onmessage', msg);
if (msg.type === 'webrtc/candidate') { if (msg.type === 'webrtc/candidate') {
pc.addIceCandidate({candidate: msg.value, sdpMid: ''}); pc.addIceCandidate({candidate: msg.value, sdpMid: ''});
@ -65,7 +62,7 @@ function initStream() {
} }
export default function WebRtcPlayer({ camera, width, height }) { export default function WebRtcPlayer({ camera, width, height }) {
initStream(); initStream(camera);
return ( return (
<div> <div>
<video id='video' autoplay playsinline controls muted width={width} height={height} /> <video id='video' autoplay playsinline controls muted width={width} height={height} />

View File

@ -123,7 +123,7 @@ export default function Camera({ camera }) {
player = ( player = (
<Fragment> <Fragment>
<div> <div>
<WebRtcPlayer width={liveWidth} height={cameraConfig.live.height} /> <WebRtcPlayer camera={camera} width={liveWidth} height={cameraConfig.live.height} />
</div> </div>
</Fragment> </Fragment>
) )