Upgraded to WebSocket 8.2.2
MODIFY
package-lock.json
package-lock.json
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
+ },
+ "ws": {
+ "version": "7.4.6",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
+ "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A=="
}
}
},
}
},
"ws": {
- "version": "7.4.6",
- "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
- "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A=="
+ "version": "8.2.2",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.2.2.tgz",
+ "integrity": "sha512-Q6B6H2oc8QY3llc3cB8kVmQ6pnJWVQbP7Q5algTcIxx7YEpc0oU4NBVHlztA7Ekzfhw2r0rPducMUiCGWKQRzw=="
},
"xdg-basedir": {
"version": "3.0.0",

MODIFY
package.json
package.json
"urlencode": "^1.1.0",
"uuid": "^8.3.2",
"validator": "^13.6.0",
- "ws": "^7.4.6"
+ "ws": "^8.2.2"
},
"optionalDependencies": {
"bufferutil": "^4.0.4",

MODIFY
src/server/ocpp/json/JsonCentralSystemServer.ts
src/server/ocpp/json/JsonCentralSystemServer.ts
import { ServerAction, WSServerProtocol } from '../../../types/Server';
+import http, { IncomingMessage } from 'http';
import CentralSystemConfiguration from '../../../types/configuration/CentralSystemConfiguration';
import CentralSystemServer from '../CentralSystemServer';
@@ -15,7 +16,6 @@ import WSServer from './WSServer';
import WebSocket from 'ws';
import { WebSocketCloseEventStatusCode } from '../../../types/WebSocket';
import global from '../../../types/GlobalType';
-import http from 'http';
const MODULE_NAME = 'JsonCentralSystemServer';
@@ -119,20 +119,14 @@ export default class JsonCentralSystemServer extends CentralSystemServer {
return false;
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
- const handleProtocols = (protocols: WSServerProtocol | WSServerProtocol[], request: http.IncomingMessage): boolean | WSServerProtocol => {
+ const handleProtocols = (protocols: Set<string>, request: IncomingMessage): string | false => {
// Check the protocols and ensure protocol used as ocpp1.6 or nothing (should create an error)
- if (!Utils.isEmptyArray(protocols)) {
- if (protocols.includes(WSServerProtocol.OCPP16)) {
+ if (protocols?.has(WSServerProtocol.OCPP16)) {
return WSServerProtocol.OCPP16;
}
- if (protocols.includes(WSServerProtocol.REST)) {
+ if (protocols?.has(WSServerProtocol.REST)) {
return WSServerProtocol.REST;
}
- } else if (protocols === WSServerProtocol.OCPP16) {
- return protocols;
- } else if (protocols === WSServerProtocol.REST) {
- return protocols;
- }
void Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
module: MODULE_NAME, method: 'handleProtocols',

MODIFY
src/server/ocpp/json/WSServer.ts
src/server/ocpp/json/WSServer.ts
+import http, { IncomingMessage } from 'http';
+
import CentralSystemServerConfiguration from '../../../types/configuration/CentralSystemServerConfiguration';
import { ServerUtils } from '../../ServerUtils';
-import { WSServerProtocol } from '../../../types/Server';
import WebSocket from 'ws';
-import http from 'http';
const MODULE_NAME = 'WSServer';
@@ -13,7 +13,7 @@ export default class WSServer extends WebSocket.Server {
public constructor(serverConfig: CentralSystemServerConfiguration, serverName: string,
verifyClientCb: WebSocket.VerifyClientCallbackAsync | WebSocket.VerifyClientCallbackSync = (): void => { },
- handleProtocolsCb: (protocols: WSServerProtocol | WSServerProtocol[], request: http.IncomingMessage) => boolean | string = (protocols, request) => '') {
+ handleProtocolsCb: (protocols: Set<string>, request: IncomingMessage) => string | false = (protocols, request) => '') {
const httpServer = ServerUtils.createHttpServer(serverConfig);
// Create the WebSocket Server
super({

Upgraded to WebSocket 8.2.2