From 2a6f2d6f9bbf6b6c5a8a5fa4564132fea1d0e918 Mon Sep 17 00:00:00 2001 From: Jane Petrovna Date: Sun, 8 Nov 2020 23:15:14 -0500 Subject: [PATCH] network stuff? --- lights/request.js | 32 ++++++++++++++++++-------------- package.json | 4 ++-- pnpm-lock.yaml | 22 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/lights/request.js b/lights/request.js index d019727..29132e2 100644 --- a/lights/request.js +++ b/lights/request.js @@ -1,18 +1,22 @@ -import * as https from 'https'; +import * as net from 'net'; -const options = { - hostname: '192.168.1.219', - port: '29999', - path: '/', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, -}; +const hostname = '192.168.1.219'; +const port = 29999; + +function getBinarySize(string) { + return Buffer.byteLength(string, 'utf8'); +} export default function req(data, callback, errorCallback) { - const request = https.request(options, (res) => callback(res)); - request.on('error', (error) => errorCallback(error)); - request.write(JSON.stringify(data)); - request.end(); + let string_data = JSON.stringify(data); + let size = getBinarySize(string_data); + + let client = new net.Socket(); + client.connect(port, hostname, () => { + let res = client.write(size); + + if (res) { + client.write(string_data); + } + }); } diff --git a/package.json b/package.json index d0147c7..dc86990 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "type": "module", "dependencies": { - "eris": "^0.14.0" + "eris": "^0.14.0", + "socket.engine": "^1.0.0" }, "name": "lights", "version": "1.0.0", "main": "bot.js", - "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node bot.js" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d21f2f0..afae322 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,6 @@ dependencies: eris: 0.14.0 + socket.engine: 1.0.0 lockfileVersion: 5.1 packages: /eris/0.14.0: @@ -13,11 +14,31 @@ packages: tweetnacl: 1.0.3 resolution: integrity: sha512-/W6X0SFR2swtA9oc4ga5Wh1TQcZtPgbUaDDdwYc67fvFUAtwC+V1xzWUZq2yDeJnTfB8Uot9SJWA8Lthe2sDtQ== + /fs/0.0.1-security: + dev: false + resolution: + integrity: sha1-invTcYa23d84E/I4WLV+yq9eQdQ= + /ip/1.1.5: + dev: false + resolution: + integrity: sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo= + /net/1.0.2: + dev: false + resolution: + integrity: sha1-0XV+yaf7I3HYPPR1XOPifhCCk4g= /opusscript/0.0.7: dev: false optional: true resolution: integrity: sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg== + /socket.engine/1.0.0: + dependencies: + fs: 0.0.1-security + ip: 1.1.5 + net: 1.0.2 + dev: false + resolution: + integrity: sha512-vwc9JVBNe33686TBl9T3Ro53FaF09z11NVnrf0HIlYUOIDaZ1OFA1J1O6igU57qhP3NyUv4a+kZtgMm6SnziaQ== /tweetnacl/1.0.3: dev: false optional: true @@ -39,3 +60,4 @@ packages: integrity: sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA== specifiers: eris: ^0.14.0 + socket.engine: ^1.0.0