- return Utils.promiseWithTimeout(new Promise((resolve, reject) => {
- const messageToSend = this.buildMessageToSend(messageId, messagePayload, messageType, commandName, responseCallback, rejectCallback);
- if (this.chargingStation.getEnableStatistics()) {
- this.chargingStation.performanceStatistics.addRequestStatistic(commandName, messageType);
- }
- // Check if wsConnection opened
- if (this.chargingStation.isWebSocketConnectionOpened()) {
- // Yes: Send Message
- const beginId = PerformanceStatistics.beginMeasure(commandName);
- // FIXME: Handle sending error
- this.chargingStation.wsConnection.send(messageToSend);
- PerformanceStatistics.endMeasure(commandName, beginId);
- } else if (!params.skipBufferingOnError) {
- // Buffer it
- this.chargingStation.bufferMessage(messageToSend);
- const ocppError = new OCPPError(ErrorType.GENERIC_ERROR, `WebSocket closed for buffered message id '${messageId}' with content '${messageToSend}'`, commandName, messagePayload?.details as JsonType ?? {});
- if (messageType === MessageType.CALL_MESSAGE) {
- // Reject it but keep the request in the cache
- return reject(ocppError);
+ return Utils.promiseWithTimeout(
+ new Promise((resolve, reject) => {
+ const messageToSend = this.buildMessageToSend(
+ messageId,
+ messagePayload,
+ messageType,
+ commandName,
+ responseCallback,
+ rejectCallback
+ );
+ if (this.chargingStation.getEnableStatistics()) {
+ this.chargingStation.performanceStatistics.addRequestStatistic(
+ commandName,
+ messageType
+ );