littlelines / littlechat

A peer-to-peer video chat application made using Phoenix, LiveView, and WebRTC. Want to know how it's made? Read the blog post: https://littlelines.com/blog/2020/07/06/building-a-video-chat-app-in-phoenix-liveview
https://littlechat.app
MIT License
189 stars 21 forks source link

Are you using TURN server for group video? #12

Open iamonkara opened 4 years ago

iamonkara commented 4 years ago

@JesseHerrick

I am just trying to understand if you are using TURN server for group chats or somehow managing with just STUN servers

If just STUN servers then I am having hard time comprehending how is it working since STUN is only for peer to peer (AFAIK) or is it your app working like TURN server?

My guess is with combination of Phoenix Channels/PubSub & LiveView websockets somehow you are negating the need of TURN server. But again as I said I a kinda lost.

Please enlighten me or point me to the code responsibly for this magic.

JesseHerrick commented 4 years ago

Hi @iamonkara, have you had a chance to read this article? It might help you understand the design choices I made in this application.

To directly answer your question, peer-to-peer video calls through WebRTC are possible with only the use of a STUN server and no TURN server. In fact, under ideal circumstances (which, of course, are incredibly unlikely) one might even get away with no STUN server as well.

Currently, the app only uses a built-in STUN server because 1) it works in most cases and 2) the bandwidth of a TURN server might overwhelm the small DigitalOcean box we're running this app on. We may consider adding a TURN server to this application to make it more full-featured later on. Likewise, adding documentation on setting up a TURN server alongside this application would be an excellent enhancement to this application, so I'll add both of these suggestions to the backlog.

In case you're curious, the excellent stun Erlang library we make use of to serve the STUN server also provides a TURN server. Although I have not yet had an opportunity to test this, the code should be as simple as this on the server-side:

:stun_listener.add_listener({127, 0, 0, 1}, 3478, :udp, [{:use_turn, true}])

Additionally, one would need to add code on the client-side adding the TURN server.