repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'main' into reservation-feature
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ui-server
/
UIWebSocketServer.ts
diff --git
a/src/charging-station/ui-server/UIWebSocketServer.ts
b/src/charging-station/ui-server/UIWebSocketServer.ts
index 291e92631bc2864dda4a77c18fd702cf2763263c..dd5b6163576dc86b7bb22bb93c9cdb7223e31e91 100644
(file)
--- a/
src/charging-station/ui-server/UIWebSocketServer.ts
+++ b/
src/charging-station/ui-server/UIWebSocketServer.ts
@@
-4,14
+4,15
@@
import type { Duplex } from 'node:stream';
import { StatusCodes } from 'http-status-codes';
import WebSocket, { type RawData, WebSocketServer } from 'ws';
import { StatusCodes } from 'http-status-codes';
import WebSocket, { type RawData, WebSocketServer } from 'ws';
+import { AbstractUIServer } from './AbstractUIServer';
+import { UIServerUtils } from './UIServerUtils';
import {
type ProtocolRequest,
type ProtocolResponse,
type UIServerConfiguration,
WebSocketCloseEventStatusCode,
} from '../../types';
import {
type ProtocolRequest,
type ProtocolResponse,
type UIServerConfiguration,
WebSocketCloseEventStatusCode,
} from '../../types';
-import { Utils, logger } from '../../utils';
-import { AbstractUIServer, UIServerUtils } from '../internal';
+import { Constants, Utils, logger } from '../../utils';
const moduleName = 'UIWebSocketServer';
const moduleName = 'UIWebSocketServer';
@@
-51,9
+52,12
@@
export class UIWebSocketServer extends AbstractUIServer {
this.uiServices
.get(version)
?.requestHandler(request)
this.uiServices
.get(version)
?.requestHandler(request)
- .catch(() => {
- /* Error caught by AbstractUIService */
- });
+ .then((protocolResponse: ProtocolResponse) => {
+ if (!Utils.isNullOrUndefined(protocolResponse)) {
+ this.sendResponse(protocolResponse);
+ }
+ })
+ .catch(Constants.EMPTY_FUNCTION);
});
ws.on('error', (error) => {
logger.error(`${this.logPrefix(moduleName, 'start.ws.onerror')} WebSocket error:`, error);
});
ws.on('error', (error) => {
logger.error(`${this.logPrefix(moduleName, 'start.ws.onerror')} WebSocket error:`, error);
@@
-108,7
+112,7
@@
export class UIWebSocketServer extends AbstractUIServer {
public sendResponse(response: ProtocolResponse): void {
const responseId = response[0];
try {
public sendResponse(response: ProtocolResponse): void {
const responseId = response[0];
try {
- if (this.
responseHandlers.has
(responseId)) {
+ if (this.
hasResponseHandler
(responseId)) {
const ws = this.responseHandlers.get(responseId) as WebSocket;
if (ws?.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(response));
const ws = this.responseHandlers.get(responseId) as WebSocket;
if (ws?.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(response));