Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broadcast web cam with socket.io?

I can get stream from browser with these lines of code:

var socket = io.connect('127.0.0.1:9000');
navigator.getUserMedia  = navigator.getUserMedia ||
                          navigator.webkitGetUserMedia ||
                          navigator.mozGetUserMedia ||
                          navigator.msGetUserMedia;


var cam;
navigator.getUserMedia({video: true, audio: true}, function(stream) {
    //var call = peer.call('another-peers-id', stream);
        //call.on('stream', function(remoteStream) {
        // Show stream in some video/canvas element.
    //});
    cam = stream;
    console.log(stream);
}, function(err) {
    console.log('Failed to get local stream' ,err);
});

Now I want to send live stream to socket.io server and then broadcast it with socket.io server.
Is there any simple code to do it ?

like image 492
Soroush Khosravi Avatar asked Jun 26 '14 13:06

Soroush Khosravi


People also ask

Can I use Socket.IO for video streaming?

Using the WebRTC protocol, we can stream video in addition to audio and simply pipe it into an HTML video element instead of an audio element. In this recipe, we will create a peer-to-peer connection where we can allow two users to chat using live video.

Does Socket.IO use WebRTC?

Socket.IO P2P provides an easy and reliable way to setup a WebRTC connection between peers and communicate using the socket. io-protocol.

What is Socket.IO broadcasting?

Broadcasting means sending a message to all connected clients. Broadcasting can be done at multiple levels. We can send the message to all the connected clients, to clients on a namespace and clients in a particular room.

Should I use Socket.IO or WebSockets?

As said before, Socket.IO can fall back to technologies other than WebSockets when the client doesn't support it. If (for some reason) a WebSocket connection drops, it will not automatically reconnect… but guess what? Socket.IO handles that for you! Socket.IO APIs are built to be easier to work with.


1 Answers

I tried for a few days to get something like this working, and after going down the rabbit hole I ended up just firing up an instance of Wowza media server on AWS (following these instructions) and managing the server with my node instance instead of trying to do the video.

It worked beautifully. Scales well (auto-scaling even), relatively easy to deploy, and has great support on their forums. A++, would code again.

Also, ultimately you're probably going to need to do some transcoding/scaling/watermarking if this is to be a commercial project, and Wowza leverages NVENC on the GPU on Amazon's graphics instances, which just blows anything else out of the water.

like image 195
Delaney Avatar answered Nov 15 '22 21:11

Delaney