repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix: avoid duplicated slash in connection url
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
broadcast-channel
/
WorkerBroadcastChannel.ts
diff --git
a/src/charging-station/broadcast-channel/WorkerBroadcastChannel.ts
b/src/charging-station/broadcast-channel/WorkerBroadcastChannel.ts
index fd73b1bb59021ced8057ca4b85961dafbb860758..91c92ac2b41ede0d234b184d127ec6329f1b9427 100644
(file)
--- a/
src/charging-station/broadcast-channel/WorkerBroadcastChannel.ts
+++ b/
src/charging-station/broadcast-channel/WorkerBroadcastChannel.ts
@@
-1,59
+1,59
@@
-import { BroadcastChannel } from 'node:worker_threads'
;
+import { BroadcastChannel } from 'node:worker_threads'
import type {
BroadcastChannelRequest,
BroadcastChannelResponse,
JsonType,
import type {
BroadcastChannelRequest,
BroadcastChannelResponse,
JsonType,
- MessageEvent
,
-} from '../../types
';
-import {
Utils, logger } from '../../utils';
+ MessageEvent
+} from '../../types
/index.js'
+import {
logger, logPrefix, validateUUID } from '../../utils/index.js'
-const moduleName = 'WorkerBroadcastChannel'
;
+const moduleName = 'WorkerBroadcastChannel'
export abstract class WorkerBroadcastChannel extends BroadcastChannel {
export abstract class WorkerBroadcastChannel extends BroadcastChannel {
- protected constructor() {
- super('worker')
;
+ protected constructor
() {
+ super('worker')
}
}
- public sendRequest(request: BroadcastChannelRequest): void {
- this.postMessage(request)
;
+ public sendRequest
(request: BroadcastChannelRequest): void {
+ this.postMessage(request)
}
}
- protected sendResponse(response: BroadcastChannelResponse): void {
- this.postMessage(response)
;
+ protected sendResponse
(response: BroadcastChannelResponse): void {
+ this.postMessage(response)
}
}
- protected isRequest(message: JsonType[]): boolean {
- return Array.isArray(message)
=== true && message.length === 3;
+ protected isRequest
(message: JsonType[]): boolean {
+ return Array.isArray(message)
&& message.length === 3
}
}
- protected isResponse(message: JsonType[]): boolean {
- return Array.isArray(message)
=== true && message.length === 2;
+ protected isResponse
(message: JsonType[]): boolean {
+ return Array.isArray(message)
&& message.length === 2
}
}
- protected validateMessageEvent(messageEvent: MessageEvent): MessageEvent | false {
- if (
Array.isArray(messageEvent.data) === false
) {
+ protected validateMessageEvent
(messageEvent: MessageEvent): MessageEvent | false {
+ if (
!Array.isArray(messageEvent.data)
) {
logger.error(
`${this.logPrefix(
moduleName,
'validateMessageEvent'
)} Worker broadcast channel protocol message event data is not an array`
logger.error(
`${this.logPrefix(
moduleName,
'validateMessageEvent'
)} Worker broadcast channel protocol message event data is not an array`
- )
;
- return false
;
+ )
+ return false
}
}
- if (
Utils.validateUUID(messageEvent.data[0]) === false
) {
+ if (
!validateUUID(messageEvent.data[0])
) {
logger.error(
`${this.logPrefix(
moduleName,
'validateMessageEvent'
)} Worker broadcast channel protocol message event data UUID field is invalid`
logger.error(
`${this.logPrefix(
moduleName,
'validateMessageEvent'
)} Worker broadcast channel protocol message event data UUID field is invalid`
- )
;
- return false
;
+ )
+ return false
}
}
- return messageEvent
;
+ return messageEvent
}
}
- private logPrefix = (modName: string, methodName: string): string => {
- return
Utils.logPrefix(` Worker Broadcast Channel | ${modName}.${methodName}:`);
- }
;
+ private
readonly
logPrefix = (modName: string, methodName: string): string => {
+ return
logPrefix(` Worker Broadcast Channel | ${modName}.${methodName}:`)
+ }
}
}