2018-01-05 04:43:33 +00:00
|
|
|
'use script'
|
|
|
|
|
|
|
|
let os
|
|
|
|
let restify
|
|
|
|
let app
|
|
|
|
|
|
|
|
let cam
|
|
|
|
let proj
|
|
|
|
let light
|
|
|
|
|
2018-03-15 19:32:26 +00:00
|
|
|
const PACKAGE = require('../../package.json')
|
|
|
|
|
2018-01-05 04:43:33 +00:00
|
|
|
class Server {
|
2018-01-11 11:25:17 +00:00
|
|
|
constructor (camera, projector, light) {
|
2018-01-05 04:43:33 +00:00
|
|
|
restify = require('restify')
|
|
|
|
os = require('os')
|
2018-01-11 11:25:17 +00:00
|
|
|
app = restify.createServer({
|
|
|
|
name: 'mcopy-server',
|
2018-03-15 19:32:26 +00:00
|
|
|
version: PACKAGE.version
|
2018-01-11 11:25:17 +00:00
|
|
|
})
|
2018-01-05 04:43:33 +00:00
|
|
|
|
2018-01-11 11:25:17 +00:00
|
|
|
this.ip = this.getIp()
|
2018-01-05 04:43:33 +00:00
|
|
|
|
2018-01-11 11:25:17 +00:00
|
|
|
/*app.get('/', function (req, res) {
|
2018-01-05 04:43:33 +00:00
|
|
|
mcopy.mobile.log('Device connected');
|
|
|
|
res.send(fs.readFileSync('tmpl/mcopy_index.html', 'utf8'));
|
2018-01-11 11:25:17 +00:00
|
|
|
})
|
|
|
|
app.get('/js/mcopy_mobile.js', function (req, res) {
|
|
|
|
res.send(fs.readFileSync('js/mcopy_mobile.js', 'utf8'));
|
2018-01-05 04:43:33 +00:00
|
|
|
});
|
2018-01-11 11:25:17 +00:00
|
|
|
app.get('/js/jquery.js', function (req, res) {
|
|
|
|
res.send(fs.readFileSync('js/jquery.js', 'utf8'));
|
|
|
|
});
|
|
|
|
app.get('/cmd/:cmd', function (req, res) {
|
|
|
|
var cmd,
|
|
|
|
success = function (res) {
|
|
|
|
var obj = {
|
|
|
|
success: true,
|
|
|
|
cmd : cmd,
|
2019-03-31 00:29:01 +00:00
|
|
|
cam: {
|
|
|
|
dir : cam.dir,
|
|
|
|
pos : cam.pos
|
|
|
|
},
|
|
|
|
proj: {
|
|
|
|
dir : proj.dir,
|
|
|
|
pos : proj.pos
|
|
|
|
}
|
2018-01-11 11:25:17 +00:00
|
|
|
}
|
|
|
|
res.json(obj);
|
|
|
|
};
|
|
|
|
if (typeof req.params.cmd !== 'undefined') {
|
|
|
|
mcopy.log('Receiving command from mobile: ' + req.params.cmd);
|
|
|
|
cmd = req.params.cmd;
|
|
|
|
if (cmd === 'CF'){
|
2019-03-22 01:02:28 +00:00
|
|
|
mcopy.cmd.camera_forward(success);
|
2018-01-11 11:25:17 +00:00
|
|
|
} else if (cmd === 'CB') {
|
2019-03-22 01:02:28 +00:00
|
|
|
mcopy.cmd.camera_backward(success);
|
2018-01-11 11:25:17 +00:00
|
|
|
} else if (cmd === 'PF') {
|
2019-03-22 01:02:28 +00:00
|
|
|
mcopy.cmd.projector_forward(success);
|
2018-01-11 11:25:17 +00:00
|
|
|
} else if (cmd === 'PB') {
|
2019-03-22 01:02:28 +00:00
|
|
|
mcopy.cmd.projector_backward(success);
|
2018-01-11 11:25:17 +00:00
|
|
|
} else {
|
|
|
|
mcopy.mobile.fail(res, 'Command ' + cmd + ' not found');
|
2018-01-05 04:43:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-01-11 11:25:17 +00:00
|
|
|
mcopy.mobile.fail(res, 'No command provided');
|
2018-01-05 04:43:33 +00:00
|
|
|
}
|
|
|
|
});
|
2018-01-11 11:25:17 +00:00
|
|
|
app.get('/state', function (req, res) {
|
|
|
|
res.json({
|
2019-03-31 00:29:01 +00:00
|
|
|
cam: {
|
|
|
|
dir : cam.dir,
|
|
|
|
pos : cam.pos
|
|
|
|
},
|
|
|
|
proj: {
|
|
|
|
dir : proj.dir,
|
|
|
|
pos : proj.pos
|
|
|
|
}
|
2018-01-11 11:25:17 +00:00
|
|
|
});
|
|
|
|
});*/
|
|
|
|
|
|
|
|
|
2018-01-05 04:43:33 +00:00
|
|
|
}
|
|
|
|
end () {
|
|
|
|
app.close()
|
2018-01-11 11:25:17 +00:00
|
|
|
app = null
|
2018-01-05 04:43:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Server
|