1 import { BroadcastChannelResponse
, MessageEvent
} from
'../types/WorkerBroadcastChannel';
2 import logger from
'../utils/Logger';
3 import AbstractUIService from
'./ui-server/ui-services/AbstractUIService';
4 import WorkerBroadcastChannel from
'./WorkerBroadcastChannel';
6 const moduleName
= 'UIServiceWorkerBroadcastChannel';
8 export default class UIServiceWorkerBroadcastChannel
extends WorkerBroadcastChannel
{
9 private uiService
: AbstractUIService
;
11 constructor(uiService
: AbstractUIService
) {
13 this.uiService
= uiService
;
14 this.onmessage
= this.responseHandler
.bind(this) as (message
: MessageEvent
) => void;
15 this.onmessageerror
= this.messageErrorHandler
.bind(this) as (message
: MessageEvent
) => void;
18 private responseHandler(messageEvent
: MessageEvent
): void {
19 if (this.isRequest(messageEvent
.data
)) {
22 const [uuid
, responsePayload
] = messageEvent
.data
as BroadcastChannelResponse
;
24 this.uiService
.sendResponse(uuid
, responsePayload
);
27 private messageErrorHandler(messageEvent
: MessageEvent
): void {
29 `${this.uiService.logPrefix(moduleName, 'messageErrorHandler')} Error at handling message:`,
30 { messageEvent
, messageEventData
: messageEvent
.data
}