From: Jérôme Benoit Date: Fri, 26 May 2023 12:55:36 +0000 (+0200) Subject: fix: only send UI server response when needed X-Git-Tag: v1.2.14~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0b22144c135af531858c989650e864edb352764d;p=e-mobility-charging-stations-simulator.git fix: only send UI server response when needed Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index b99ef36a..a831446b 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -125,6 +125,11 @@ export class UIHttpServer extends AbstractUIServer { body ?? Constants.EMPTY_FREEZED_OBJECT ) ) + .then((protocolResponse: ProtocolResponse) => { + if (Utils.isNullOrUndefined(protocolResponse)) { + this.sendResponse(protocolResponse); + } + }) .catch(Constants.EMPTY_FUNCTION); }); } else { diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index cc00db13..5ddf0e59 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -49,7 +49,15 @@ export class UIWebSocketServer extends AbstractUIServer { } const [requestId] = request as ProtocolRequest; this.responseHandlers.set(requestId, ws); - this.uiServices.get(version)?.requestHandler(request).catch(Constants.EMPTY_FUNCTION); + this.uiServices + .get(version) + ?.requestHandler(request) + .then((protocolResponse: ProtocolResponse) => { + if (!Utils.isNullOrUndefined(protocolResponse)) { + this.sendResponse(protocolResponse); + } + }) + .catch(Constants.EMPTY_FUNCTION); }); ws.on('error', (error) => { logger.error(`${this.logPrefix(moduleName, 'start.ws.onerror')} WebSocket error:`, error); diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 392a63ed..0531011f 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -100,22 +100,20 @@ export abstract class AbstractUIService { errorDetails: (error as OCPPError).details, }; } - // Send response if (!Utils.isNullOrUndefined(responsePayload)) { - this.sendResponse(messageId, responsePayload); return this.uiServer.buildProtocolResponse(messageId, responsePayload); } } - public sendRequest( - messageId: string, - procedureName: ProcedureName, - requestPayload: RequestPayload - ): void { - this.uiServer.sendRequest( - this.uiServer.buildProtocolRequest(messageId, procedureName, requestPayload) - ); - } + // public sendRequest( + // messageId: string, + // procedureName: ProcedureName, + // requestPayload: RequestPayload + // ): void { + // this.uiServer.sendRequest( + // this.uiServer.buildProtocolRequest(messageId, procedureName, requestPayload) + // ); + // } public sendResponse(messageId: string, responsePayload: ResponsePayload): void { this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(messageId, responsePayload));