import { ProtocolCommand, ProtocolRequestHandler } from '../../types/UIProtocol';
import BaseError from '../../exception/BaseError';
-import { JsonType } from '../../types/JsonType';
+import { JsonObject } from '../../types/JsonType';
import UIWebSocketServer from '../UIWebSocketServer';
import logger from '../../utils/Logger';
]);
}
- public async messageHandler(command: ProtocolCommand, payload: JsonType): Promise<void> {
- let messageResponse: JsonType;
+ public async messageHandler(command: ProtocolCommand, payload: JsonObject): Promise<void> {
+ let messageResponse: JsonObject;
if (this.messageHandlers.has(command)) {
try {
// Call the method to build the message response
- messageResponse = (await this.messageHandlers.get(command)(payload)) as JsonType;
+ messageResponse = (await this.messageHandlers.get(command)(payload)) as JsonObject;
} catch (error) {
// Log
logger.error(this.uiWebSocketServer.logPrefix() + ' Handle message error: %j', error);
this.uiWebSocketServer.broadcastToClients(this.buildProtocolMessage(command, messageResponse));
}
- protected buildProtocolMessage(command: ProtocolCommand, payload: JsonType): string {
+ protected buildProtocolMessage(command: ProtocolCommand, payload: JsonObject): string {
return JSON.stringify([command, payload]);
}