2021-05-12 06:35:00 +00:00
|
|
|
import { ServiceError, StatusObject } from '@grpc/grpc-js';
|
2021-07-22 23:04:56 +00:00
|
|
|
import { IpcMainEvent } from 'electron';
|
|
|
|
|
2021-12-09 13:23:20 +00:00
|
|
|
import { GrpcResponseEventEnum } from '../../common/grpc-events';
|
2020-11-10 00:30:27 +00:00
|
|
|
interface IResponseCallbacks {
|
2021-05-12 06:35:00 +00:00
|
|
|
sendData(requestId: string, val: Record<string, any> | undefined): void;
|
2020-11-10 00:30:27 +00:00
|
|
|
sendError(requestId: string, err: ServiceError): void;
|
2020-11-11 22:44:03 +00:00
|
|
|
sendStart(requestId: string): void;
|
|
|
|
sendEnd(requestId: string): void;
|
2021-05-12 06:35:00 +00:00
|
|
|
sendStatus(requestId: string, status: StatusObject): void;
|
2020-11-10 00:30:27 +00:00
|
|
|
}
|
|
|
|
export class ResponseCallbacks implements IResponseCallbacks {
|
2021-05-12 06:35:00 +00:00
|
|
|
_event: IpcMainEvent;
|
2020-11-10 00:30:27 +00:00
|
|
|
|
|
|
|
constructor(e: IpcMainEvent) {
|
|
|
|
this._event = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendData(requestId, val) {
|
|
|
|
this._event.reply(GrpcResponseEventEnum.data, requestId, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendError(requestId, err) {
|
|
|
|
this._event.reply(GrpcResponseEventEnum.error, requestId, err);
|
|
|
|
}
|
2020-11-11 22:44:03 +00:00
|
|
|
|
|
|
|
sendStart(requestId) {
|
|
|
|
this._event.reply(GrpcResponseEventEnum.start, requestId);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendEnd(requestId) {
|
|
|
|
this._event.reply(GrpcResponseEventEnum.end, requestId);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendStatus(requestId, status) {
|
|
|
|
this._event.reply(GrpcResponseEventEnum.status, requestId, status);
|
|
|
|
}
|
2020-11-10 00:30:27 +00:00
|
|
|
}
|