Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jfabellera committed Sep 26, 2024
1 parent 505a6f0 commit 66e02be
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
14 changes: 11 additions & 3 deletions back-end/realtime/src/rooms/FCS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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]
});
}
);
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions back-end/realtime/src/util/WLEDWorker/WLEDController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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 >=
Expand Down
34 changes: 17 additions & 17 deletions back-end/realtime/src/util/WLEDWorker/worker.ts
Original file line number Diff line number Diff line change
@@ -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);
}
});
}

0 comments on commit 66e02be

Please sign in to comment.