}
public startHeartbeat(): void {
- if (this.getHeartbeatInterval() > 0 && !this.heartbeatSetInterval) {
+ if (this.getHeartbeatInterval() > 0 && this.heartbeatSetInterval === undefined) {
this.heartbeatSetInterval = setInterval(() => {
this.ocppRequestService
.requestHandler<HeartbeatRequest, HeartbeatResponse>(this, RequestCommand.HEARTBEAT)
this.getHeartbeatInterval(),
)}`,
);
- } else if (this.heartbeatSetInterval) {
+ } else if (this.heartbeatSetInterval !== undefined) {
logger.info(
`${this.logPrefix()} Heartbeat already started every ${formatDurationMilliSeconds(
this.getHeartbeatInterval(),
}
public stopMeterValues(connectorId: number) {
- if (this.getConnectorStatus(connectorId)?.transactionSetInterval) {
+ if (this.getConnectorStatus(connectorId)?.transactionSetInterval !== undefined) {
clearInterval(this.getConnectorStatus(connectorId)?.transactionSetInterval);
}
}
public bufferMessage(message: string): void {
this.messageBuffer.add(message);
- if (this.flushMessageBufferSetInterval === undefined) {
- this.flushMessageBufferSetInterval = setInterval(() => {
- if (this.isWebSocketConnectionOpened() === true && this.inAcceptedState() === true) {
- this.flushMessageBuffer();
- }
- if (this.flushMessageBufferSetInterval !== undefined && this.messageBuffer.size === 0) {
- clearInterval(this.flushMessageBufferSetInterval);
- delete this.flushMessageBufferSetInterval;
- }
- }, Constants.DEFAULT_MESSAGE_BUFFER_FLUSH_INTERVAL);
- }
+ this.setIntervalFlushMessageBuffer();
}
public openWSConnection(
return false;
}
+ private setIntervalFlushMessageBuffer(): void {
+ if (this.flushMessageBufferSetInterval === undefined) {
+ this.flushMessageBufferSetInterval = setInterval(() => {
+ if (this.isWebSocketConnectionOpened() === true && this.inAcceptedState() === true) {
+ this.flushMessageBuffer();
+ }
+ if (this.messageBuffer.size === 0) {
+ this.clearIntervalFlushMessageBuffer();
+ }
+ }, Constants.DEFAULT_MESSAGE_BUFFER_FLUSH_INTERVAL);
+ }
+ }
+
+ private clearIntervalFlushMessageBuffer() {
+ if (this.flushMessageBufferSetInterval !== undefined) {
+ clearInterval(this.flushMessageBufferSetInterval);
+ delete this.flushMessageBufferSetInterval;
+ }
+ }
+
private getNumberOfReservableConnectors(): number {
let numberOfReservableConnectors = 0;
if (this.hasEvses) {
}
private stopHeartbeat(): void {
- if (this.heartbeatSetInterval) {
+ if (this.heartbeatSetInterval !== undefined) {
clearInterval(this.heartbeatSetInterval);
delete this.heartbeatSetInterval;
}