简体   繁体   中英

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.......................
onMetaData.......duration...........width.@.........height.@~.......
videodatarate.@.@.......videocodecid.@.........encoder..
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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM