-import Utils from './Utils';
+import { promiseWithTimeout } from './Utils';
import {
ProcedureName,
type ProtocolResponse,
reject: (reason?: unknown) => void;
};
-export default class UIClient {
+export class UIClient {
private static instance: UIClient | null = null;
private ws!: WebSocket;
public async startTransaction(
hashId: string,
connectorId: number,
- idTag: string | undefined
+ idTag: string | undefined,
): Promise<ResponsePayload> {
return this.sendRequest(ProcedureName.START_TRANSACTION, {
hashIds: [hashId],
public async stopTransaction(
hashId: string,
- transactionId: number | undefined
+ transactionId: number | undefined,
): Promise<ResponsePayload> {
return this.sendRequest(ProcedureName.STOP_TRANSACTION, {
hashIds: [hashId],
public async startAutomaticTransactionGenerator(
hashId: string,
- connectorId: number
+ connectorId: number,
): Promise<ResponsePayload> {
return this.sendRequest(ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR, {
hashIds: [hashId],
public async stopAutomaticTransactionGenerator(
hashId: string,
- connectorId: number
+ connectorId: number,
): Promise<ResponsePayload> {
return this.sendRequest(ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR, {
hashIds: [hashId],
private openWS(): void {
this.ws = new WebSocket(
`ws://${config.uiServer.host}:${config.uiServer.port}`,
- config.uiServer.protocol
+ config.uiServer.protocol,
);
this.ws.onmessage = this.responseHandler.bind(this);
this.ws.onerror = (errorEvent) => {
id: string,
procedureName: ProcedureName,
resolve: (value: ResponsePayload | PromiseLike<ResponsePayload>) => void,
- reject: (reason?: any) => void
+ reject: (reason?: unknown) => void,
): void {
this.responseHandlers.set(id, { procedureName, resolve, reject });
}
private async sendRequest(
command: ProcedureName,
- data: RequestPayload
+ data: RequestPayload,
): Promise<ResponsePayload> {
let uuid: string;
- return Utils.promiseWithTimeout(
- new Promise((resolve, reject) => {
+ return promiseWithTimeout(
+ new Promise<ResponsePayload>((resolve, reject) => {
uuid = crypto.randomUUID();
const msg = JSON.stringify([uuid, command, data]);
Error(`Send request '${command}' message timeout`),
() => {
this.responseHandlers.delete(uuid);
- }
+ },
);
}