go2rtc icon indicating copy to clipboard operation
go2rtc copied to clipboard

WebRTC - TURN server support

Open dlavrantonis opened this issue 3 years ago • 7 comments

First of all thanks for this amazing module! If possible please clarify the below.

TURN is marked as todo. I still tried the example configuration in the README and I noticed the following:

  • When trying to access a stream via the http api of go2rtc(port 1984) it looks like it works fine. Stream loads either via a peer to peer connection or via getting relayed by a coturn server I have set up.
  • When trying to access the same stream via home assistant (i.e. an IP camera) it fails to load.

the configuration I'm talking about is this one:

webrtc:
  ice_servers:
    - urls: [stun:stun.l.google.com:19302]
    - urls: [turn:123.123.123.123:3478]
      username: your_user
      credential: your_pass

Home assistant binding seems to be ok, camera entities appear as streams in go2rtc http api automatically.

Is home assistant integration still under development? If yes ill try to dig in the code and help.

dlavrantonis avatar Sep 24 '22 21:09 dlavrantonis

TURN is marked as todo because I haven't test it. I don't understand what you mean about "access the same stream via home assistant".

AlexxIT avatar Sep 24 '22 21:09 AlexxIT

I have "binded" my home assistant with go2rtc by following this instruction:

"Hass > Settings > Integrations > Add Integration > RTSPtoWebRTC > http://127.0.0.1:1984/"

my cameras have automatically appeared in go2rtc web page (localhost:1984) When selecting "webrtc" to view the cameras in go2rtc web page it works. When trying to view the same camera (=the same stream) via the lovelace card of hass, it fails to load.

Hope its clear now!

Note: I'm using the latest version downloaded from docker hub

dlavrantonis avatar Sep 24 '22 21:09 dlavrantonis

There is bug after latest update. You need to restart integration or Hass

AlexxIT avatar Sep 25 '22 04:09 AlexxIT

Tried both. Issue remains as is. Shall I share any logs?

dlavrantonis avatar Sep 25 '22 07:09 dlavrantonis

Yes. You need to find problem via logs

AlexxIT avatar Sep 25 '22 07:09 AlexxIT

I was looking into using go2rtc with TURN as well. As I understand it (and I'm very new to WebRTC), both clients (go2rtc and JS frontend) need to know and configure what TURN servers to try.

As far as I can tell, the default webrtc player in HA does not support TURN (or STUN) configuration. Nothing is passed to the RTCPeerConnection constructor. There are a few PRs associated with adding STUN support: https://github.com/home-assistant/frontend/pull/12084, https://github.com/home-assistant/core/pull/72574

The AlexxIT/WebRTC component did support TURN, it passed the ICE server info appropriately in the RTCPeerConnection constructor. I'm not sure that component supports connecting to go2rtc.

I'm actually surprised TURN worked within the default webapp that go2rtc provides. I don't see where it sets up the TURN servers in the RTCPeerConnection constructor.

Please let me know if I'm mistaken in anything above, I'm still trying to work my way through the various code bases, trying to understand webrtc more.

dougnd avatar Sep 26 '22 00:09 dougnd

I think only one will be enough. Because with integrating WebRTC Camera, I only tested TURN on the JS side.

AlexxIT avatar Sep 26 '22 04:09 AlexxIT

I have tested TURN server and it's work as it should.

AlexxIT avatar Nov 04 '22 18:11 AlexxIT