Enhance SocketClient functionality and improve host update handling
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit

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.
This commit is contained in:
Tom Butcher 2026-07-26 23:42:48 +01:00
parent d616a45f21
commit 3f5f02b087
2 changed files with 19 additions and 1 deletions

View File

@ -31,6 +31,7 @@ const printerHostInfo = (host) => {
logger.info("Reference:", ref); logger.info("Reference:", ref);
logger.info("Name:", host?.name || "Unknown"); logger.info("Name:", host?.name || "Unknown");
if (host?.tags?.length > 0) { if (host?.tags?.length > 0) {
logger.info("Tags: -", host?.tags?.[0]);
for (var i = 0; i < host?.tags?.length - 1; i++) { for (var i = 0; i < host?.tags?.length - 1; i++) {
const tag = host?.tags[i + 1]; const tag = host?.tags[i + 1];
logger.info(" -", tag); logger.info(" -", tag);

View File

@ -215,6 +215,7 @@ export class SocketClient {
saveConfig(config); saveConfig(config);
this.sendDeviceInfo(); this.sendDeviceInfo();
this.subscribeToObjectEvents(); this.subscribeToObjectEvents();
this.subscribeToObjectUpdates({ objectType: "host", _id: this.id });
this.documentPrinterManager.reloadDocumentPrinters(); this.documentPrinterManager.reloadDocumentPrinters();
this.printerManager.reloadPrinters(); this.printerManager.reloadPrinters();
await this.fileManager.updateFiles(); await this.fileManager.updateFiles();
@ -236,6 +237,22 @@ export class SocketClient {
callback({ success: true }); 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) { handleObjectAction(data, callback) {
logger.debug("Running object action...", data); logger.debug("Running object action...", data);
const id = data._id; const id = data._id;
@ -267,7 +284,7 @@ export class SocketClient {
data._id, data._id,
); );
if (data.objectType == "host") { if (data.objectType == "host") {
this.handleHostAction(action, callback); this.handleHostUpdate(data);
} }
if (data.objectType == "documentPrinter") { if (data.objectType == "documentPrinter") {
this.documentPrinterManager.handleDocumentPrinterUpdate( this.documentPrinterManager.handleDocumentPrinterUpdate(