From 555162188c5b4d08666e33c235625ba51db87a4d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 27 May 2022 12:11:55 +0200 Subject: [PATCH] Add helpers to close and terminate WS connection MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 7d853547..14bb05a1 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -554,9 +554,7 @@ export default class ChargingStation { this.getConnectorStatus(connectorId).status = ChargePointStatus.UNAVAILABLE; } } - if (this.isWebSocketConnectionOpened()) { - this.wsConnection.close(); - } + this.closeWSConnection(); if (this.getEnableStatistics()) { this.performanceStatistics.stop(); } @@ -1893,11 +1891,11 @@ export default class ChargingStation { ) { options.auth = `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`; } - if (this.isWebSocketConnectionOpened() && params?.closeOpened) { - this.wsConnection.close(); + if (params?.closeOpened) { + this.closeWSConnection(); } - if (this.isWebSocketConnectionOpened() && params?.terminateOpened) { - this.wsConnection.terminate(); + if (params?.terminateOpened) { + this.terminateWSConnection(); } let protocol: string; switch (this.getOcppVersion()) { @@ -1914,6 +1912,20 @@ export default class ChargingStation { ); } + private closeWSConnection(): void { + if (this.isWebSocketConnectionOpened()) { + this.wsConnection.close(); + this.wsConnection = null; + } + } + + private terminateWSConnection(): void { + if (this.isWebSocketConnectionOpened()) { + this.wsConnection.terminate(); + this.wsConnection = null; + } + } + private stopMeterValues(connectorId: number) { if (this.getConnectorStatus(connectorId)?.transactionSetInterval) { clearInterval(this.getConnectorStatus(connectorId).transactionSetInterval); -- 2.34.1