You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

101 lines
3.1 KiB

var BOB_mod_express = require('express');
var BOB_mod_router = BOB_mod_express.Router();
var BOB_mod_path = require('path');
var BOB_mod_mkdirp = require('mkdirp');
var BOB_mod_os = require('os');
var BOB_tol_gphotos = null;
var BOB_tol_booth = null;
var BOB_cfg_config = null;
var BOB_var_boothInProgress = 0;
var BOB_var_gamepad = require("gamepad");
var BOB_var_ipAddress = '127.0.0.1';
/* GET home page. */
BOB_mod_router.get('/bobinoscope', function(req, res, next) {
res.render('index', {serverIpAddress: BOB_var_ipAddress});
});
/* GET view page. */
BOB_mod_router.get('/', function(req, res, next) {
res.render('view', {serverIpAddress: BOB_var_ipAddress});
});
BOB_mod_router.get('/booth/build/:boothId', function(req, res, next) {
BOB_var_boothInProgress += 1;
BOB_cfg_config.io.emit('boothState');
BOB_tol_booth.buildBooth(req.params.boothId, function(pErr) {
BOB_cfg_config.io.emit('boothState');
BOB_var_boothInProgress -= 1;
res.json({ error: pErr, data : null, boothId: req.params.boothId});
});
})
BOB_mod_router.get('/booth/list/:from', function(req, res, next) {
BOB_tol_booth.getBoothList(req.params.from, function(pErr, pList) {
res.json({error: pErr, booths: pList, inProgress : BOB_var_boothInProgress});
})
})
/* GET home page. */
BOB_mod_router.get('/dslr/takepicture/:boothId/:pictId', function(req, res, next) {
// BOB_cfg_config.io.emit('boothState');
BOB_tol_gphotos.takePicture(req.params.boothId, req.params.pictId, function(pErr) {
res.json({ error: pErr, data : null});
})
});
/* GET view page. */
BOB_mod_router.get('/download/final/hd/:pictId', function(req, res, next) {
res.download('/home/cocoon/workspace/bobinoscope/public/img/final/'+req.params.pictId);
});
// Initialize the library
BOB_var_gamepad.init()
// List the state of all currently attached devices
for (var i = 0, l = BOB_var_gamepad.numDevices(); i < l; i++) {
console.log(i, BOB_var_gamepad.deviceAtIndex(i));
}
// Create a game loop and poll for events
setInterval(BOB_var_gamepad.processEvents, 16);
// Scan for new gamepads as a slower rate
setInterval(BOB_var_gamepad.detectDevices, 500);
// Listen for button down events on all gamepads
BOB_var_gamepad.on("down", function (pId, pNum) {
BOB_cfg_config.io.emit('boothClick', {
id : pId,
num : pNum
});
})
// Get local server ip address
var ifaces = BOB_mod_os.networkInterfaces();
Object.keys(ifaces).forEach(function (ifname) {
var alias = 0;
ifaces[ifname].forEach(function (iface) {
if ('IPv4' !== iface.family || iface.internal !== false) {
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
return;
}
BOB_var_ipAddress = iface.address;
if (alias >= 1) {
// this single interface has multiple ipv4 addresses
console.log(ifname + ':' + alias, iface.address);
} else {
// this interface has only one ipv4 adress
console.log(ifname, iface.address);
}
});
});
module.exports = function(pConfig) {
BOB_cfg_config = pConfig;
BOB_tol_gphotos = require('../tools/tools-gphoto2')(pConfig);
BOB_tol_booth = require('../tools/tools-photobooth')(pConfig);
return BOB_mod_router;
}