| logLevel | emerg/alert/crit/error/warning/notice/info/debug | info | string | winston logging level |
| logFile | | combined.log | string | log file relative path |
| logErrorFile | | error.log | string | error log file relative path |
-| uiWebSocketServer | | { "enabled": true, "options": { "host: "localhost", "port": 8080 } } | { enabled: boolean; options: ServerOptions; } | UI WebSocket server configuration section |
+| uiServer | | { "enabled": true, "options": { "host: "localhost", "port": 8080 } } | { enabled: boolean; options: ServerOptions; } | UI WebSocket server configuration section |
| performanceStorage | | { "enabled": false, "type": "jsonfile", "file:///performanceRecords.json" } | { enabled: boolean; type: string; URI: string; } where type can be 'jsonfile' or 'mongodb' | performance storage configuration section |
| stationTemplateUrls | | {}[] | { file: string; numberOfStations: number; }[] | array of charging station configuration templates URIs configuration section (charging station configuration template file name and number of stations) |
import Statistics from '../types/Statistics';
import { Storage } from '../performance/storage/Storage';
import { StorageFactory } from '../performance/storage/StorageFactory';
-import { UIServiceUtils } from './ui-websocket-services/UIServiceUtils';
-import UIWebSocketServer from './UIWebSocketServer';
+import { UIServiceUtils } from './ui-server/ui-services/UIServiceUtils';
+import UIWebSocketServer from './ui-server/UIWebSocketServer';
import Utils from '../utils/Utils';
import WorkerAbstract from '../worker/WorkerAbstract';
import WorkerFactory from '../worker/WorkerFactory';
export default class Bootstrap {
private static instance: Bootstrap | null = null;
private workerImplementation: WorkerAbstract<ChargingStationWorkerData> | null = null;
- private readonly uiWebSocketServer!: UIWebSocketServer;
+ private readonly uiServer!: UIWebSocketServer;
private readonly storage!: Storage;
private numberOfChargingStations: number;
private readonly version: string = version;
'ChargingStationWorker.js'
);
this.initWorkerImplementation();
- Configuration.getUIWebSocketServer().enabled &&
- (this.uiWebSocketServer = new UIWebSocketServer({
- ...Configuration.getUIWebSocketServer().options,
+ Configuration.getUIServer().enabled &&
+ (this.uiServer = new UIWebSocketServer({
+ ...Configuration.getUIServer().options,
handleProtocols: UIServiceUtils.handleProtocols,
}));
Configuration.getPerformanceStorage().enabled &&
this.numberOfChargingStations = 0;
await this.storage?.open();
await this.workerImplementation.start();
- this.uiWebSocketServer?.start();
+ this.uiServer?.start();
const stationTemplateUrls = Configuration.getStationTemplateUrls();
// Start ChargingStation object in worker thread
if (stationTemplateUrls) {
public async stop(): Promise<void> {
if (isMainThread && this.started) {
await this.workerImplementation.stop();
- this.uiWebSocketServer?.stop();
+ this.uiServer?.stop();
await this.storage?.close();
} else {
console.error(chalk.red('Trying to stop the charging stations simulator while not started'));
},
messageHandler: async (msg: ChargingStationWorkerMessage) => {
if (msg.id === ChargingStationWorkerMessageEvents.STARTED) {
- this.uiWebSocketServer.chargingStations.add(msg.data.id as string);
+ this.uiServer.chargingStations.add(msg.data.id as string);
} else if (msg.id === ChargingStationWorkerMessageEvents.STOPPED) {
- this.uiWebSocketServer.chargingStations.delete(msg.data.id as string);
+ this.uiServer.chargingStations.delete(msg.data.id as string);
} else if (msg.id === ChargingStationWorkerMessageEvents.PERFORMANCE_STATISTICS) {
await this.storage.storePerformanceStatistics(msg.data as unknown as Statistics);
}
-import { Protocol, ProtocolVersion } from '../types/UIProtocol';
+import { Protocol, ProtocolVersion } from '../../types/UIProtocol';
import WebSocket, { OPEN, Server, ServerOptions } from 'ws';
-import AbstractUIService from './ui-websocket-services/AbstractUIService';
-import Configuration from '../utils/Configuration';
+import AbstractUIService from './ui-services/AbstractUIService';
+import Configuration from '../../utils/Configuration';
import { IncomingMessage } from 'http';
-import UIServiceFactory from './ui-websocket-services/UIServiceFactory';
-import Utils from '../utils/Utils';
-import logger from '../utils/Logger';
+import UIServiceFactory from './ui-services/UIServiceFactory';
+import Utils from '../../utils/Utils';
+import logger from '../../utils/Logger';
export default class UIWebSocketServer extends Server {
public readonly chargingStations: Set<string>;
public constructor(options?: ServerOptions, callback?: () => void) {
// Create the WebSocket Server
- super(options ?? Configuration.getUIWebSocketServer().options, callback);
+ super(options ?? Configuration.getUIServer().options, callback);
this.chargingStations = new Set<string>();
this.uiServices = new Map<ProtocolVersion, AbstractUIService>();
}
-import { ProtocolCommand, ProtocolRequest, ProtocolRequestHandler } from '../../types/UIProtocol';
+import {
+ ProtocolCommand,
+ ProtocolRequest,
+ ProtocolRequestHandler,
+} from '../../../types/UIProtocol';
-import BaseError from '../../exception/BaseError';
-import { JsonType } from '../../types/JsonType';
+import BaseError from '../../../exception/BaseError';
+import { JsonType } from '../../../types/JsonType';
import { RawData } from 'ws';
import UIWebSocketServer from '../UIWebSocketServer';
-import Utils from '../../utils/Utils';
-import logger from '../../utils/Logger';
+import Utils from '../../../utils/Utils';
+import logger from '../../../utils/Logger';
export default abstract class AbstractUIService {
- protected readonly uiWebSocketServer: UIWebSocketServer;
+ protected readonly uiServer: UIWebSocketServer;
protected readonly messageHandlers: Map<ProtocolCommand, ProtocolRequestHandler>;
- constructor(uiWebSocketServer: UIWebSocketServer) {
- this.uiWebSocketServer = uiWebSocketServer;
+ constructor(uiServer: UIWebSocketServer) {
+ this.uiServer = uiServer;
this.messageHandlers = new Map<ProtocolCommand, ProtocolRequestHandler>([
[ProtocolCommand.LIST_CHARGING_STATIONS, this.handleListChargingStations.bind(this)],
]);
messageResponse = (await this.messageHandlers.get(command)(payload)) as JsonType;
} catch (error) {
// Log
- logger.error(this.uiWebSocketServer.logPrefix() + ' Handle message error: %j', error);
+ logger.error(this.uiServer.logPrefix() + ' Handle message error: %j', error);
throw error;
}
} else {
);
}
// Send the message response
- this.uiWebSocketServer.sendResponse(this.buildProtocolMessage(command, messageResponse));
+ this.uiServer.sendResponse(this.buildProtocolMessage(command, messageResponse));
}
protected buildProtocolMessage(command: ProtocolCommand, payload: JsonType): string {
}
private handleListChargingStations(): JsonType {
- return Array.from(this.uiWebSocketServer.chargingStations);
+ return Array.from(this.uiServer.chargingStations);
}
}
-import { ProtocolCommand, ProtocolRequestHandler } from '../../types/UIProtocol';
+import { ProtocolCommand, ProtocolRequestHandler } from '../../../types/UIProtocol';
import AbstractUIService from './AbstractUIService';
-import { JsonType } from '../../types/JsonType';
+import { JsonType } from '../../../types/JsonType';
import UIWebSocketServer from '../UIWebSocketServer';
export default class UIService001 extends AbstractUIService {
- constructor(uiWebSocketServer: UIWebSocketServer) {
- super(uiWebSocketServer);
+ constructor(uiServer: UIWebSocketServer) {
+ super(uiServer);
this.messageHandlers.set(
ProtocolCommand.START_TRANSACTION,
this.handleStartTransaction.bind(this) as ProtocolRequestHandler
import AbstractUIService from './AbstractUIService';
-import { ProtocolVersion } from '../../types/UIProtocol';
+import { ProtocolVersion } from '../../../types/UIProtocol';
import UIService001 from './UIService001';
import UIWebSocketServer from '../UIWebSocketServer';
public static getUIServiceImplementation(
version: ProtocolVersion,
- uiWebSocketServer: UIWebSocketServer
+ uiServer: UIWebSocketServer
): AbstractUIService | null {
switch (version) {
case ProtocolVersion['0.0.1']:
- return new UIService001(uiWebSocketServer);
+ return new UIService001(uiServer);
default:
return null;
}
-import { Protocol, ProtocolVersion } from '../../types/UIProtocol';
+import { Protocol, ProtocolVersion } from '../../../types/UIProtocol';
import { IncomingMessage } from 'http';
-import Utils from '../../utils/Utils';
-import logger from '../../utils/Logger';
+import Utils from '../../../utils/Utils';
+import logger from '../../../utils/Logger';
export class UIServiceUtils {
public static handleProtocols = (
numberOfStations: number;
}
-export interface UIWebSocketServerConfiguration {
+export interface UIServerConfiguration {
enabled?: boolean;
options?: ServerOptions;
}
supervisionUrls?: string | string[];
supervisionUrlDistribution?: SupervisionUrlDistribution;
stationTemplateUrls: StationTemplateUrl[];
- uiWebSocketServer?: UIWebSocketServerConfiguration;
+ uiServer?: UIServerConfiguration;
performanceStorage?: StorageConfiguration;
autoReconnectMaxRetries?: number;
workerProcess?: WorkerProcessType;
UI = 'ui',
}
+export enum ApplicationProtocol {
+ HTTP = 'http',
+ WS = 'ws',
+}
+
export enum ProtocolVersion {
'0.0.1' = '0.0.1',
}
StationTemplateUrl,
StorageConfiguration,
SupervisionUrlDistribution,
- UIWebSocketServerConfiguration,
+ UIServerConfiguration,
} from '../types/ConfigurationData';
import Constants from './Constants';
: Constants.DEFAULT_LOG_STATISTICS_INTERVAL;
}
- static getUIWebSocketServer(): UIWebSocketServerConfiguration {
+ static getUIServer(): UIServerConfiguration {
let options: ServerOptions = {
host: Constants.DEFAULT_UI_WEBSOCKET_SERVER_HOST,
port: Constants.DEFAULT_UI_WEBSOCKET_SERVER_PORT,
};
- let uiWebSocketServerConfiguration: UIWebSocketServerConfiguration = {
+ let uiServerConfiguration: UIServerConfiguration = {
enabled: true,
options,
};
- if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'uiWebSocketServer')) {
- if (
- Configuration.objectHasOwnProperty(Configuration.getConfig().uiWebSocketServer, 'options')
- ) {
+ if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'uiServer')) {
+ if (Configuration.objectHasOwnProperty(Configuration.getConfig().uiServer, 'options')) {
options = {
...options,
...(Configuration.objectHasOwnProperty(
- Configuration.getConfig().uiWebSocketServer.options,
+ Configuration.getConfig().uiServer.options,
'host'
- ) && { host: Configuration.getConfig().uiWebSocketServer.options.host }),
+ ) && { host: Configuration.getConfig().uiServer.options.host }),
...(Configuration.objectHasOwnProperty(
- Configuration.getConfig().uiWebSocketServer.options,
+ Configuration.getConfig().uiServer.options,
'port'
- ) && { port: Configuration.getConfig().uiWebSocketServer.options.port }),
+ ) && { port: Configuration.getConfig().uiServer.options.port }),
};
}
- uiWebSocketServerConfiguration = {
- ...uiWebSocketServerConfiguration,
- ...(Configuration.objectHasOwnProperty(
- Configuration.getConfig().uiWebSocketServer,
- 'enabled'
- ) && { enabled: Configuration.getConfig().uiWebSocketServer.enabled }),
+ uiServerConfiguration = {
+ ...uiServerConfiguration,
+ ...(Configuration.objectHasOwnProperty(Configuration.getConfig().uiServer, 'enabled') && {
+ enabled: Configuration.getConfig().uiServer.enabled,
+ }),
options,
};
}
- return uiWebSocketServerConfiguration;
+ return uiServerConfiguration;
}
static getPerformanceStorage(): StorageConfiguration {