begin migrating parsing to backend
This commit is contained in:
parent
e1e17d2313
commit
cc9e1b86e6
3 changed files with 27 additions and 13 deletions
|
@ -33,8 +33,8 @@ ws281x.configure({
|
||||||
});
|
});
|
||||||
|
|
||||||
export function set_pattern(pat) {
|
export function set_pattern(pat) {
|
||||||
|
pattern = pat
|
||||||
log.debug("pattern set");
|
log.debug("pattern set");
|
||||||
pattern = pat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const functions = {
|
export const functions = {
|
||||||
|
|
5
parse.js
Normal file
5
parse.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export default function parse(data) {
|
||||||
|
return {
|
||||||
|
errors: ["not yet implemented"]
|
||||||
|
}
|
||||||
|
}
|
33
server.js
33
server.js
|
@ -1,7 +1,7 @@
|
||||||
import * as net from 'net';
|
import * as net from 'net';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { functions, reqs } from './lights.js'
|
|
||||||
import Logger, { levels } from './logger.js';
|
import Logger, { levels } from './logger.js';
|
||||||
|
import parse from './parse.js'
|
||||||
|
|
||||||
const cfg = JSON.parse(fs.readFileSync('./config.json'));
|
const cfg = JSON.parse(fs.readFileSync('./config.json'));
|
||||||
const log = new Logger("server", cfg.log_level ? levels[cfg.log_level] : levels.INFO);
|
const log = new Logger("server", cfg.log_level ? levels[cfg.log_level] : levels.INFO);
|
||||||
|
@ -16,18 +16,27 @@ export function recv(callback, errorCallback) {
|
||||||
server.on('connection', (con) => {
|
server.on('connection', (con) => {
|
||||||
console.log('connection recieved: ' +
|
console.log('connection recieved: ' +
|
||||||
con.remoteAddress + ":" + con.remotePort);
|
con.remoteAddress + ":" + con.remotePort);
|
||||||
let data = [];
|
// let data = [];
|
||||||
for (let key of Object.keys(functions)) {
|
// for (let key of Object.keys(functions)) {
|
||||||
data.push({
|
// data.push({
|
||||||
n: key.toUpperCase(),
|
// n: key.toUpperCase(),
|
||||||
a: reqs[key.toLowerCase()] != undefined ? reqs[key.toLowerCase()] : true
|
// a: reqs[key.toLowerCase()] != undefined ? reqs[key.toLowerCase()] : true
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
let functions_str = JSON.stringify(data);
|
// let functions_str = JSON.stringify(data);
|
||||||
con.write(functions_str);
|
// con.write(functions_str);
|
||||||
log.debug(`sending ${functions_str}`);
|
// log.debug(`sending ${functions_str}`);
|
||||||
con.on('data', (data) => {
|
con.on('data', (data) => {
|
||||||
callback(data);
|
let parsed_data = parse(data);
|
||||||
|
|
||||||
|
if (parsed_data.errors) {
|
||||||
|
con.write(JSON.stringify(parsed_data.errors));
|
||||||
|
errorCallback(parsed_data);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
con.write("success");
|
||||||
|
callback(data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
con.on('close', () => {
|
con.on('close', () => {
|
||||||
console.log('recieved close for ' +
|
console.log('recieved close for ' +
|
||||||
|
|
Loading…
Reference in a new issue