Use camel case everywhere
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-websocket-services / UIServiceUtils.ts
1 import { Protocol, ProtocolVersion } from '../../types/UiProtocol';
2
3 import { IncomingMessage } from 'http';
4 import Utils from '../../utils/Utils';
5 import logger from '../../utils/Logger';
6
7 export class UIServiceUtils {
8 public static handleProtocols = (protocols: Set<string>, request: IncomingMessage): string | false => {
9 let protocolIndex: number;
10 let protocol: Protocol;
11 let version: ProtocolVersion;
12 for (const fullProtocol of protocols) {
13 protocolIndex = fullProtocol.indexOf(Protocol.UI);
14 protocol = fullProtocol.substring(protocolIndex, protocolIndex + Protocol.UI.length) as Protocol;
15 version = fullProtocol.substring(protocolIndex + Protocol.UI.length) as ProtocolVersion;
16 if (Object.values(Protocol).includes(protocol) && Object.values(ProtocolVersion).includes(version)) {
17 return fullProtocol;
18 }
19 }
20 logger.error(`${Utils.logPrefix(' UI WebSocket Server:')} Unsupported protocol: ${protocol} or protocol version: ${version}`);
21 return false;
22 };
23 }