Building one to many live streaming platform - node.js

I want to build a one to many users streaming app where admin can stream video and users can view that video in live. I have to use node.js. which is best approach and what are good tools for that.
Does using webrtc one to many affect performance at large scale?
Suggestions please...
Thanks

given my extensive experience in the subject and the use of many WebRTC libraries, I would recommend that you use an SFU or MCU where you can cover high-level conferences on a large scale, I do not recommend the use of WebRTC one to one due to you'll no doubt have a lot of performance issues.
My recommendation is that you use an SFU or MCU library, for example:
https://github.com/livekit/livekit
LiveKit is easy to use, great scalability (depends on your server), it has tools to measure the server so you know if you need a better one, it also has many server-side and client-side SDKs such as: Javascript, ReactNative, Flutter, Android and Server Side: PHP, Nodejs, Etc.
It also allows you to have total control of the room, who can enter a room, who can broadcast, etc.
I hope my answer helps you.

Related

Should I use webRTC alongside Socket.IO if I want a live chat ability beside the real-time video streaming?

What I am trying to do is to create a simple virtual classroom project like Adobe connect, but obviously simpler, using Flutter and NodeJS, and I need the following options:
Real-time video or only voice streaming
Live chat box
Screen sharing ability
File sharing ability(Like PDF or PowerPoint or other text/doc files)
Whiteboard
As I searched so far I found that it seems WebRTC works for video/voice streaming and also screen sharing as well.
Also most of the livechat projects using Socket.IO.
My main question here is to know can I use only WebRTC for both real-time video/voice streaming and also live chat as well? Is it a good idea or it's better to combine Socket.IO and WebRTC together?
Furthermore I want to know can I use each of those libraries for File-Sharing purposes?
WebRTC gives you lower latency and a lot of functionality for conferencing out of the box. So for video/audio calls and screen sharing this is definitely a better choice.
Also, there's an option to use p2p communication which reduces latency even more and saves you resources on the server-side. Though if you intend to support many participants it looks less beneficial - you will need to maintain n-1 connections for each user if you have n users in total.
For live chat, whiteboard and file sharing there would be no big difference in terms of performance.
Things to consider:
WebRTC is more complex technology than websockets to setup and support
There might be opensource solutions for this features, i would make a decision based on what you can reuse in your project
You can use WebRTC for some of the features and websockets for others
can I use only WebRTC for both real-time video/voice streaming and
also live chat as well
Yes you can, there's a RTCDataChannel interface for exchanging arbitrary data. It can be used for live chat / whiteboard / file transfer.
As a good example, there's an opensource project peercalls, that implements chat and file transfer via WebRTC through the same connection that is used for conferencing.
Websockets can be used for file transfer as well, check out this library.
Using WebRTC requires signaling server and signaling is often implemented using websocket, check this mdn article Signaling and video calling
And with websocket you can implement livechat too, so it is not an either or situation but both quite often.

Technology advice for mobile application

I would like to develop a mobile game, kind of like an interactive ARG.
The players would see POI-s on a map, and they can interact with them in various ways. Some interactions on a POI should be visible to other players real time, and players should receive push notifications when a new POI appears in their area.
Up until now, I mostly worked with web technologies, so I figured a Node.js for backend, and a React Native for the application would be nice choices and I could learn both along the way. Since I have little experience with both, and don't really know about their capabilities performance-wise.
Are these technologies a good choice for an application like this? Is there a reason to go full native iOS/Android instead of React Native?
Could Node.js and React Native handle like 1-200k players daily? (It will probably never get there, lol)
I know it's just a pet project, but I'm interested in what would be the "industry standard" stack for something like this?
I would think using React native should be fine for this genre of game for your frontend/client. Where it seem to involves a lot of point click, drag and drop, present player with information. If more real time rendering and interactivity then you may need to use a library/framework that are suitable for more real time rendering and interactivity.
As for the backend using Node.js is fine for handling your data requests. For scaling to support lots of user, then that's quite a big topic that you'll need to work out. You'll typically have to look at how complex your data/requests are and so how much your server can handle the load. From there you will need to load balance on multiple servers.
For game or any type of application, where you need a backend it's very similar in needs. You'll use a language that's best for backend development and performance. From there you have to serve it and scale accordingly base on your loads. You can leverage AWS or other cloud providers to do a lot of these.
Hopefully this answer some of the things you're asking for.

On the performance of an audio live streaming application

I would like to develop an application that will allow a user to live streams audio from his computer and broadcast it through the network.
My main concern is the performance of this application. I want the quality of the sound to be preserved as its highest and I would like as few "delay" as possible.
Can I reach such a level of performance with web-based languages such as AJAX, NodeJS, or Ruby (Ruby on Rails?) or should I consider more low-level languages such as C/C++?
Thanks!
The performance of sound of the application is not affected so much by the language you choose. That level of performance is achieved by using the correct protocols to send the audio stream over the network. One common mistake is to use HTTP which user TCP protocol because is has a lot of certificates to be verified and this delay the information from streaming live. The best protocol which is used by all big stream companies like Facebook, Instagram, Skype, Lync is the UDP protocol which is super fast because of the minimum level of certificates to be checked.
The companies mentioned above uses different programming languages in order to build the streaming servers and get almost the same results so this is my opinion that the protocol makes the difference.
You can use Java if you want, I have friends that work for 8x8 one of the best companies of live streaming in the USA and they have used JAVA for building the servers and the clients.

Stream WebCam using socket.io

I have been trying to implement a web application that will be able to handle following scenario:
Streaming video/audio from a client to other clients (actually a particular set of them, no broadcasting) and server at the same time. The data source would be a webcam of the client.
This streamed data has to be displayed in the real time on the other clients' browser and be saved on the server side for the 'archiving' purposes.
It has to be implemented in node.js + socket.io environment.
To put it in some more specific context... The scenario is that there is a guy that makes a kind of a room for the users that he chooses. After the chosen users join the room, the creator starts streaming video/audio from his/her built in devices (webcam). All of the guests receive the data in real time, moreover the data is being sent to the server where it is stored so it can be recovered after the stream and room get closed.
I was thinking about mixing Socket.IO with WebRTC. In theory the combination of these two seem just perfect for the job.
The Socket.IO is great for gathering specific set of users by assigning some sockets to a room and for signaling process demanded by the WebRTC.
At the same time WebRTC is awesome for P2P connection between users gathered in the same room, it is also really easy to get access to the webcam and other built in devices that I might want to use.
So yeah, everything is looking pretty decent in theory but I would really need to see some code in action so I could actually try to implement it on my own. Moreover, I see some issues:
How do I save the stream that is sent by the P2P connection? Obviously server does not have access to that. I was thinking that I might treat the server as another 'guest', so it would be just another endpoint of the P2P connection with the creator of the room. Somehow it feels edgy, though.
Wouldn't it be better to treat server as the middleman between the creator and the clients? At one point there might be some, probably insignificant, delay comparing to P2P but presumably it would be the same for all the clients. (I tried that but I can't get the streaming from webcam to the server done, that's however is the topic for a different question as I am having problems with processing the MediaStream)
I was looking for some nice solutions but without any success. I have seen that there is this nice P2P solution made for socket.io: http://socket.io/blog/socket-io-p2p/ . The thing is - I don't think it will handle the data stream well. The examples mention only simple chat app and I need something a little bit heavier than that.
I would be really thankful for some specific examples, docs, whatever may lead me a little closer to the implementation of it as I really don't know how to approach it.
Thanks in advance :)
You task can be solved by using one of the open source WebRTC-servers.
For example, kurento.
You can realize schemas of stream:
One to one
One to many
Many to many
WebRtc-server schema
Clients will connect to each other through the WebRTC server.
So, on server side you can record the stream, or send it for transcoding.
webSocket is used for communicating with server.
You can find some examples according to your task
Video streaming to multiple users is a really hard problem that unfortunately requires extensive infrastructure to achieve. You will not be able to stream video data through a websocket. WebRTC is also not a viable solution for what you are describing because, as you mentioned, the WebRTC protocol is P2P, as in the streaming user will need to make a direct connection to all the 'viewers'. This will obviously not scale beyond a few 'viewers'. WebRTC is more for direct video calls like in Skype for example.
Here is an article describing the architecture used by a somewhat popular live streaming service. As you can see achieving live video at any sort of scale will require considerable resources.

Real-time newsfeed for followers - which tools and languages?

I want to implement newsfeed for followers just like Twitter in realtime. But I'm stucked which tools will be the best for my purposes. The solution (complexed solution) should be production-ready. I've tried node.js + socket.io + rabbitmq (node-ampq, rabbitJS), but node frequently crashes... Another solution is Tornado + sockJS-tornadio, but I'm unsure (and know Python not good). Before diving into code, I just need to know which tools are ebst for my purposes and can be 'really' realtime. By 'really' I mean trully fast request-responses. I've tried RabbitMQ + PHP API + Ajax, but it's not 'really' realtime, it uses ajax instead of, for example, websockets.
The data for newsfeed will be like 'John updated its profile', 'Doe uploaded new file' and something similar.
Thanks!
What sort of crashes are they? Node has been fairly stable for some time now, at least for me.
Node is a fine solution, but you introduce some amount of complexity with communication between Node and PHP (which you look to want to solve with RabbitMQ). "Really" realtime can be easily accomplished with socket.io, and since it has multiple fallbacks is ideal for getting a wide audience. Long polling and friends do have their overhead but it isn't too much if the events aren't very frequent.
If it's easier for you to integrate the newsfeed into your PHP program and you are willing to accept the minor overhead I say go for it. Otherwise, I would invest in Node. The platform is still young, but it's matured well, IMO.
I just build a realtime web application.Users can drag items and chat in the same page.and I use tornado + jquery pending + redis as a MQ system.It works good, but I am considering to try socket.io to handle realtime requests.
tornado is kickass in terms of performance, and really easy to work with. the only problem is that you need to make sure you have adapters for databases and other blocking-by-nature sources you need to communicate with. It supports websocket of course so you can stream data to users.
If I had to implement this today, the stack I'd use is:
Redis for the data and pub/sub on channels.
Tornado as the API server.
WebSocket for the communication layer wherever possible.

Resources