From: Jérôme Benoit Date: Fri, 27 May 2022 10:11:55 +0000 (+0200) Subject: Add helpers to close and terminate WS connection X-Git-Tag: v1.1.61~25 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=555162188c5b4d08666e33c235625ba51db87a4d;p=e-mobility-charging-stations-simulator.git Add helpers to close and terminate WS connection Signed-off-by: Jérôme Benoit --- 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);