Skip to content

Instantly share code, notes, and snippets.

@danfinlay
Created May 7, 2013 20:00
Show Gist options
  • Save danfinlay/5535637 to your computer and use it in GitHub Desktop.
Save danfinlay/5535637 to your computer and use it in GitHub Desktop.
Trying to serve a video stream with low capacity to more users. I haven't really used streams before. This was my best guess, but I'm sure there's some fundamental problem. The error this throws is: "You cannot pipe after data has been emitted from the response."
var request = require('request')
var r = request('http://my-video-stream-url', function(err, response){
if(err){
console.log("Request had error: "+err)
}else{
http.createServer(function(request, response) {
response.setHeader('Content-Type', 'image/jpeg');
response.setHeader('Accept-Ranges', 'bytes');
r.pipe(response)
r.on('end', function(){
response.end()
})
}).listen(3021);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment