-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
596bcfe
commit aef63a6
Showing
11 changed files
with
550 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"arrowParens": "always", | ||
"bracketSpacing": true, | ||
"printWidth": 120, | ||
"semi": false, | ||
"singleQuote": true, | ||
"useTabs": true, | ||
"endOfLine": "lf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ Built with [Electron](https://electronjs.org). | |
``` | ||
$ npm install | ||
$ npm start | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,104 @@ | ||
const express = require('express'); | ||
const http = require('http'); | ||
const socketio = require('socket.io'); | ||
const express = require('express') | ||
const http = require('http') | ||
const socketio = require('socket.io') | ||
|
||
const util = require('./util.js'); | ||
const config = require('./config.js'); | ||
const util = require('./util.js') | ||
const config = require('./config.js') | ||
|
||
const package_json = require('./package.json'); | ||
const VERSION = package_json.version; | ||
const package_json = require('./package.json') | ||
const VERSION = package_json.version | ||
|
||
var server = null; | ||
var httpServer = null; | ||
var io = null; | ||
var server = null | ||
var httpServer = null | ||
var io = null | ||
|
||
class API { | ||
static start(port) { | ||
//starts the REST API | ||
server = express(); | ||
server = express() | ||
|
||
httpServer = new http.Server(server); | ||
io = new socketio.Server(httpServer, { allowEIO3: true }); | ||
httpServer = new http.Server(server) | ||
io = new socketio.Server(httpServer, { allowEIO3: true }) | ||
|
||
server.use(express.json()); //parse json in body | ||
server.use(express.json()) //parse json in body | ||
|
||
server.get('/version', function (req, res) { | ||
res.send({version: VERSION}); | ||
}); | ||
res.send({ version: VERSION }) | ||
}) | ||
|
||
server.get('/control_status', function (req, res) { | ||
res.send({control_status: config.get('allowControl')}); | ||
}); | ||
res.send({ control_status: config.get('allowControl') }) | ||
}) | ||
|
||
server.get('/devices', function (req, res) { | ||
res.send({devices: util.getDevices()}); | ||
}); | ||
res.send({ devices: util.getDevices() }) | ||
}) | ||
|
||
server.get('/colors', function (req, res) { | ||
res.send({colors: util.getColors()}); | ||
}); | ||
res.send({ colors: util.getColors() }) | ||
}) | ||
|
||
server.get('/sounds', function (req, res) { | ||
res.send({sounds: util.getSounds()}); | ||
}); | ||
res.send({ sounds: util.getSounds() }) | ||
}) | ||
|
||
server.post('/beacon', function (req, res) { | ||
let beaconObj = req.body; | ||
let beaconObj = req.body | ||
if (beaconObj) { | ||
util.showNotification(beaconObj); | ||
util.engageBeacon(beaconObj); | ||
util.playSound(beaconObj); | ||
util.showNotification(beaconObj) | ||
util.engageBeacon(beaconObj) | ||
util.playSound(beaconObj) | ||
} | ||
|
||
res.send({control_status: config.get('allowControl')}); | ||
}); | ||
res.send({ control_status: config.get('allowControl') }) | ||
}) | ||
|
||
server.use(function (req, res) { | ||
res.status(404).send({error: true, url: req.originalUrl + ' not found.'}); | ||
}); | ||
res.status(404).send({ error: true, url: req.originalUrl + ' not found.' }) | ||
}) | ||
|
||
io.sockets.on('connection', (socket) => { | ||
let ipAddr = socket.handshake.address; | ||
socket.emit('control_status', config.get('allowControl')); | ||
let ipAddr = socket.handshake.address | ||
socket.emit('control_status', config.get('allowControl')) | ||
|
||
socket.on('version', function() { | ||
socket.emit('version', VERSION); | ||
}); | ||
socket.on('version', function () { | ||
socket.emit('version', VERSION) | ||
}) | ||
|
||
socket.on('control_status', function() { | ||
socket.emit('control_status', config.get('allowControl')); | ||
}); | ||
socket.on('control_status', function () { | ||
socket.emit('control_status', config.get('allowControl')) | ||
}) | ||
|
||
socket.on('devices', function() { | ||
socket.emit('devices', util.getDevices()); | ||
}); | ||
socket.on('devices', function () { | ||
socket.emit('devices', util.getDevices()) | ||
}) | ||
|
||
socket.on('colors', function() { | ||
socket.emit('colors', util.getColors()); | ||
}); | ||
socket.on('colors', function () { | ||
socket.emit('colors', util.getColors()) | ||
}) | ||
|
||
socket.on('sounds', function() { | ||
socket.emit('sounds', util.getSounds()); | ||
}); | ||
socket.on('sounds', function () { | ||
socket.emit('sounds', util.getSounds()) | ||
}) | ||
|
||
socket.on('beacon', function(beaconObj) { | ||
socket.on('beacon', function (beaconObj) { | ||
if (beaconObj) { | ||
util.showNotification(beaconObj); | ||
util.engageBeacon(beaconObj); | ||
util.playSound(beaconObj); | ||
util.showNotification(beaconObj) | ||
util.engageBeacon(beaconObj) | ||
util.playSound(beaconObj) | ||
} | ||
}); | ||
}); | ||
}) | ||
}) | ||
|
||
httpServer.listen(port); | ||
console.log('REST/Socket.io API server started on: ' + port); | ||
httpServer.listen(port) | ||
console.log('REST/Socket.io API server started on: ' + port) | ||
|
||
util.startUp(); | ||
util.startUp() | ||
} | ||
|
||
static sendControlStatus() { | ||
io.sockets.emit('control_status', config.get('allowControl')); | ||
io.sockets.emit('control_status', config.get('allowControl')) | ||
} | ||
} | ||
|
||
module.exports = API; | ||
module.exports = API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.