WebRTC icon indicating copy to clipboard operation
WebRTC copied to clipboard

WebRTC Card with external go2rtc server

Open rsurgiewicz opened this issue 11 months ago • 6 comments

Hi there,

I'm pulling my hair out because I'm out of ideas ...

I have go2rtc server in docker localIP: 192.168.5.105 I set-up one input rtsp stream named tapo1 I can access GUI and open links with stream.html via browser etc.

My Home assistant instance is 192.168.5.55 I added custom component to homeassistant manually. I've placed webrtc directory and addedd necessary .js to lovelace includes.

I've tried a number of configurations but none of them worked. All I get is player widget with loading...

Examples that I've tried:

1

 - type: 'custom:webrtc-camera'
    url: 'tapo1'
    server: http://192.168.5.105:1984/

2

 - type: 'custom:webrtc-camera'
    url: 'rtsp://user:[email protected]:554/stream1'
    server: http://192.168.5.105:1984/

3

 - type: 'custom:webrtc-camera'
    url: 'http://192.168.5.105:1984/api/stream/webrtc?src=tapo1'

This is the result:

Image

Opening developer console I can see entries:

video-rtc.js?v=1.9.4:303 WebSocket connection to 'ws://192.168.5.**55**:8123/api/webrtc/ws?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI3ZTUyMWVlN2QxZjM0OWU2ODk0NmNjM2Q3Y2I4NzYxMCIsInBhdGgiOiIvYXBpL3dlYnJ0Yy93cyIsInBhcmFtcyI6W10sImlhdCI6MTczODI2MjM3OCwiZXhwIjoxNzM4MjYyNDA4fQ.fYOUrLq5jaf2hfgFxc0-46YLDlKexglhLiD5pUnITnY&url=http%3A%2F%2F192.168.5.105%3A1984%2Fstream.html%3Fsrc%3Dtapo1%26mode%3Dwebrtc' failed:

So it looks like it tries to connect to home assistant instance despite server directive?

Is it a bug or am I doing something wrong?

rsurgiewicz avatar Jan 30 '25 18:01 rsurgiewicz

Your configs 1 and 2 are correct. They should work. Your config 3 is incorrect. You are showing an error for this particular config.

AlexxIT avatar Jan 31 '25 10:01 AlexxIT

Is there any update on this issue?

I'm experiencing the same problem. I'm running both Home Assistant and Go2RTC in docker, and while I can access the streams directly through Go2RTC from browser, they don't work in Home Assistant.

I've tried multiple versions of Go2RTC and WebRTC (including the current master branch) and also tested different WebRTC setups, but the result is always the same - just a black screen with a "Loading..." message in Home Assistant.

I also ran tcpdump and noticed that there's no ongoing communication between Home Assistant and the Go2RTC server. There's only a brief exchange of packets when I first set the server address (Add entry) in Home Assistant, but after that, the connection closes gracefully and nothing further is transmitted, even when viewing the dashboard with the WebRTC camera card.

Could you please help me figure out how to debug this issue?

OttoHollmann avatar Apr 18 '25 16:04 OttoHollmann

You should check browser dev tools. For example error from original post:

/api/webrtc/ws?authSig=***&url=http%3A%2F%2F192.168.5.105%3A1984%2Fstream.html%3Fsrc%3Dtapo1%26mode%3Dwebrtc

  • has wrong url param
  • doesn't have server param

AlexxIT avatar Apr 19 '25 11:04 AlexxIT

Thank you for the suggestion! I found that the issue was caused by a misconfigured Nginx.

I initially had only these two location blocks:

location / { ... }
location /api/websocket { ... }

As a result, /api/webrtc was unreachable.

After fixing this Nginx configuration, I'm now able to see the camera stream, and at first glance, everything seems to be working well.

OttoHollmann avatar Apr 23 '25 18:04 OttoHollmann

@OttoHollmann I experienced the same issue and tried to setup a Nginx service in docker to redirect the go2rtc endpoint. However, the websocket still cannot be reached. May I have some suggestion on the Nginx configuration?

junlingf avatar Apr 26 '25 22:04 junlingf

Sorry for the confusion — I was referring to the NGINX configuration for Home Assistant. I had only enabled the api/websocket endpoint, but for WebRTC to work, you need to expose the /api/webrtc endpoint. So your homeassistant.example.com/api/webrtc should be accessible.

If I understand correctly, you're trying to set up an NGINX reverse proxy for go2rtc. If that's the case, you might find this issue helpful: https://github.com/AlexxIT/go2rtc/issues/542 But unless you have a specific reason, you probably don't need to set up a reverse proxy for go2rtc. Go2rtc will be accessed only by Home Assistant.

OttoHollmann avatar Apr 27 '25 07:04 OttoHollmann