Commit | Line | Data |
---|---|---|
33cea517 | 1 | import { |
32de5a57 | 2 | ProcedureName, |
33cea517 JB |
3 | ProtocolRequestHandler, |
4 | ProtocolVersion, | |
89b7a234 | 5 | RequestPayload, |
32de5a57 LM |
6 | ResponsePayload, |
7 | ResponseStatus, | |
33cea517 | 8 | } from '../../../types/UIProtocol'; |
4e3ff94d JB |
9 | import { |
10 | BroadcastChannelProcedureName, | |
11 | BroadcastChannelRequestPayload, | |
12 | } from '../../../types/WorkerBroadcastChannel'; | |
fe94fce0 | 13 | import { AbstractUIServer } from '../AbstractUIServer'; |
4198ad5c | 14 | import AbstractUIService from './AbstractUIService'; |
4198ad5c | 15 | |
f16356b9 | 16 | export default class UIService001 extends AbstractUIService { |
fe94fce0 | 17 | constructor(uiServer: AbstractUIServer) { |
33cea517 | 18 | super(uiServer, ProtocolVersion['0.0.1']); |
e7aeea18 | 19 | this.messageHandlers.set( |
32de5a57 | 20 | ProcedureName.START_TRANSACTION, |
e7aeea18 JB |
21 | this.handleStartTransaction.bind(this) as ProtocolRequestHandler |
22 | ); | |
23 | this.messageHandlers.set( | |
32de5a57 | 24 | ProcedureName.STOP_TRANSACTION, |
e7aeea18 JB |
25 | this.handleStopTransaction.bind(this) as ProtocolRequestHandler |
26 | ); | |
89b7a234 JB |
27 | this.messageHandlers.set( |
28 | ProcedureName.START_CHARGING_STATION, | |
29 | this.handleStartChargingStation.bind(this) as ProtocolRequestHandler | |
30 | ); | |
31 | this.messageHandlers.set( | |
32 | ProcedureName.STOP_CHARGING_STATION, | |
33 | this.handleStopChargingStation.bind(this) as ProtocolRequestHandler | |
34 | ); | |
35 | } | |
36 | ||
4e3ff94d JB |
37 | private handleStartTransaction(uuid: string, payload: RequestPayload): ResponsePayload { |
38 | this.workerBroadcastChannel.sendRequest([ | |
39 | uuid, | |
89b7a234 | 40 | BroadcastChannelProcedureName.START_TRANSACTION, |
4e3ff94d | 41 | payload as BroadcastChannelRequestPayload, |
89b7a234 JB |
42 | ]); |
43 | return { status: ResponseStatus.SUCCESS }; | |
44 | } | |
45 | ||
4e3ff94d JB |
46 | private handleStopTransaction(uuid: string, payload: RequestPayload): ResponsePayload { |
47 | this.workerBroadcastChannel.sendRequest([ | |
48 | uuid, | |
89b7a234 | 49 | BroadcastChannelProcedureName.STOP_TRANSACTION, |
4e3ff94d | 50 | payload as BroadcastChannelRequestPayload, |
89b7a234 JB |
51 | ]); |
52 | return { status: ResponseStatus.SUCCESS }; | |
4198ad5c JB |
53 | } |
54 | ||
4e3ff94d JB |
55 | private handleStartChargingStation(uuid: string, payload: RequestPayload): ResponsePayload { |
56 | this.workerBroadcastChannel.sendRequest([ | |
57 | uuid, | |
89b7a234 | 58 | BroadcastChannelProcedureName.START_CHARGING_STATION, |
4e3ff94d | 59 | payload as BroadcastChannelRequestPayload, |
89b7a234 | 60 | ]); |
32de5a57 LM |
61 | return { status: ResponseStatus.SUCCESS }; |
62 | } | |
63 | ||
4e3ff94d JB |
64 | private handleStopChargingStation(uuid: string, payload: RequestPayload): ResponsePayload { |
65 | this.workerBroadcastChannel.sendRequest([ | |
66 | uuid, | |
89b7a234 | 67 | BroadcastChannelProcedureName.STOP_CHARGING_STATION, |
4e3ff94d | 68 | payload as BroadcastChannelRequestPayload, |
89b7a234 | 69 | ]); |
32de5a57 LM |
70 | return { status: ResponseStatus.SUCCESS }; |
71 | } | |
4198ad5c | 72 | } |