From a560e54bd44017d0e9286e1e08134309aac27780 Mon Sep 17 00:00:00 2001 From: Philippe Rene Date: Tue, 7 Sep 2010 17:35:51 -0400 Subject: Added core of the mjpeg proxy, need to be reworked on this is just a working prototype --- node-mjpeg-proxy.js | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 node-mjpeg-proxy.js diff --git a/node-mjpeg-proxy.js b/node-mjpeg-proxy.js new file mode 100644 index 0000000..84f6a07 --- /dev/null +++ b/node-mjpeg-proxy.js @@ -0,0 +1,114 @@ +/************************** +TODO: +1. better passing of the headers +2. Make in modular +3. Write it modular so it can be dynamically set for cam creds +**************************/ + +var http = require('http'); +var sys = require('sys'); +// port of the cam +var cam = http.createClient(80, '192.168.1.186'); +var allHttpClient = []; +// Starting the stream on the cam +var request = cam.request('GET', '/axis-cgi/mjpg/video.cgi?fps=5', + {'host': '192.168.1.186', + 'Authorization': "Basic ZnFubWFveGJtb3A6MTAyMzc3"}); +request.end(); +request.on('response', function (response) { + response.setEncoding('binary'); + response.on('data', function (chunk) { + + for(i=0; i < allHttpClient.length; i++) + { + allHttpClient[i].write(chunk, 'binary'); + } + + }); + +}); +var testServer = http.createServer(); + +testServer.on('request', function (req, res){ + res.writeHead(200, {"cache-control":"no-cache","pragma":"no-cache","expires":"Thu, 01 Dec 1994 16:00:00 GMT","content-type":"multipart/x-mixed-replace; boundary=myboundary"}); + allHttpClient.push(res); +}); + +testServer.listen(5080, "0.0.0.0"); +sys.puts('Server started on port 5080'); + + + + + + + + + + + + + + + + + + + + + + + + + + + +/************************* +DEPRECATED SHIT +*************************/ +/******** READ AN IMAGE AND SEND IT ON CONNECTION *********/ +//var image = fs.readFileSync('/home/prene/Desktop/hotmail.png', 'binary', function(err, data){ +// sys.puts("yep gone through"); +// if(err) throw err; +// +// return data; +// }); + +//var server = http.createServer(function (req, res) { + +// res.writeHead(200, { "Content-Type": "text/jpg" +// , "Content-Length": image.length +// }); +// +// res.end(image, 'binary'); + +// +//}).listen(7878, "0.0.0.0"); + +/**** // *******/ + + +/************ STORE ALL SOCKETS CONNECTING *****************/ + +//sockets = []; +// + +//net.createServer(function (socket) { + +// socket.setEncoding("utf8"); +// socket.addListener("connect", function () { +// console.log("Connected"); +// +// }); + +// socket.addListener("end", function () { +// socket.end(); +// +// }); + +// sockets.push(socket); + +//}).listen(port, "0.0.0.0"); +//sys.puts("Server TCP listening on 127.0.0.1 on port: " + port); + +/************ // ********/ -- cgit v1.2.1