import * as uuid from 'uuid/v4' import { RPCParams, RPCPayload, RPCRequestMethod, TopicServiceName, TopicType } from '../types' import { RPCInternalResponseTopic, RPCRequestTopic, RPCResponseTopic } from './topicBuilder' export class RPCRequest { private _serviceName: TopicServiceName private _clientId: string private readonly _method: RPCRequestMethod private readonly _params: RPCParams private readonly _requestId: string private readonly _deviceId?: string constructor ( clientId: string, serviceName: TopicServiceName, method: RPCRequestMethod, params: RPCParams, deviceId?: string ) { this._serviceName = serviceName this._clientId = clientId this._method = method this._params = params this._requestId = uuid() this._deviceId = deviceId } public get requestId (): string { return this._requestId } public get publishTopic (): string { return new RPCRequestTopic(this._serviceName, this._deviceId).topic } public get subscribeTopic (): string { return new RPCResponseTopic(this._clientId).topic } public get eventTopic (): string { return new RPCInternalResponseTopic(TopicType.RPC_RESPONSE, this.requestId).topic } public get payload (): RPCPayload { return { requestId: this.requestId, method: this._method, params: this._params, } } }