}
}
- public addMessageToBuffer(message: string): void {
+ public addToMessageQueue(message: string): void {
let dups = false;
// Handle dups in buffer
for (const bufferedMessage of this.messageQueue) {
}
}
+ private flushMessageQueue() {
+ if (!Utils.isEmptyArray(this.messageQueue)) {
+ this.messageQueue.forEach((message, index) => {
+ this.messageQueue.splice(index, 1);
+ this.wsConnection.send(message);
+ });
+ }
+ }
+
private getChargingStationId(stationTemplate: ChargingStationTemplate): string {
// In case of multiple instances: add instance index to charging station id
let instanceIndex = process.env.CF_INSTANCE_INDEX ? process.env.CF_INSTANCE_INDEX : 0;
await this.startMessageSequence();
this.hasStopped && (this.hasStopped = false);
if (this.hasSocketRestarted && this.isWebSocketOpen()) {
- if (!Utils.isEmptyArray(this.messageQueue)) {
- this.messageQueue.forEach((message, index) => {
- this.messageQueue.splice(index, 1);
- this.wsConnection.send(message);
- });
- }
+ this.flushMessageQueue();
}
} else {
logger.error(`${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})`);
this.chargingStation.wsConnection.send(messageToSend);
} else if (commandName !== RequestCommand.BOOT_NOTIFICATION) {
// Buffer it
- this.chargingStation.addMessageToBuffer(messageToSend);
+ this.chargingStation.addToMessageQueue(messageToSend);
// Reject it
return rejectCallback(new OCPPError(commandParams.code ? commandParams.code : ErrorType.GENERIC_ERROR, commandParams.message ? commandParams.message : `WebSocket closed for message id '${messageId}' with content '${messageToSend}', message buffered`, commandParams.details ? commandParams.details : {}));
}