update for new backend impl

This commit is contained in:
jane 2021-12-28 21:40:12 -05:00
parent 8b6116e0cc
commit 438c64f936
3 changed files with 56 additions and 34 deletions

View file

@ -1,10 +1,11 @@
import * as net from 'net'; import * as ws from "ws";
import * as net from "net";
const hostname = '192.168.1.219'; const hostname = "192.168.1.219";
const port = 29999; const port = 29999;
function getBinarySize(string) { function getBinarySize(string) {
return Buffer.byteLength(string, 'utf8'); return Buffer.byteLength(string, "utf8");
} }
// export function contactServer(callback, errorCallback) { // export function contactServer(callback, errorCallback) {
@ -23,28 +24,29 @@ function getBinarySize(string) {
// } // }
export default function req(data, callback, errorCallback) { export default function req(data, callback, errorCallback) {
let string_data = JSON.stringify(data); let string_data = data;
let size = getBinarySize(string_data); let size = getBinarySize(string_data);
if (size > 9999) { if (size > 9999) {
errorCallback("too long"); errorCallback("too long");
return; return;
} }
let client = new net.Socket();
let c_port = global.ctx.lights.port || port; let c_port = global.ctx.lights.port || port;
let c_addr = global.ctx.lights.addr || hostname; let c_addr = global.ctx.lights.addr || hostname;
client.connect(c_port, c_addr, () => { }); let url = `ws://${c_addr}:${c_port}`;
client.on('connect', () => {
client.write(string_data);
})
client.on('data', (dat) => {
callback(String(dat));
client.destroy();
})
client.on('error', (e) => { let client = new ws.WebSocket(url);
client.destroy();
client.on("open", () => {
client.send(string_data);
});
client.on("message", (dat) => {
callback(String(dat));
client.close();
});
client.on("error", (e) => {
client.terminate();
errorCallback(e); errorCallback(e);
}); });
} }

View file

@ -1,7 +1,8 @@
{ {
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"eris": "^0.14.0" "eris": "^0.14.0",
"ws": "^8.4.0"
}, },
"name": "lights", "name": "lights",
"version": "1.0.0", "version": "1.0.0",

View file

@ -1,32 +1,41 @@
lockfileVersion: 5.3
specifiers:
eris: ^0.14.0
ws: ^8.4.0
dependencies: dependencies:
eris: 0.14.0 eris: 0.14.0
lockfileVersion: 5.2 ws: 8.4.0
packages: packages:
/eris/0.14.0: /eris/0.14.0:
resolution: {integrity: sha512-/W6X0SFR2swtA9oc4ga5Wh1TQcZtPgbUaDDdwYc67fvFUAtwC+V1xzWUZq2yDeJnTfB8Uot9SJWA8Lthe2sDtQ==}
engines: {node: '>=8.0.0'}
dependencies: dependencies:
ws: 7.3.1 ws: 7.3.1
dev: false
engines:
node: '>=8.0.0'
optionalDependencies: optionalDependencies:
opusscript: 0.0.7 opusscript: 0.0.7
tweetnacl: 1.0.3 tweetnacl: 1.0.3
resolution: transitivePeerDependencies:
integrity: sha512-/W6X0SFR2swtA9oc4ga5Wh1TQcZtPgbUaDDdwYc67fvFUAtwC+V1xzWUZq2yDeJnTfB8Uot9SJWA8Lthe2sDtQ== - bufferutil
- utf-8-validate
dev: false
/opusscript/0.0.7: /opusscript/0.0.7:
resolution: {integrity: sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==}
dev: false dev: false
optional: true optional: true
resolution:
integrity: sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==
/tweetnacl/1.0.3: /tweetnacl/1.0.3:
resolution: {integrity: sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==}
dev: false dev: false
optional: true optional: true
resolution:
integrity: sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==
/ws/7.3.1: /ws/7.3.1:
dev: false resolution: {integrity: sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==}
engines: engines: {node: '>=8.3.0'}
node: '>=8.3.0'
peerDependencies: peerDependencies:
bufferutil: ^4.0.1 bufferutil: ^4.0.1
utf-8-validate: ^5.0.2 utf-8-validate: ^5.0.2
@ -35,7 +44,17 @@ packages:
optional: true optional: true
utf-8-validate: utf-8-validate:
optional: true optional: true
resolution: dev: false
integrity: sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==
specifiers: /ws/8.4.0:
eris: ^0.14.0 resolution: {integrity: sha512-IHVsKe2pjajSUIl4KYMQOdlyliovpEPquKkqbwswulszzI7r0SfQrxnXdWAEqOlDCLrVSJzo+O1hAwdog2sKSQ==}
engines: {node: '>=10.0.0'}
peerDependencies:
bufferutil: ^4.0.1
utf-8-validate: ^5.0.2
peerDependenciesMeta:
bufferutil:
optional: true
utf-8-validate:
optional: true
dev: false