From 573a798156423707ca770c19c9cfb0b7bb6a5808 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 24 Jan 2014 01:01:38 +0100 Subject: Relay control signals --- cam_public/index.html | 16 +++++++++++++-- server.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/cam_public/index.html b/cam_public/index.html index 8bdde6e..790efca 100644 --- a/cam_public/index.html +++ b/cam_public/index.html @@ -1,2 +1,14 @@ -

Hello, World!

- + + + + + + + +
+ + + + + + diff --git a/server.js b/server.js index c887b1f..f8dcd8a 100644 --- a/server.js +++ b/server.js @@ -1,15 +1,24 @@ +'use strict'; + var express = require('express'); var fs = require('fs'); +var request = require('request'); var MjpegProxy = require('mjpeg-proxy').MjpegProxy; var app = express(); var cameras = [ { - url: 'http://admin:123456@192.168.0.117/videostream.cgi?rate=1' + baseurl: 'http://admin:123456@192.168.0.33', + model: 'conceptronic' + }, + { + baseurl: 'http://admin:123456@192.168.0.117', + model: 'conceptronic' }, { - url: 'http://admin:123456@192.168.0.178/videostream.cgi?rate=1' + url: 'http://admin:123456@192.168.0.178', + model: 'conceptronic' } ]; @@ -18,12 +27,52 @@ var still_frames = [ fs.readFileSync(__dirname + '/noise2.jpg'), ]; +function SimpleProxy(url) { + var self = this; + + self.url = url; + self.handle_request = function(req, res) { + console.log('Got request. Forwarding to ' + self.url); + request(self.url).pipe(res); + }; +} + for (var camera_idx in cameras) { var camera = cameras[camera_idx]; - camera.proxy = new MjpegProxy(camera.url, still_frames) + var urls = {}; + + if (camera.model == 'conceptronic') { + urls.mjpeg = camera.baseurl + '/videostream.cgi?rate=1'; + urls.down = camera.baseurl + + '/decoder_control.cgi?onestep=1&command=0'; + urls.up = camera.baseurl + + '/decoder_control.cgi?onestep=1&command=2'; + urls.right = camera.baseurl + + '/decoder_control.cgi?onestep=1&command=4'; + urls.left = camera.baseurl + + '/decoder_control.cgi?onestep=1&command=6'; + urls.snapshot = camera.baseurl + '/snapshot.cgi'; + } else if (camera.model == 'mjpegplexer') { + urls.mjpeg = camera.baseurl + '/stream.mjpeg'; + urls.down = camera.baseurl + '/control/down'; + urls.up = camera.baseurl + '/control/up'; + urls.right = camera.baseurl + '/control/right'; + urls.left = camera.baseurl + '/control/left'; + urls.snapshow = camera.baseurl + '/snapshot.jpg'; + }; + + camera.proxy = new MjpegProxy(urls.mjpeg, still_frames); app.get('/cam/' + camera_idx + '/stream.mjpeg', camera.proxy.proxyRequest); + for (var url in urls) { + if (url == 'mjpeg' || url == 'snapshot') + continue; + app.get('/cam/' + camera_idx + '/control/' + url, + new SimpleProxy(urls[url]).handle_request); + } + app.get('/cam/' + camera_idx + '/snapshot.jpg', + new SimpleProxy(urls.snapshot).handle_request); app.use('/cam/' + camera_idx + '/browse', - express.static(__dirname + '/cam_public')); + express.static(__dirname + '/cam_public')); } app.get('/blackout', function(req, res) { -- cgit v1.2.1