}
}
+ public addMessageToBuffer(message: string): void {
+ let dups = false;
+ // Handle dups in buffer
+ for (const bufferedMessage of this.messageQueue) {
+ // Same message
+ if (message === bufferedMessage) {
+ dups = true;
+ break;
+ }
+ }
+ if (!dups) {
+ // Buffer message
+ this.messageQueue.push(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;
// Yes: Send Message
this.chargingStation.wsConnection.send(messageToSend);
} else if (commandName !== RequestCommand.BOOT_NOTIFICATION) {
- let dups = false;
- // Handle dups in buffer
- for (const message of this.chargingStation.messageQueue) {
- // Same message
- if (messageToSend === message) {
- dups = true;
- break;
- }
- }
- if (!dups) {
- // Buffer message
- this.chargingStation.messageQueue.push(messageToSend);
- }
+ // Buffer it
+ this.chargingStation.addMessageToBuffer(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 : {}));
}