From f1499f7811b188353eb85e65da8551faffece833 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Sat, 15 Oct 2022 14:04:54 -0600 Subject: [PATCH] Support webrtc --- docker/rootfs/usr/local/nginx/conf/nginx.conf | 8 ++++++++ web/src/components/WebRtcPlayer.jsx | 15 ++++++--------- web/src/routes/Camera.jsx | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docker/rootfs/usr/local/nginx/conf/nginx.conf b/docker/rootfs/usr/local/nginx/conf/nginx.conf index 9142b3cd2..670adb9b2 100644 --- a/docker/rootfs/usr/local/nginx/conf/nginx.conf +++ b/docker/rootfs/usr/local/nginx/conf/nginx.conf @@ -170,6 +170,14 @@ http { 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/ { proxy_pass http://jsmpeg/; proxy_http_version 1.1; diff --git a/web/src/components/WebRtcPlayer.jsx b/web/src/components/WebRtcPlayer.jsx index cf8edf634..6edf25af6 100644 --- a/web/src/components/WebRtcPlayer.jsx +++ b/web/src/components/WebRtcPlayer.jsx @@ -3,11 +3,11 @@ import { useRef, useEffect } from 'preact/hooks'; let ws; -function initStream() { - console.log('Doing a thing'); - ws = new WebSocket('ws://127.0.0.1:1984/api/ws?src=garage_cam'); +function initStream(camera) { + //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 = () => { - console.log('ws.onopen'); + console.debug('ws.onopen'); pc.createOffer().then(offer => { pc.setLocalDescription(offer).then(() => { 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 => { const msg = JSON.parse(ev.data); - console.log('ws.onmessage', msg); + console.debug('ws.onmessage', msg); if (msg.type === 'webrtc/candidate') { pc.addIceCandidate({candidate: msg.value, sdpMid: ''}); @@ -65,7 +62,7 @@ function initStream() { } export default function WebRtcPlayer({ camera, width, height }) { - initStream(); + initStream(camera); return (