Apply dependencies update
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / ui-services / UIService001.ts
1 import {
2 ProcedureName,
3 ProtocolRequestHandler,
4 ProtocolVersion,
5 RequestPayload,
6 } from '../../../types/UIProtocol';
7 import {
8 BroadcastChannelProcedureName,
9 BroadcastChannelRequestPayload,
10 } from '../../../types/WorkerBroadcastChannel';
11 import type { AbstractUIServer } from '../AbstractUIServer';
12 import AbstractUIService from './AbstractUIService';
13
14 export default class UIService001 extends AbstractUIService {
15 constructor(uiServer: AbstractUIServer) {
16 super(uiServer, ProtocolVersion['0.0.1']);
17 this.requestHandlers.set(
18 ProcedureName.START_CHARGING_STATION,
19 this.handleStartChargingStation.bind(this) as ProtocolRequestHandler
20 );
21 this.requestHandlers.set(
22 ProcedureName.STOP_CHARGING_STATION,
23 this.handleStopChargingStation.bind(this) as ProtocolRequestHandler
24 );
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 );
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 );
49 }
50
51 private handleStartChargingStation(uuid: string, payload: RequestPayload): void {
52 this.uiServiceWorkerBroadcastChannel.sendRequest([
53 uuid,
54 BroadcastChannelProcedureName.START_CHARGING_STATION,
55 payload as BroadcastChannelRequestPayload,
56 ]);
57 }
58
59 private handleStopChargingStation(uuid: string, payload: RequestPayload): void {
60 this.uiServiceWorkerBroadcastChannel.sendRequest([
61 uuid,
62 BroadcastChannelProcedureName.STOP_CHARGING_STATION,
63 payload as BroadcastChannelRequestPayload,
64 ]);
65 }
66
67 private handleOpenConnection(uuid: string, payload: RequestPayload): void {
68 this.uiServiceWorkerBroadcastChannel.sendRequest([
69 uuid,
70 BroadcastChannelProcedureName.OPEN_CONNECTION,
71 payload as BroadcastChannelRequestPayload,
72 ]);
73 }
74
75 private handleCloseConnection(uuid: string, payload: RequestPayload): void {
76 this.uiServiceWorkerBroadcastChannel.sendRequest([
77 uuid,
78 BroadcastChannelProcedureName.CLOSE_CONNECTION,
79 payload as BroadcastChannelRequestPayload,
80 ]);
81 }
82
83 private handleStartTransaction(uuid: string, payload: RequestPayload): void {
84 this.uiServiceWorkerBroadcastChannel.sendRequest([
85 uuid,
86 BroadcastChannelProcedureName.START_TRANSACTION,
87 payload as BroadcastChannelRequestPayload,
88 ]);
89 }
90
91 private handleStopTransaction(uuid: string, payload: RequestPayload): void {
92 this.uiServiceWorkerBroadcastChannel.sendRequest([
93 uuid,
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,
111 payload as BroadcastChannelRequestPayload,
112 ]);
113 }
114 }