CurrentType,
Voltage,
} from '../types/ChargingStationTemplate';
-import type { SampledValueTemplate } from '../types/MeasurandPerPhaseSampledValueTemplates';
import { ChargingProfileKindType, RecurrencyKindType } from '../types/ocpp/1.6/ChargingProfile';
import type { ChargingProfile, ChargingSchedulePeriod } from '../types/ocpp/ChargingProfile';
-import { StandardParametersKey } from '../types/ocpp/Configuration';
-import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues';
-import {
- type BootNotificationRequest,
- IncomingRequestCommand,
- RequestCommand,
-} from '../types/ocpp/Requests';
+import type { BootNotificationRequest } from '../types/ocpp/Requests';
import { WorkerProcessType } from '../types/Worker';
import Configuration from '../utils/Configuration';
import Constants from '../utils/Constants';
import logger from '../utils/Logger';
import Utils from '../utils/Utils';
-import type ChargingStation from './ChargingStation';
-import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils';
const moduleName = 'ChargingStationUtils';
return unitDivider;
}
- public static setChargingProfile(
- chargingStation: ChargingStation,
- connectorId: number,
- cp: ChargingProfile
- ): void {
- if (Utils.isNullOrUndefined(chargingStation.getConnectorStatus(connectorId).chargingProfiles)) {
- logger.error(
- `${chargingStation.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an uninitialized charging profiles array attribute, applying deferred initialization`
- );
- chargingStation.getConnectorStatus(connectorId).chargingProfiles = [];
- }
- if (Array.isArray(chargingStation.getConnectorStatus(connectorId).chargingProfiles) === false) {
- logger.error(
- `${chargingStation.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization`
- );
- chargingStation.getConnectorStatus(connectorId).chargingProfiles = [];
- }
- let cpReplaced = false;
- if (!Utils.isEmptyArray(chargingStation.getConnectorStatus(connectorId).chargingProfiles)) {
- chargingStation
- .getConnectorStatus(connectorId)
- .chargingProfiles?.forEach((chargingProfile: ChargingProfile, index: number) => {
- if (
- chargingProfile.chargingProfileId === cp.chargingProfileId ||
- (chargingProfile.stackLevel === cp.stackLevel &&
- chargingProfile.chargingProfilePurpose === cp.chargingProfilePurpose)
- ) {
- chargingStation.getConnectorStatus(connectorId).chargingProfiles[index] = cp;
- cpReplaced = true;
- }
- });
- }
- !cpReplaced && chargingStation.getConnectorStatus(connectorId).chargingProfiles?.push(cp);
- }
-
/**
* Charging profiles should already be sorted by connectorId and stack level (highest stack level has priority)
*
return defaultVoltageOut;
}
- public static getSampledValueTemplate(
- chargingStation: ChargingStation,
- connectorId: number,
- measurand: MeterValueMeasurand = MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER,
- phase?: MeterValuePhase
- ): SampledValueTemplate | undefined {
- const onPhaseStr = phase ? `on phase ${phase} ` : '';
- if (Constants.SUPPORTED_MEASURANDS.includes(measurand) === false) {
- logger.warn(
- `${chargingStation.logPrefix()} Trying to get unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
- );
- return;
- }
- if (
- measurand !== MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
- !ChargingStationConfigurationUtils.getConfigurationKey(
- chargingStation,
- StandardParametersKey.MeterValuesSampledData
- )?.value.includes(measurand)
- ) {
- logger.debug(
- `${chargingStation.logPrefix()} Trying to get MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId} not found in '${
- StandardParametersKey.MeterValuesSampledData
- }' OCPP parameter`
- );
- return;
- }
- const sampledValueTemplates: SampledValueTemplate[] =
- chargingStation.getConnectorStatus(connectorId).MeterValues;
- for (
- let index = 0;
- !Utils.isEmptyArray(sampledValueTemplates) && index < sampledValueTemplates.length;
- index++
- ) {
- if (
- Constants.SUPPORTED_MEASURANDS.includes(
- sampledValueTemplates[index]?.measurand ??
- MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
- ) === false
- ) {
- logger.warn(
- `${chargingStation.logPrefix()} Unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
- );
- } else if (
- phase &&
- sampledValueTemplates[index]?.phase === phase &&
- sampledValueTemplates[index]?.measurand === measurand &&
- ChargingStationConfigurationUtils.getConfigurationKey(
- chargingStation,
- StandardParametersKey.MeterValuesSampledData
- )?.value.includes(measurand) === true
- ) {
- return sampledValueTemplates[index];
- } else if (
- !phase &&
- !sampledValueTemplates[index].phase &&
- sampledValueTemplates[index]?.measurand === measurand &&
- ChargingStationConfigurationUtils.getConfigurationKey(
- chargingStation,
- StandardParametersKey.MeterValuesSampledData
- )?.value.includes(measurand) === true
- ) {
- return sampledValueTemplates[index];
- } else if (
- measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
- (!sampledValueTemplates[index].measurand ||
- sampledValueTemplates[index].measurand === measurand)
- ) {
- return sampledValueTemplates[index];
- }
- }
- if (measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER) {
- const errorMsg = `Missing MeterValues for default measurand '${measurand}' in template on connectorId ${connectorId}`;
- logger.error(`${chargingStation.logPrefix()} ${errorMsg}`);
- throw new BaseError(errorMsg);
- }
- logger.debug(
- `${chargingStation.logPrefix()} No MeterValues for measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
- );
- }
-
public static getAuthorizationFile(stationInfo: ChargingStationInfo): string | undefined {
return (
stationInfo.authorizationFile &&
);
}
- public static isRequestCommandSupported(
- command: RequestCommand,
- chargingStation: ChargingStation
- ): boolean {
- const isRequestCommand = Object.values(RequestCommand).includes(command);
- if (
- isRequestCommand === true &&
- !chargingStation.stationInfo?.commandsSupport?.outgoingCommands
- ) {
- return true;
- } else if (
- isRequestCommand === true &&
- chargingStation.stationInfo?.commandsSupport?.outgoingCommands
- ) {
- return chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command] ?? false;
- }
- logger.error(`${chargingStation.logPrefix()} Unknown outgoing OCPP command '${command}'`);
- return false;
- }
-
- public static isIncomingRequestCommandSupported(
- command: IncomingRequestCommand,
- chargingStation: ChargingStation
- ): boolean {
- const isIncomingRequestCommand = Object.values(IncomingRequestCommand).includes(command);
- if (
- isIncomingRequestCommand === true &&
- !chargingStation.stationInfo?.commandsSupport?.incomingCommands
- ) {
- return true;
- } else if (
- isIncomingRequestCommand === true &&
- chargingStation.stationInfo?.commandsSupport?.incomingCommands
- ) {
- return chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] ?? false;
- }
- logger.error(`${chargingStation.logPrefix()} Unknown incoming OCPP command '${command}'`);
- return false;
- }
-
private static getRandomSerialNumberSuffix(params?: {
randomBytesLength?: number;
upperCase?: boolean;
) {
if (
this.incomingRequestHandlers.has(commandName) &&
- ChargingStationUtils.isIncomingRequestCommandSupported(commandName, chargingStation)
+ OCPP16ServiceUtils.isIncomingRequestCommandSupported(commandName, chargingStation)
) {
try {
this.validatePayload(chargingStation, commandName, commandPayload);
) {
return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
}
- ChargingStationUtils.setChargingProfile(
+ OCPP16ServiceUtils.setChargingProfile(
chargingStation,
commandPayload.connectorId,
commandPayload.csChargingProfiles
cp: OCPP16ChargingProfile
): boolean {
if (cp && cp.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) {
- ChargingStationUtils.setChargingProfile(chargingStation, connectorId, cp);
+ OCPP16ServiceUtils.setChargingProfile(chargingStation, connectorId, cp);
logger.debug(
`${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}, dump their stack: %j`,
chargingStation.getConnectorStatus(connectorId).chargingProfiles
commandParams?: JsonType,
params?: RequestParams
): Promise<ResponseType> {
- if (ChargingStationUtils.isRequestCommandSupported(commandName, chargingStation)) {
+ if (OCPP16ServiceUtils.isRequestCommandSupported(commandName, chargingStation)) {
const requestPayload = this.buildRequestPayload<RequestType>(
chargingStation,
commandName,
if (chargingStation.isRegistered() || commandName === OCPP16RequestCommand.BOOT_NOTIFICATION) {
if (
this.responseHandlers.has(commandName) &&
- ChargingStationUtils.isRequestCommandSupported(commandName, chargingStation)
+ OCPP16ServiceUtils.isRequestCommandSupported(commandName, chargingStation)
) {
try {
this.validatePayload(chargingStation, commandName, payload);
// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+import BaseError from '../../../exception/BaseError';
import OCPPError from '../../../exception/OCPPError';
import { CurrentType, Voltage } from '../../../types/ChargingStationTemplate';
import type {
OCPP16IncomingRequestCommand,
OCPP16RequestCommand,
} from '../../../types/ocpp/1.6/Requests';
+import type { ChargingProfile } from '../../../types/ocpp/ChargingProfile';
+import { StandardParametersKey } from '../../../types/ocpp/Configuration';
import { ErrorType } from '../../../types/ocpp/ErrorType';
+import { MeterValueMeasurand, type MeterValuePhase } from '../../../types/ocpp/MeterValues';
import Constants from '../../../utils/Constants';
import { ACElectricUtils, DCElectricUtils } from '../../../utils/ElectricUtils';
import logger from '../../../utils/Logger';
import Utils from '../../../utils/Utils';
import type ChargingStation from '../../ChargingStation';
-import { ChargingStationUtils } from '../../ChargingStationUtils';
+import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils';
import { OCPPServiceUtils } from '../OCPPServiceUtils';
export class OCPP16ServiceUtils extends OCPPServiceUtils {
};
const connector = chargingStation.getConnectorStatus(connectorId);
// SoC measurand
- const socSampledValueTemplate = ChargingStationUtils.getSampledValueTemplate(
+ const socSampledValueTemplate = OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.STATE_OF_CHARGE
}
}
// Voltage measurand
- const voltageSampledValueTemplate = ChargingStationUtils.getSampledValueTemplate(
+ const voltageSampledValueTemplate = OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.VOLTAGE
) {
const phaseLineToNeutralValue = `L${phase}-N`;
const voltagePhaseLineToNeutralSampledValueTemplate =
- ChargingStationUtils.getSampledValueTemplate(
+ OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.VOLTAGE,
: chargingStation.getNumberOfPhases()
}`;
const voltagePhaseLineToLineSampledValueTemplate =
- ChargingStationUtils.getSampledValueTemplate(
+ OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.VOLTAGE,
}
}
// Power.Active.Import measurand
- const powerSampledValueTemplate = ChargingStationUtils.getSampledValueTemplate(
+ const powerSampledValueTemplate = OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.POWER_ACTIVE_IMPORT
let powerPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates = {};
if (chargingStation.getNumberOfPhases() === 3) {
powerPerPhaseSampledValueTemplates = {
- L1: ChargingStationUtils.getSampledValueTemplate(
+ L1: OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.POWER_ACTIVE_IMPORT,
OCPP16MeterValuePhase.L1_N
),
- L2: ChargingStationUtils.getSampledValueTemplate(
+ L2: OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.POWER_ACTIVE_IMPORT,
OCPP16MeterValuePhase.L2_N
),
- L3: ChargingStationUtils.getSampledValueTemplate(
+ L3: OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.POWER_ACTIVE_IMPORT,
}
}
// Current.Import measurand
- const currentSampledValueTemplate = ChargingStationUtils.getSampledValueTemplate(
+ const currentSampledValueTemplate = OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.CURRENT_IMPORT
let currentPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates = {};
if (chargingStation.getNumberOfPhases() === 3) {
currentPerPhaseSampledValueTemplates = {
- L1: ChargingStationUtils.getSampledValueTemplate(
+ L1: OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.CURRENT_IMPORT,
OCPP16MeterValuePhase.L1
),
- L2: ChargingStationUtils.getSampledValueTemplate(
+ L2: OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.CURRENT_IMPORT,
OCPP16MeterValuePhase.L2
),
- L3: ChargingStationUtils.getSampledValueTemplate(
+ L3: OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId,
OCPP16MeterValueMeasurand.CURRENT_IMPORT,
}
}
// Energy.Active.Import.Register measurand (default)
- const energySampledValueTemplate = ChargingStationUtils.getSampledValueTemplate(
+ const energySampledValueTemplate = OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId
);
sampledValue: [],
};
// Energy.Active.Import.Register measurand (default)
- const sampledValueTemplate = ChargingStationUtils.getSampledValueTemplate(
+ const sampledValueTemplate = OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId
);
sampledValue: [],
};
// Energy.Active.Import.Register measurand (default)
- const sampledValueTemplate = ChargingStationUtils.getSampledValueTemplate(
+ const sampledValueTemplate = OCPP16ServiceUtils.getSampledValueTemplate(
chargingStation,
connectorId
);
return meterValues;
}
+ public static setChargingProfile(
+ chargingStation: ChargingStation,
+ connectorId: number,
+ cp: ChargingProfile
+ ): void {
+ if (Utils.isNullOrUndefined(chargingStation.getConnectorStatus(connectorId).chargingProfiles)) {
+ logger.error(
+ `${chargingStation.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an uninitialized charging profiles array attribute, applying deferred initialization`
+ );
+ chargingStation.getConnectorStatus(connectorId).chargingProfiles = [];
+ }
+ if (Array.isArray(chargingStation.getConnectorStatus(connectorId).chargingProfiles) === false) {
+ logger.error(
+ `${chargingStation.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization`
+ );
+ chargingStation.getConnectorStatus(connectorId).chargingProfiles = [];
+ }
+ let cpReplaced = false;
+ if (!Utils.isEmptyArray(chargingStation.getConnectorStatus(connectorId).chargingProfiles)) {
+ chargingStation
+ .getConnectorStatus(connectorId)
+ .chargingProfiles?.forEach((chargingProfile: ChargingProfile, index: number) => {
+ if (
+ chargingProfile.chargingProfileId === cp.chargingProfileId ||
+ (chargingProfile.stackLevel === cp.stackLevel &&
+ chargingProfile.chargingProfilePurpose === cp.chargingProfilePurpose)
+ ) {
+ chargingStation.getConnectorStatus(connectorId).chargingProfiles[index] = cp;
+ cpReplaced = true;
+ }
+ });
+ }
+ !cpReplaced && chargingStation.getConnectorStatus(connectorId).chargingProfiles?.push(cp);
+ }
+
+ private static getSampledValueTemplate(
+ chargingStation: ChargingStation,
+ connectorId: number,
+ measurand: MeterValueMeasurand = MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER,
+ phase?: MeterValuePhase
+ ): SampledValueTemplate | undefined {
+ const onPhaseStr = phase ? `on phase ${phase} ` : '';
+ if (Constants.SUPPORTED_MEASURANDS.includes(measurand) === false) {
+ logger.warn(
+ `${chargingStation.logPrefix()} Trying to get unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
+ );
+ return;
+ }
+ if (
+ measurand !== MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
+ !ChargingStationConfigurationUtils.getConfigurationKey(
+ chargingStation,
+ StandardParametersKey.MeterValuesSampledData
+ )?.value.includes(measurand)
+ ) {
+ logger.debug(
+ `${chargingStation.logPrefix()} Trying to get MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId} not found in '${
+ StandardParametersKey.MeterValuesSampledData
+ }' OCPP parameter`
+ );
+ return;
+ }
+ const sampledValueTemplates: SampledValueTemplate[] =
+ chargingStation.getConnectorStatus(connectorId).MeterValues;
+ for (
+ let index = 0;
+ !Utils.isEmptyArray(sampledValueTemplates) && index < sampledValueTemplates.length;
+ index++
+ ) {
+ if (
+ Constants.SUPPORTED_MEASURANDS.includes(
+ sampledValueTemplates[index]?.measurand ??
+ MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
+ ) === false
+ ) {
+ logger.warn(
+ `${chargingStation.logPrefix()} Unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
+ );
+ } else if (
+ phase &&
+ sampledValueTemplates[index]?.phase === phase &&
+ sampledValueTemplates[index]?.measurand === measurand &&
+ ChargingStationConfigurationUtils.getConfigurationKey(
+ chargingStation,
+ StandardParametersKey.MeterValuesSampledData
+ )?.value.includes(measurand) === true
+ ) {
+ return sampledValueTemplates[index];
+ } else if (
+ !phase &&
+ !sampledValueTemplates[index].phase &&
+ sampledValueTemplates[index]?.measurand === measurand &&
+ ChargingStationConfigurationUtils.getConfigurationKey(
+ chargingStation,
+ StandardParametersKey.MeterValuesSampledData
+ )?.value.includes(measurand) === true
+ ) {
+ return sampledValueTemplates[index];
+ } else if (
+ measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
+ (!sampledValueTemplates[index].measurand ||
+ sampledValueTemplates[index].measurand === measurand)
+ ) {
+ return sampledValueTemplates[index];
+ }
+ }
+ if (measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER) {
+ const errorMsg = `Missing MeterValues for default measurand '${measurand}' in template on connectorId ${connectorId}`;
+ logger.error(`${chargingStation.logPrefix()} ${errorMsg}`);
+ throw new BaseError(errorMsg);
+ }
+ logger.debug(
+ `${chargingStation.logPrefix()} No MeterValues for measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
+ );
+ }
+
private static buildSampledValue(
sampledValueTemplate: SampledValueTemplate,
value: number,
import type { DefinedError, ErrorObject } from 'ajv';
import { ErrorType } from '../../types/ocpp/ErrorType';
+import { IncomingRequestCommand, RequestCommand } from '../../types/ocpp/Requests';
+import logger from '../../utils/Logger';
+import type ChargingStation from '../ChargingStation';
export class OCPPServiceUtils {
protected constructor() {
return ErrorType.FORMAT_VIOLATION;
}
+ public static isRequestCommandSupported(
+ command: RequestCommand,
+ chargingStation: ChargingStation
+ ): boolean {
+ const isRequestCommand = Object.values(RequestCommand).includes(command);
+ if (
+ isRequestCommand === true &&
+ !chargingStation.stationInfo?.commandsSupport?.outgoingCommands
+ ) {
+ return true;
+ } else if (
+ isRequestCommand === true &&
+ chargingStation.stationInfo?.commandsSupport?.outgoingCommands
+ ) {
+ return chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command] ?? false;
+ }
+ logger.error(`${chargingStation.logPrefix()} Unknown outgoing OCPP command '${command}'`);
+ return false;
+ }
+
+ public static isIncomingRequestCommandSupported(
+ command: IncomingRequestCommand,
+ chargingStation: ChargingStation
+ ): boolean {
+ const isIncomingRequestCommand = Object.values(IncomingRequestCommand).includes(command);
+ if (
+ isIncomingRequestCommand === true &&
+ !chargingStation.stationInfo?.commandsSupport?.incomingCommands
+ ) {
+ return true;
+ } else if (
+ isIncomingRequestCommand === true &&
+ chargingStation.stationInfo?.commandsSupport?.incomingCommands
+ ) {
+ return chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] ?? false;
+ }
+ logger.error(`${chargingStation.logPrefix()} Unknown incoming OCPP command '${command}'`);
+ return false;
+ }
+
protected static getLimitFromSampledValueTemplateCustomValue(
value: string,
limit: number,
import logger from '../../utils/Logger';
import Utils from '../../utils/Utils';
import { AbstractUIServer } from './AbstractUIServer';
-import { UIServiceUtils } from './ui-services/UIServiceUtils';
+import { UIServerUtils } from './UIServerUtils';
const moduleName = 'UIHttpServer';
this.responseHandlers.set(uuid, res);
try {
const fullProtocol = `${protocol}${version}`;
- if (UIServiceUtils.isProtocolAndVersionSupported(fullProtocol) === false) {
+ if (UIServerUtils.isProtocolAndVersionSupported(fullProtocol) === false) {
throw new BaseError(`Unsupported UI protocol version: '${fullProtocol}'`);
}
this.registerProtocolVersionUIService(version);
import { ApplicationProtocol } from '../../types/UIProtocol';
import Configuration from '../../utils/Configuration';
import type { AbstractUIServer } from './AbstractUIServer';
-import { UIServiceUtils } from './ui-services/UIServiceUtils';
import UIHttpServer from './UIHttpServer';
+import { UIServerUtils } from './UIServerUtils';
import UIWebSocketServer from './UIWebSocketServer';
export default class UIServerFactory {
public static getUIServerImplementation(
uiServerConfiguration?: UIServerConfiguration
): AbstractUIServer | null {
- if (UIServiceUtils.isLoopback(uiServerConfiguration.options?.host) === false) {
+ if (UIServerUtils.isLoopback(uiServerConfiguration.options?.host) === false) {
console.warn(
chalk.yellow(
'Loopback address not detected in UI server configuration. This is not recommended.'
import type { IncomingMessage } from 'http';
-import { Protocol, ProtocolVersion } from '../../../types/UIProtocol';
-import logger from '../../../utils/Logger';
-import Utils from '../../../utils/Utils';
+import { Protocol, ProtocolVersion } from '../../types/UIProtocol';
+import logger from '../../utils/Logger';
+import Utils from '../../utils/Utils';
-export class UIServiceUtils {
+export class UIServerUtils {
private constructor() {
// This is intentional
}
return false;
}
for (const fullProtocol of protocols) {
- if (UIServiceUtils.isProtocolAndVersionSupported(fullProtocol) === true) {
+ if (UIServerUtils.isProtocolAndVersionSupported(fullProtocol) === true) {
return fullProtocol;
}
}
};
public static isProtocolAndVersionSupported = (protocolStr: string): boolean => {
- const [protocol, version] = UIServiceUtils.getProtocolAndVersion(protocolStr);
+ const [protocol, version] = UIServerUtils.getProtocolAndVersion(protocolStr);
return (
Object.values(Protocol).includes(protocol) === true &&
Object.values(ProtocolVersion).includes(version) === true
import logger from '../../utils/Logger';
import Utils from '../../utils/Utils';
import { AbstractUIServer } from './AbstractUIServer';
-import { UIServiceUtils } from './ui-services/UIServiceUtils';
+import { UIServerUtils } from './UIServerUtils';
const moduleName = 'UIWebSocketServer';
public constructor(protected readonly uiServerConfiguration: UIServerConfiguration) {
super(uiServerConfiguration);
this.webSocketServer = new WebSocketServer({
- handleProtocols: UIServiceUtils.handleProtocols,
+ handleProtocols: UIServerUtils.handleProtocols,
noServer: true,
});
}
public start(): void {
this.webSocketServer.on('connection', (ws: WebSocket, req: IncomingMessage): void => {
- if (UIServiceUtils.isProtocolAndVersionSupported(ws.protocol) === false) {
+ if (UIServerUtils.isProtocolAndVersionSupported(ws.protocol) === false) {
logger.error(
`${this.logPrefix(
moduleName,
);
ws.close(WebSocketCloseEventStatusCode.CLOSE_PROTOCOL_ERROR);
}
- const [, version] = UIServiceUtils.getProtocolAndVersion(ws.protocol);
+ const [, version] = UIServerUtils.getProtocolAndVersion(ws.protocol);
this.registerProtocolVersionUIService(version);
ws.on('message', (rawData) => {
const request = this.validateRawDataRequest(rawData);