From 3f5f02b0871eb1f30edc8b6832d8a2a0b4acf5fa Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sun, 26 Jul 2026 23:42:48 +0100 Subject: [PATCH] Enhance SocketClient functionality and improve host update handling Add a new method to handle host updates in SocketClient, ensuring that updates are processed correctly based on the host ID. Additionally, improve logging in index.js to include the first tag of the host for better visibility. This change streamlines the management of host information and enhances the overall logging clarity. --- src/index.js | 1 + src/socket/socketclient.js | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 67f2918..3e61e26 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,7 @@ const printerHostInfo = (host) => { logger.info("Reference:", ref); logger.info("Name:", host?.name || "Unknown"); if (host?.tags?.length > 0) { + logger.info("Tags: -", host?.tags?.[0]); for (var i = 0; i < host?.tags?.length - 1; i++) { const tag = host?.tags[i + 1]; logger.info(" -", tag); diff --git a/src/socket/socketclient.js b/src/socket/socketclient.js index 5aedffa..a089575 100644 --- a/src/socket/socketclient.js +++ b/src/socket/socketclient.js @@ -215,6 +215,7 @@ export class SocketClient { saveConfig(config); this.sendDeviceInfo(); this.subscribeToObjectEvents(); + this.subscribeToObjectUpdates({ objectType: "host", _id: this.id }); this.documentPrinterManager.reloadDocumentPrinters(); this.printerManager.reloadPrinters(); await this.fileManager.updateFiles(); @@ -236,6 +237,22 @@ export class SocketClient { callback({ success: true }); } + handleHostUpdate(data) { + if (data._id != this.id) { + return; + } + + logger.debug("Handling host update for id:", data._id); + const { online, state } = this.host; + this.host = { ...this.host, ...data.object, online, state }; + sendIPC("setHost", this.host); + + if (data.object?.authCode) { + config.host = { id: this.id, authCode: data.object.authCode }; + saveConfig(config); + } + } + handleObjectAction(data, callback) { logger.debug("Running object action...", data); const id = data._id; @@ -267,7 +284,7 @@ export class SocketClient { data._id, ); if (data.objectType == "host") { - this.handleHostAction(action, callback); + this.handleHostUpdate(data); } if (data.objectType == "documentPrinter") { this.documentPrinterManager.handleDocumentPrinterUpdate(