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(