From 0b22144c135af531858c989650e864edb352764d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 26 May 2023 14:55:36 +0200 Subject: [PATCH] fix: only send UI server response when needed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ui-server/UIHttpServer.ts | 5 +++++ .../ui-server/UIWebSocketServer.ts | 10 +++++++++- .../ui-services/AbstractUIService.ts | 20 +++++++++---------- 3 files changed, 23 insertions(+), 12 deletions(-) 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)); -- 2.34.1