Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Stream audio/video with socket (.io) from node.js server to html5 page

I need to stream mp3 or mp4 from a node.js server and watch it on a html5 page. I am trying to use socket.io to sped up communications and i hope it will lower the latency that i have using simple http. I set up socket.io in my project, both on the client (mobile web application) and the server, but i can't figure out nor find on the web how to properly send data and lead it to a tag.

like image 297
Alessandro Annini Avatar asked May 23 '14 06:05

Alessandro Annini


People also ask

How do I connect Socket.IO to HTML?

// Require HTTP module (to start server) and Socket.IO var http = require('http'); var io = require('socket.io'); var port = 8080; // Start the server at port 8080 var server = http. createServer(function(req, res){ // Send HTML headers and message res. writeHead(200,{ 'Content-Type': 'text/html' }); res.

How do I connect Socket.IO to node JS?

In order to do it, you need to create an index. js file and install socket.io and express. You can use the following command: touch index. js && npm install express socket.io && npm install --save-dev nodemon .

Is NodeJS suitable for video streaming?

Nodejs is very good to streaming audio and video, but nodejs is a new technology, so it's don't have a lot of softwares yet.

How does Socket.IO work NodeJS?

The bidirectional channel between the Socket.IO server (Node. js) and the Socket.IO client (browser, Node. js, or another programming language) is established with a WebSocket connection whenever possible, and will use HTTP long-polling as fallback.


2 Answers

Try ffmpeg to make sync audio/video streaming. In HTML5 audio and video tag automatically play it when you give source address of server in src element of audio/video tag.

like image 115
Munam Tariq Avatar answered Oct 02 '22 19:10

Munam Tariq


please see socket.io-stream project https://www.npmjs.org/package/socket.io-stream

like image 27
Nikolay Lukyanchuk Avatar answered Oct 02 '22 18:10

Nikolay Lukyanchuk