From 66e02bea867f6135247d290b8ed29fc3a76b0b5e Mon Sep 17 00:00:00 2001 From: Jan-Felix Abellera Date: Fri, 27 Sep 2024 01:54:14 +0300 Subject: [PATCH] Prettier --- back-end/realtime/src/rooms/FCS.ts | 14 ++++++-- .../src/util/WLEDWorker/WLEDController.ts | 4 +-- .../realtime/src/util/WLEDWorker/worker.ts | 34 +++++++++---------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/back-end/realtime/src/rooms/FCS.ts b/back-end/realtime/src/rooms/FCS.ts index bfb8dc34..f6d848a7 100644 --- a/back-end/realtime/src/rooms/FCS.ts +++ b/back-end/realtime/src/rooms/FCS.ts @@ -40,7 +40,9 @@ export default class FCS extends Room { // Connect to wled websocket servers if there are wleds Object.entries(this.packetManager.getInitPacket().wleds).forEach((wled) => { const isProd = environment.get().nodeEnv === 'production'; - const path = isProd ? `${__dirname}/worker/index.js` : join(__dirname, "../../build/util/WLEDWorker/worker.js"); + const path = isProd + ? `${__dirname}/worker/index.js` + : join(__dirname, '../../build/util/WLEDWorker/worker.js'); logger.verbose(`Creating WLED worker for ${wled[0]} at ${path}`); this.wledControllers[wled[0]] = new Worker(path, { workerData: wled[1] }); // this.wledControllers[wled[0]] = new WledController(wled[1]); @@ -105,7 +107,10 @@ export default class FCS extends Room { Object.entries(this.packetManager.getInitPacket().wleds).forEach( (wled) => { // this.wledControllers[wled[0]].initialize(wled[1]); - this.wledControllers[wled[0]].postMessage({ type: "initialize", data: wled[1] }); + this.wledControllers[wled[0]].postMessage({ + type: 'initialize', + data: wled[1] + }); } ); } @@ -122,7 +127,10 @@ export default class FCS extends Room { // Handle wleds Object.entries(update.wleds).forEach((wled) => { // this.wledControllers[wled[0]].update(wled[1]); - this.wledControllers[wled[0]].postMessage({ type: "update", data: wled[1] }); + this.wledControllers[wled[0]].postMessage({ + type: 'update', + data: wled[1] + }); }); // Update this.latestFcsStatus AFTER sending out the new update diff --git a/back-end/realtime/src/util/WLEDWorker/WLEDController.ts b/back-end/realtime/src/util/WLEDWorker/WLEDController.ts index 3ee25261..c6d34e3c 100644 --- a/back-end/realtime/src/util/WLEDWorker/WLEDController.ts +++ b/back-end/realtime/src/util/WLEDWorker/WLEDController.ts @@ -75,7 +75,7 @@ export class WledController { } // Attempt to reconnect once the socket has closed setTimeout(() => this.initialize(), WledController.reconnectPeriodMs); - } + }; this.socket.onerror = (e: WebSocket.ErrorEvent) => { logger.error(`${this.getName()} failed to connect: ${e.error}`); @@ -106,7 +106,7 @@ export class WledController { private startKeepalive(): void { logger.info(`${this.getName()} starting keepalive`); this.keepAlive = setInterval(() => { - if (!this.connected) return + if (!this.connected) return; if (!this.lastTimestamp) return; if ( Date.now() - this.lastTimestamp >= diff --git a/back-end/realtime/src/util/WLEDWorker/worker.ts b/back-end/realtime/src/util/WLEDWorker/worker.ts index dfa24cd6..70bba8a2 100644 --- a/back-end/realtime/src/util/WLEDWorker/worker.ts +++ b/back-end/realtime/src/util/WLEDWorker/worker.ts @@ -1,28 +1,28 @@ -import { WledInitParameters, WledUpdateParameters } from "@toa-lib/models"; -import { workerData, parentPort } from 'worker_threads' -import { WledController } from "./WLEDController.js"; +import { WledInitParameters, WledUpdateParameters } from '@toa-lib/models'; +import { workerData, parentPort } from 'worker_threads'; +import { WledController } from './WLEDController.js'; interface UpdateMessage { - data: WledUpdateParameters - type: "update" + data: WledUpdateParameters; + type: 'update'; } interface InitializeMessage { - type: "initialize" - data: WledInitParameters + type: 'initialize'; + data: WledInitParameters; } -type Message = UpdateMessage | InitializeMessage +type Message = UpdateMessage | InitializeMessage; -const wled = new WledController(workerData) -wled.initialize() +const wled = new WledController(workerData); +wled.initialize(); if (parentPort) { - parentPort.on('message', (message: Message) => { - if (message.type === "update") { - wled.update(message.data) - } else if (message.type === "initialize") { - wled.initialize(message.data) - } - }); + parentPort.on('message', (message: Message) => { + if (message.type === 'update') { + wled.update(message.data); + } else if (message.type === 'initialize') { + wled.initialize(message.data); + } + }); }