}
this.started = true;
} catch (error) {
- console.error(chalk.red('Bootstrap start error '), error);
+ console.error(chalk.red('Bootstrap start error: '), error);
}
} else {
console.error(chalk.red('Cannot start an already started charging stations simulator'));
try {
commandResponse = await this.commandHandler(command, requestPayload);
if (commandResponse === undefined) {
- responsePayload = { status: ResponseStatus.SUCCESS };
+ responsePayload = {
+ hashId: this.chargingStation.hashId,
+ status: ResponseStatus.SUCCESS,
+ };
} else {
- responsePayload = { status: this.commandResponseToResponseStatus(commandResponse) };
+ responsePayload = {
+ hashId: this.chargingStation.hashId,
+ status: this.commandResponseToResponseStatus(commandResponse),
+ };
}
} catch (error) {
logger.error(
error
);
responsePayload = {
+ hashId: this.chargingStation.hashId,
status: ResponseStatus.FAILURE,
command,
requestPayload,
}
this.validateMessageEvent(messageEvent);
const [uuid, responsePayload] = messageEvent.data as BroadcastChannelResponse;
+ // TODO: handle multiple responses for the same uuid
+ delete responsePayload.hashId;
this.uiService.sendResponse(uuid, responsePayload);
}
}
public start(): void {
- (this.server as Server).listen(this.options ?? Configuration.getUIServer().options);
+ if ((this.server as Server).listening === false) {
+ (this.server as Server).listen(this.options ?? Configuration.getUIServer().options);
+ }
}
public stop(): void {
this.chargingStations.clear();
+ this.responseHandlers.clear();
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public sendResponse(response: string): void {
const [uuid, payload] = JSON.parse(response) as ProtocolResponse;
const statusCode = this.responseStatusToStatusCode(payload.status);
- if (this.responseHandlers.has(uuid)) {
+ if (this.responseHandlers.has(uuid) === true) {
const { res } = this.responseHandlers.get(uuid);
res.writeHead(statusCode, { 'Content-Type': 'application/json' });
res.write(JSON.stringify(payload));
| HashIdBroadcastChannelRequestPayload
| HashIdsBroadcastChannelRequestPayload;
-export type BroadcastChannelResponsePayload = ResponsePayload;
+export interface BroadcastChannelResponsePayload extends ResponsePayload {
+ hashId: string;
+}
export type MessageEvent = { data: BroadcastChannelRequest | BroadcastChannelResponse };