Web Radio Creation Through Node.js - node.js

I wanted to create my own web radio in node.js, which will include a functionality to create a library by admin. this library will holds sngs in it. while my songs get picked on backend and played on frontend to all connected users. How can I do it?

You're question is very broad. but am going to answer the part of audio stream
as below
on you're node js server install a package called wrtc which will receive stream from producer and broadcast that stream to other peers which peers uses normal browser/mobile webrtc endpoints

Related

WebRTC through host with nodeJS express and socketio

I created a web app to let people communicate. I want to implement screen sharing and audio calls.
My current app is programmed in NodeJs and uses express and socket.io to serve the client connection and open a socket connection. I want to stream video and audio. My problem with WebRTC is that all those who connect to a call are vulnerable to a DDoS attack since it is p2p. I found an article from Discord explaining how they managed to let the entire traffic go through their servers: https://blog.discord.com/how-discord-handles-two-and-half-million-concurrent-voice-users-using-webrtc-ce01c3187429, that's exactly what I want to achieve.
Could I possibly use socket.io-stream https://www.npmjs.com/package/socket.io-stream ? I didn't yet figure out how, and it seems like all socket.io streaming libraries are made for file upload/download, not for actual video/audio streaming.
If that doesn't work, a library such as what Discord managed to make would be the perfect solution, since all traffic is proxied, and not p2p. Though I couldn't find any of those libraries, maybe I'm just looking for the wrong thing?
Best regards
You will want to use a SFU.
Each peer negotiates a session with the SFU. They then exchange media through it. Each Peer will just communicate with the server. It has lots of other benefits and is what most WebRTC deploys today use.
There are lots of Open Source SFUs out there. You can even build your own with Open Source libraries.

Is data traffic made via WebRTC measured on a platform like Heroku for example?

I want to build a Facetime clone app using NodeJS, ReactJS and WebRTC.
I am new to WebRTC and I don't know how data is transferred between clients.
My question is that if I will deploy the app on a platform like Heroku, the data transferred via video call is measured by Heroku ? That will mean huge costs to make some realtime video calls
WebRTC is peer-to-peer so would not use your Heroku data for the audio/video. Just for the matching, signing up, etc. The peers (web browsers) connect to each other and pass data directly.
However, WebRTC can only handle so many connected clients before each client cannot keep up. So a server system that relays the videos or mirrors the video (itself acting as one of the peers) would use bandwidth. But for only two videos, peer-to-peer should be ok assuming the client's bandwidth is sufficient.

What is the best solution for Live-cam Service in web application?

I am trying to setup a web-based Live webcam streaming service(Using laravel framework php) where a user can broadcast live via webcam (Web based Only).
For example:
User X Starts a webcam-Broadcast at http://localhost/userx while Users Y,Z etc join that room on http://localhost/userx will be able to watch the live webcam/stream.
I was playing around with node.js and socket.io library for realtime chat and it works fine.
But I have no idea about webcam streaming.
Should i use webrtc? How many viewers can handle the broadcaster if i use Webrtc ?
What is best solution for handling around 1000-2000 viewers?
Any suggestion would help me a lot.
Why not use the node-camera module which enables you to access and stream web camera in nodejs using opencv and websockets.
This the command you should run in order to run it:
npm start -- [-open] [-wsport websocketPort] [-webport webserverport] [-res widthxheight]
where the options passed to run it are:
-open Open streaming url on startup
-wsport Web socket port for streaming media
-webport Web server port
-res Resolution for preview image
-input Input source. ( eg. ip camera url)
There are few more libraries such as ffmpeg, vlc and OpenCV which are available using webcam access that can be written as node's native addon

how to distribute socket.io

Im using nodejs and socket.io to deliver a chat on my business app, but i want to distribute the deploy so i can have as many chat servers i want to balance the load of the traffic.
I try the load balance approach from nginx but that just do that balance the traffic but the communication between the socket.io serves its not the same, so one chat message send from user A to server S1 wont travel to user B on server S2.
There is any tool or approach to do this.
Thanks in advance.
===== EDIT =====
Here is the architecture of the app.
The main app frontend on PHP CodeIgniter lets tag it as PHPCI
The chat app backend on NodeJs and SocketIO lets tag it as CHAT
The chat model data on Redist lets tag it as REDIST
So what i have now its PHPCI -> CHAT -> REDIST. That work just fine.
What i need is to distribute the application so i can have as many PHPCI or CHAT or REDIST i want, example
PHPCI1 CHAT1
PHPCI2 -> -> REDIST1
PHPCI3 CHAT2
Where the numbers represent instances not different apps.
So a User A connected to PHPCI1 can send a message to a user B connected on PHPCI3.
I think some queue in the middle of CHAT can handle this something like rabbitmq that can only use the SocketIO to deliver the messages to the client.
If you're distributing the server load (and that's a requirement), I'd suggest adding a designated chat data server (usually an in-memory database or message queue) to handle chat state and message passing across edge servers.
Redis Pub/Sub is ideal for this purpose, and can scale up to crazy levels on even a low-end machine. The Redis Cookbook has a chapter on precisely this use case.
If you set up the server-side of your chat app correctly, you shouldn't have to distribute socket.io. Since node.js is browser-based and doesn't require any client-side code (other than the resources downloaded from the webpage), it works automatically. With a webpage, the files required to run socket.io are temporarily downloaded to users when they are correctly included (just like with jQuery). If you are using node.js and socket.io to make an android app, the files should be included in your application when you distribute it, not separately.
In addition, if you wish to use two separate socket.io servers, you should be able to establish communication between the two by connecting them in a similar manner that a client connects to the server, but with a special parameter that lets the other server know that a server connected and it can respond and set a variable for the other server.

how we will know on the server side if the peer still connected using Nodejs WebRTC

I am using WebRTC to make a audio, video and chat application. How on the server side we can check if the peer is still connected.
Actually, I want to check before making audio/video call that the other user end is still connected. I am able to maintain Presence (i.e online/offline) when user logs in or logs out of the application.
Suppose, the network connection drops or got disconnected, I am not able to get any information on the server side. If I can get, then I can communicate to rest of the peers connected.
So, need help how to get the information if the peer is still connected or not. I am using Nodejs and WebRTC in my application.
Socket.IO has a concept of 'rooms' that makes it very handy for building WebRTC signaling servers, and a disconnect event fired when a user disconnects. You can also set up a custom event to be emited when, for example, a user stops a video stream or leaves a page.
You might want to take a look at the codelab at bitbucket.org/webrtc/codelab, which uses Socket.IO for signaling. (Apologies, once again, for shameless self promotion!)
You would need to implement your own logic to do that.
Since you already have the client registering presence you could:
maintain a persistent connection via websockets
implement a polling/keep alive algorithm between your clients and server

Resources