IggY
IggY

Reputation: 3125

NodeJS/ExpressJS : proxy an HTTP video stream (from VLC)

With VLC 2.2.1 I create an HTTP stream of my webcam hosted by a computer named server.

On another computer, client, if I open vlc, and open the network stream http://server:8080 I can see the webcam video perfectly.

A wireshark capture of the HTTP stream look like the following :

GET / HTTP/1.1
Host: server:8080
User-Agent: VLC/2.2.0-rc2 LibVLC/2.2.0-rc2
Range: bytes=0-
Connection: close
Icy-MetaData: 1

HTTP/1.0 200 OK
Content-type: application/octet-stream
Cache-Control: no-cache

FLV.......................
[email protected].@~.......
videodatarate.@[email protected][email protected]..
Lavf56.1.0..filesize....
etc...

On the client computer, I have an API running under NodeJS v5 & Express v3 and I'd like to have an url like : http://client/video that act as a proxy to http://server:8080 so the users can only see one endpoint.

I saw few npm module claiming to act as "proxy" but due to the special nature of the content (live video stream) I'm not sure of what I should do.

Upvotes: 3

Views: 3187

Answers (1)

konsumer
konsumer

Reputation: 3503

var express = require('express')
var fetch = require('node-fetch')

var app = express()

app.get('/video', (req, res) => {
  fetch('http://server:8080')
    .then(r => r.body)
    .then(s => {
      s.pipe(res)
    })
    .catch(e => {
      res.status(500).send('Error.')
    })
})

app.listen(80)

to open up port 80, you'll need to be root, so run with sudo

Upvotes: 2

Related Questions