- return rejectCallback(ocppError, false);
- } else {
- // Reject it
- return rejectCallback(new OCPPError(ErrorType.GENERIC_ERROR, `WebSocket closed for non buffered message id '${messageId}' with content '${messageToSend}'`, commandName, messagePayload?.details as JsonType ?? {}), false);
- }
- // Response?
- if (messageType !== MessageType.CALL_MESSAGE) {
- // Yes: send Ok
- return resolve(messagePayload);
- }
-
- /**
- * Function that will receive the request's response
- *
- * @param payload
- * @param requestPayload
- */
- async function responseCallback(payload: JsonType | string, requestPayload: JsonType): Promise<void> {
- if (self.chargingStation.getEnableStatistics()) {
- self.chargingStation.performanceStatistics.addRequestStatistic(commandName, MessageType.CALL_RESULT_MESSAGE);
+ // Check if wsConnection opened
+ if (chargingStation.isWebSocketConnectionOpened() === true) {
+ // Yes: Send Message
+ const beginId = PerformanceStatistics.beginMeasure(commandName);
+ // FIXME: Handle sending error
+ chargingStation.wsConnection.send(messageToSend);
+ PerformanceStatistics.endMeasure(commandName, beginId);
+ logger.debug(
+ `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString(
+ messageType
+ )} payload: ${messageToSend}`
+ );
+ } else if (params.skipBufferingOnError === false) {
+ // Buffer it
+ chargingStation.bufferMessage(messageToSend);
+ const ocppError = new OCPPError(
+ ErrorType.GENERIC_ERROR,
+ `WebSocket closed for buffered message id '${messageId}' with content '${messageToSend}'`,
+ commandName,
+ (messagePayload as JsonObject)?.details ?? {}
+ );
+ if (messageType === MessageType.CALL_MESSAGE) {
+ // Reject it but keep the request in the cache
+ return reject(ocppError);
+ }
+ return errorCallback(ocppError, false);
+ } else {
+ // Reject it
+ return errorCallback(
+ new OCPPError(
+ ErrorType.GENERIC_ERROR,
+ `WebSocket closed for non buffered message id '${messageId}' with content '${messageToSend}'`,
+ commandName,
+ (messagePayload as JsonObject)?.details ?? {}
+ ),
+ false
+ );