From e692077ed5661484e3b66819b88251afb082e165 Mon Sep 17 00:00:00 2001 From: Essem Date: Wed, 5 Jan 2022 10:39:50 -0600 Subject: [PATCH] Send number of running jobs on init payload --- api/IMPLEMENTATION.md | 2 +- api/index.js | 4 +++- utils/imageConnection.js | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api/IMPLEMENTATION.md b/api/IMPLEMENTATION.md index da269e6..3104314 100644 --- a/api/IMPLEMENTATION.md +++ b/api/IMPLEMENTATION.md @@ -30,7 +30,7 @@ A client sends *requests* (T-messages) to a server, which subsequently *replies* - Rcancel tag[2] - Twait tag[2] jid[4] - Rwait tag[2] -- Rinit tag[2] max_jobs[2] formats[j] +- Rinit tag[2] max_jobs[2] running_jobs[2] formats[j] ### Job Object The job object is formatted like this: diff --git a/api/index.js b/api/index.js index dcf163e..f24e3f7 100644 --- a/api/index.js +++ b/api/index.js @@ -91,11 +91,13 @@ wss.on("connection", (ws, request) => { log(`WS client ${request.socket.remoteAddress}:${request.socket.remotePort} has connected`); const num = Buffer.alloc(2); num.writeUInt16LE(MAX_JOBS); + const cur = Buffer.alloc(2); + cur.writeUInt16LE(jobAmount); const formats = {}; for (const cmd of Object.keys(magick)) { formats[cmd] = ["image/png", "image/gif", "image/jpeg", "image/webp"]; } - const init = Buffer.concat([Buffer.from([Rinit]), Buffer.from([0x00, 0x00]), num, Buffer.from(JSON.stringify(formats))]); + const init = Buffer.concat([Buffer.from([Rinit]), Buffer.from([0x00, 0x00]), num, cur, Buffer.from(JSON.stringify(formats))]); ws.send(init); ws.on("error", (err) => { diff --git a/utils/imageConnection.js b/utils/imageConnection.js index 3482098..6c23b6e 100644 --- a/utils/imageConnection.js +++ b/utils/imageConnection.js @@ -63,7 +63,8 @@ class ImageConnection { const op = msg.readUint8(0); if (op === Rinit) { this.max = msg.readUint16LE(3); - this.formats = JSON.parse(msg.toString("utf8", 5)); + this.njobs = msg.readUint16LE(5); + this.formats = JSON.parse(msg.toString("utf8", 7)); return; } const tag = msg.readUint16LE(1);