-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·36 lines (28 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"use strict";
var websocket = require("nodejs-websocket");
var config = require(process.argv[2]||"./config.json");
var StripController = require("./strip-controller");
var stripServices = Object.create(null);
for (var stripName in config.strips) {
if (!config.strips.hasOwnProperty(stripName)) continue;
stripServices[stripName] = new StripController(config.strips[stripName]);
}
console.log(stripServices);
var server = websocket.createServer(function(connection){
var stripName = connection.path.substring(1);
if (!(stripName in stripServices)) {
return connection.close(404,"No led service " +stripName);
};
var stripService = stripServices[stripName];
connection.on("binary", function(inStream){
var data = new Buffer(0)
inStream.on("readable", function () {
var newData = inStream.read()
if (newData)
data = Buffer.concat([data, newData], data.length+newData.length)
});
inStream.on("end", function () {
stripService.send(data)
});
});
}).listen(config.port);