Enhance SocketClient functionality and improve host update handling
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
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:
parent
d616a45f21
commit
3f5f02b087
@ -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);
|
||||
|
||||
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user