fix tslint errors
This commit is contained in:
@@ -10,7 +10,7 @@ export let SparkplugPayload = root.lookupType('com.cirruslink.sparkplug.protobuf
|
|||||||
export const SparkplugDecoder = {
|
export const SparkplugDecoder = {
|
||||||
decode(input: Buffer): Base64Message | undefined {
|
decode(input: Buffer): Base64Message | undefined {
|
||||||
try {
|
try {
|
||||||
let message = Base64Message.fromString(
|
const message = Base64Message.fromString(
|
||||||
JSON.stringify(SparkplugPayload.toObject(SparkplugPayload.decode(new Uint8Array(input))))
|
JSON.stringify(SparkplugPayload.toObject(SparkplugPayload.decode(new Uint8Array(input))))
|
||||||
)
|
)
|
||||||
message.decoder = Decoder.SPARKPLUG
|
message.decoder = Decoder.SPARKPLUG
|
||||||
|
|||||||
@@ -2,24 +2,25 @@ import { Event } from '../Events'
|
|||||||
import { EventBusInterface } from './EventBusInterface'
|
import { EventBusInterface } from './EventBusInterface'
|
||||||
import { v4 } from 'uuid'
|
import { v4 } from 'uuid'
|
||||||
|
|
||||||
export type RpcEvent<RequstType, ResponseType> = {
|
export type RpcEvent<RequestType, ResponseType> = {
|
||||||
topic: string
|
topic: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Rpc {
|
export class Rpc {
|
||||||
constructor(private participant: EventBusInterface) {}
|
constructor(private participant: EventBusInterface) {}
|
||||||
|
|
||||||
|
// tslint:disable-next-line:member-access
|
||||||
async call<RpcRequest, RpcResponse>(
|
async call<RpcRequest, RpcResponse>(
|
||||||
event: RpcEvent<RpcRequest, RpcResponse>,
|
event: RpcEvent<RpcRequest, RpcResponse>,
|
||||||
request: RpcRequest,
|
request: RpcRequest,
|
||||||
timeout: number = 0
|
timeout: number = 0
|
||||||
): Promise<RpcResponse> {
|
): Promise<RpcResponse> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let id = v4()
|
const id = v4()
|
||||||
|
|
||||||
let responseEvent: Event<any> = { topic: `${event.topic}/response/${id}` }
|
const responseEvent: Event<any> = { topic: `${event.topic}/response/${id}` }
|
||||||
let requestEvent: Event<any> = { topic: `${event.topic}/request` }
|
const requestEvent: Event<any> = { topic: `${event.topic}/request` }
|
||||||
let callback = (result: { id: string; payload: RpcResponse; error: unknown }) => {
|
const callback = (result: { id: string; payload: RpcResponse; error: unknown }) => {
|
||||||
this.participant.unsubscribe(responseEvent as any, callback)
|
this.participant.unsubscribe(responseEvent as any, callback)
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
reject(result.error)
|
reject(result.error)
|
||||||
@@ -40,11 +41,12 @@ export class Rpc {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tslint:disable-next-line:member-access
|
||||||
async on<RpcRequest, RpcResponse>(
|
async on<RpcRequest, RpcResponse>(
|
||||||
event: RpcEvent<RpcRequest, RpcResponse>,
|
event: RpcEvent<RpcRequest, RpcResponse>,
|
||||||
handler: (request: RpcRequest) => Promise<RpcResponse>
|
handler: (request: RpcRequest) => Promise<RpcResponse>
|
||||||
) {
|
) {
|
||||||
this.participant.subscribe<RpcRequest>({ topic: `${event.topic}/request` } as RpcEvent<any, any>, async request => {
|
this.participant.subscribe<RpcRequest>({ topic: `${event.topic}/request` }, async request => {
|
||||||
let payload
|
let payload
|
||||||
let error
|
let error
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -52,5 +52,5 @@ export function makeConnectionMessageEvent(connectionId: string): Event<MqttMess
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getAppVersion: RpcEvent<void, string> = {
|
export const getAppVersion: RpcEvent<void, string> = {
|
||||||
topic: `getAppVersion`,
|
topic: 'getAppVersion',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ import { RpcEvent } from './EventSystem/Rpc'
|
|||||||
|
|
||||||
export function makeOpenDialogRpc(): RpcEvent<OpenDialogOptions, OpenDialogReturnValue> {
|
export function makeOpenDialogRpc(): RpcEvent<OpenDialogOptions, OpenDialogReturnValue> {
|
||||||
return {
|
return {
|
||||||
topic: `openDialog`,
|
topic: 'openDialog',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user