Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web LiveStreaming WebRTC and Sockets (Flask Backend)

I want to build a live streaming app. My thought process:

  1. Get the Video/Audio data from the navigator.mediaDevices.getUserMedia(constraints); [client-streamer]
  2. create rooms using sockets(Socket.IO or WebSockets from flask) [backend]
  3. Send the data in 1 to the room members using sockets.
  4. display the media on the client-side.

Is that correct? How should I do it?

how do I broadcast data to specific room members and not to everyone? (flask) How to consistently send data from the streamer -> server -> room members. the stream is given from 1 is an object, where is the data?

any other better ideas will be great! thanks.

  • I need to implement the server-side by myself without help from libraries that will do the work for me.
like image 622
Sahar Cohen Avatar asked Nov 04 '25 08:11

Sahar Cohen


1 Answers

Implementing a streaming platform is not trivial. Unfortunately, it is not as simple as emitting chunks received from the MediaRecorder with onndatavailable and forwarding them to users using a WebSocket server - this is not scalable nor efficient nor reliable.

Below are some strategies you can try for different types of scenarios:

P2P: If you want to have simple peer-to-peer streaming, you can use WebRTC to achieve that with a simple socket.io server for signaling purposes.

Conference: Here things start to get more complicated. You will need a media server if you want to be somewhat scalable. One approach is to route your stream to the users using an SFU or MCU. This will take care of forwarding/processing media to different peers efficiently.

Broadcast: Here things are also non-trivial. Common WebRTC-based architectures include ingesting the WebRTC stream and forward that to an HLS server which will let your stream chunks available for clients through a CDN, or perform RTP forwarding of the WebRTC stream, convert it to RTMP using something like FFmpeg and deliver it through Youtube Live or Twitch to leverage from their infrastructure.

Be aware that the last 2 items are resource-intensive and will certainly not be cheap to maintain.

Below are some open source projects that could help you along the way:

  • Janus
  • MediaSoup
  • AntMedia
  • Jitsi

Good luck!

like image 156
lnogueir Avatar answered Nov 07 '25 14:11

lnogueir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!