Apply dependencies update
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / UIService001.ts
CommitLineData
33cea517 1import {
32de5a57 2 ProcedureName,
33cea517
JB
3 ProtocolRequestHandler,
4 ProtocolVersion,
89b7a234 5 RequestPayload,
33cea517 6} from '../../../types/UIProtocol';
4e3ff94d
JB
7import {
8 BroadcastChannelProcedureName,
9 BroadcastChannelRequestPayload,
10} from '../../../types/WorkerBroadcastChannel';
6c1761d4 11import type { AbstractUIServer } from '../AbstractUIServer';
4198ad5c 12import AbstractUIService from './AbstractUIService';
4198ad5c 13
f16356b9 14export default class UIService001 extends AbstractUIService {
fe94fce0 15 constructor(uiServer: AbstractUIServer) {
33cea517 16 super(uiServer, ProtocolVersion['0.0.1']);
02a6943a 17 this.requestHandlers.set(
89b7a234
JB
18 ProcedureName.START_CHARGING_STATION,
19 this.handleStartChargingStation.bind(this) as ProtocolRequestHandler
20 );
02a6943a 21 this.requestHandlers.set(
89b7a234
JB
22 ProcedureName.STOP_CHARGING_STATION,
23 this.handleStopChargingStation.bind(this) as ProtocolRequestHandler
24 );
db2336d9
JB
25 this.requestHandlers.set(
26 ProcedureName.OPEN_CONNECTION,
27 this.handleOpenConnection.bind(this) as ProtocolRequestHandler
28 );
29 this.requestHandlers.set(
30 ProcedureName.CLOSE_CONNECTION,
31 this.handleCloseConnection.bind(this) as ProtocolRequestHandler
32 );
4f69be04
JB
33 this.requestHandlers.set(
34 ProcedureName.START_TRANSACTION,
35 this.handleStartTransaction.bind(this) as ProtocolRequestHandler
36 );
37 this.requestHandlers.set(
38 ProcedureName.STOP_TRANSACTION,
39 this.handleStopTransaction.bind(this) as ProtocolRequestHandler
40 );
41 this.requestHandlers.set(
42 ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
43 this.handleStartAutomaticTransactionGenerator.bind(this) as ProtocolRequestHandler
44 );
45 this.requestHandlers.set(
46 ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
47 this.handleStopAutomaticTransactionGenerator.bind(this) as ProtocolRequestHandler
48 );
89b7a234
JB
49 }
50
4f69be04 51 private handleStartChargingStation(uuid: string, payload: RequestPayload): void {
6812b4e1 52 this.uiServiceWorkerBroadcastChannel.sendRequest([
4e3ff94d 53 uuid,
4f69be04 54 BroadcastChannelProcedureName.START_CHARGING_STATION,
4e3ff94d 55 payload as BroadcastChannelRequestPayload,
89b7a234 56 ]);
89b7a234
JB
57 }
58
4f69be04 59 private handleStopChargingStation(uuid: string, payload: RequestPayload): void {
6812b4e1 60 this.uiServiceWorkerBroadcastChannel.sendRequest([
4e3ff94d 61 uuid,
4f69be04 62 BroadcastChannelProcedureName.STOP_CHARGING_STATION,
4e3ff94d 63 payload as BroadcastChannelRequestPayload,
89b7a234 64 ]);
4198ad5c
JB
65 }
66
4f69be04 67 private handleOpenConnection(uuid: string, payload: RequestPayload): void {
6812b4e1 68 this.uiServiceWorkerBroadcastChannel.sendRequest([
4e3ff94d 69 uuid,
4f69be04 70 BroadcastChannelProcedureName.OPEN_CONNECTION,
4e3ff94d 71 payload as BroadcastChannelRequestPayload,
89b7a234 72 ]);
32de5a57
LM
73 }
74
4f69be04 75 private handleCloseConnection(uuid: string, payload: RequestPayload): void {
6812b4e1 76 this.uiServiceWorkerBroadcastChannel.sendRequest([
4e3ff94d 77 uuid,
4f69be04 78 BroadcastChannelProcedureName.CLOSE_CONNECTION,
4e3ff94d 79 payload as BroadcastChannelRequestPayload,
89b7a234 80 ]);
32de5a57 81 }
db2336d9 82
4f69be04 83 private handleStartTransaction(uuid: string, payload: RequestPayload): void {
db2336d9
JB
84 this.uiServiceWorkerBroadcastChannel.sendRequest([
85 uuid,
4f69be04 86 BroadcastChannelProcedureName.START_TRANSACTION,
db2336d9
JB
87 payload as BroadcastChannelRequestPayload,
88 ]);
89 }
90
4f69be04 91 private handleStopTransaction(uuid: string, payload: RequestPayload): void {
db2336d9
JB
92 this.uiServiceWorkerBroadcastChannel.sendRequest([
93 uuid,
4f69be04
JB
94 BroadcastChannelProcedureName.STOP_TRANSACTION,
95 payload as BroadcastChannelRequestPayload,
96 ]);
97 }
98
99 private handleStartAutomaticTransactionGenerator(uuid: string, payload: RequestPayload): void {
100 this.uiServiceWorkerBroadcastChannel.sendRequest([
101 uuid,
102 BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
103 payload as BroadcastChannelRequestPayload,
104 ]);
105 }
106
107 private handleStopAutomaticTransactionGenerator(uuid: string, payload: RequestPayload): void {
108 this.uiServiceWorkerBroadcastChannel.sendRequest([
109 uuid,
110 BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
db2336d9
JB
111 payload as BroadcastChannelRequestPayload,
112 ]);
113 }
4198ad5c 114}