diff options
author | Georges-Etienne Legendre <legege@legege.com> | 2013-02-04 13:39:06 -0500 |
---|---|---|
committer | Georges-Etienne Legendre <legege@legege.com> | 2013-02-04 13:39:06 -0500 |
commit | 91736294567db46f2f309f53c42f287622e21591 (patch) | |
tree | 0878000735dccb01e2baf67531636acb5dae33d1 /node-mjpeg-proxy.js | |
parent | cfe2dbe5bb3bbb87ac7ab29390a30d8f592391f3 (diff) |
A module version of this application, with express.js
Diffstat (limited to 'node-mjpeg-proxy.js')
-rw-r--r-- | node-mjpeg-proxy.js | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/node-mjpeg-proxy.js b/node-mjpeg-proxy.js deleted file mode 100644 index 831ef55..0000000 --- a/node-mjpeg-proxy.js +++ /dev/null @@ -1,49 +0,0 @@ -/************************** -TODO: -1. Make it work with existing HTTP servers and listen to resource URLs -**************************/ - -var http = require('http'), -sys = require('sys'), -url = require('url'); - -Proxy = exports.Proxy = function (srcURL, options) { - if (!srcURL) throw new Error("Please provide a source feed URL"); - srcURL = url.parse(srcURL); - - var srcClient = http.createClient(srcURL.port || 80, srcURL.hostname); - - var audienceServer = options.audienceServer || http.createServer(); - var audienceServerPort = options.port || 5080; - var audienceClients = []; - - // Starting the stream on from the source - var request = srcClient.request('GET', srcURL.pathname + - (srcURL.search ? srcURL.search : ""), - {'host': srcURL.hostname}); - request.end(); - request.on('response', function (srcResponse) { - /** Setup Audience server listener **/ - audienceServer.on('request', function (req, res) { - /** Replicate the header from the source **/ - res.writeHead(200, srcResponse.headers); - /** Push the client into the client list **/ - audienceClients.push(res); - /** Clean up connections when they're dead **/ - res.socket.on('close', function () { - audienceClients.splice(audienceClients.indexOf(res), 1); - }); - }); - audienceServer.listen(audienceServerPort); - sys.puts('node-mjpeg-proxy server started on port 5080'); - - /** Send data to relevant clients **/ - srcResponse.setEncoding('binary'); - srcResponse.on('data', function (chunk) { - var i; - for (i = audienceClients.length; i--;) { - audienceClients[i].write(chunk, 'binary'); - } - }); - }); -}; |