X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FWorkerBroadcastChannel.ts;h=f3c168bdc8f1057611d1b8768d6d1dde0364c627;hb=a7bb184512dd064b5da4dc125d652b6b40ceffee;hp=c1df1afdabb88b7dd276f4b38e891bf5eb863d79;hpb=5f7e72c1538ebf67dc5de3c29840f7b4da6704f8;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/WorkerBroadcastChannel.ts b/src/charging-station/WorkerBroadcastChannel.ts index c1df1afd..f3c168bd 100644 --- a/src/charging-station/WorkerBroadcastChannel.ts +++ b/src/charging-station/WorkerBroadcastChannel.ts @@ -1,19 +1,16 @@ -import { BroadcastChannel } from 'worker_threads'; +import { BroadcastChannel } from 'node:worker_threads'; -import * as uuid from 'uuid'; - -import type { JsonType } from '../types/JsonType'; import type { BroadcastChannelRequest, BroadcastChannelResponse, + JsonType, MessageEvent, -} from '../types/WorkerBroadcastChannel'; -import logger from '../utils/Logger'; -import Utils from '../utils/Utils'; +} from '../types'; +import { Utils, logger } from '../utils'; const moduleName = 'WorkerBroadcastChannel'; -export default abstract class WorkerBroadcastChannel extends BroadcastChannel { +export abstract class WorkerBroadcastChannel extends BroadcastChannel { protected constructor() { super('worker'); } @@ -37,22 +34,26 @@ export default abstract class WorkerBroadcastChannel extends BroadcastChannel { protected validateMessageEvent(messageEvent: MessageEvent): MessageEvent | false { if (Array.isArray(messageEvent.data) === false) { logger.error( - this.logPrefix(moduleName, 'validateMessageEvent') + - ' Worker broadcast channel protocol message event data is not an array' + `${this.logPrefix( + moduleName, + 'validateMessageEvent' + )} Worker broadcast channel protocol message event data is not an array` ); return false; } - if (uuid.validate(messageEvent.data[0]) === false) { + if (Utils.validateUUID(messageEvent.data[0]) === false) { logger.error( - this.logPrefix(moduleName, 'validateMessageEvent') + - ' Worker broadcast channel protocol message event data UUID field is invalid' + `${this.logPrefix( + moduleName, + 'validateMessageEvent' + )} Worker broadcast channel protocol message event data UUID field is invalid` ); return false; } return messageEvent; } - private logPrefix(modName: string, methodName: string): string { + private logPrefix = (modName: string, methodName: string): string => { return Utils.logPrefix(` Worker Broadcast Channel | ${modName}.${methodName}:`); - } + }; }