2
votes

I'm going to create a website where one Admin will stream his live webcam to multiple Viewers. I've spent few days googling about WebRTC and Websocket solutions, but still feel confused. People say WebRTC is the only sane way, but...

What I got from google, please correct me if I'm wrong:

  1. WebRTC is used mostly for p2p connections, which means my 'Admin' won't be able to have many (say, 50+) viewers -- simply because his 50M internet will start lagging, trying to stream 50x p2p at once;

  2. I'd like to process the video (on the fly!) from Admin _asap_but_before_ showing it to Viewers (i.e. make some overlays or embed another video into the main one) -- that's another problem with p2p, isnt it?

So, at this point I'm pretty sure I should rather use Websockets instead of WebRTC. Maybe I'm missing something important? Could you please suggest me any NotExtremelyComplicated solutions for this?

Thank you

1

1 Answers

3
votes

Everything you said is correct! If you connect P2P from the Admin to all viewers you will probably hit an upper limit, since you need to upload for each viewer. What you want to do is use an SFU instead. You could also do the processing/overlays on the server.

An SFU is a server that sits in the middle and acts as a 'repeater' so the Admin only uploads once. The topology would look like

               |----> Viewer
               |
Admin ---> SFU |----> Viewer
               |
               |----> Viewer

There are lots of SFU implementations, each have their own ups/downs. I am happy to help if you have questions about Pion WebRTC. It is the Go implementation of WebRTC, and we have an example of how to build a minimal-sfu.


You could also build this via Websockets, but you may have latency issues. I haven't done it myself, but I believe it is possible via the MSE API.

The nice thing about WebRTC is that you get bi-directional media and data, and you don't have to do much coding. Then on top of that WebRTC has some nice things like Congestion Control (WebRTC will shrink/grow the bitrate to accommodate your available bandwidth). While with Websockets it is much harder to handle stuff like this.