matterbridge-roborock-vacuum-plugin
Version:
Matterbridge Roborock Vacuum Plugin
51 lines • 1.5 kB
JavaScript
import { randomInt } from 'node:crypto';
import { Protocol } from './protocol.js';
export class RequestMessage {
version;
messageId;
protocol;
method;
params;
secure;
timestamp;
nonce;
dps;
body;
constructor(args) {
this.messageId = args.messageId ?? randomInt(10000, 32767);
this.protocol = args.protocol ?? Protocol.rpc_request;
this.method = args.method;
this.params = args.params;
this.secure = args.secure ?? false;
this.nonce = args.nonce ?? randomInt(10000, 32767);
this.timestamp = args.timestamp ?? Math.floor(Date.now() / 1000);
this.version = args.version;
this.dps = args.dps;
this.body = args.body;
}
isForProtocol(protocol) {
return this.protocol === protocol;
}
toMqttRequest() {
return this;
}
toLocalRequest(protocolVersion = undefined) {
if (this.protocol == Protocol.rpc_request) {
return new RequestMessage({
messageId: this.messageId,
protocol: Protocol.general_request,
version: protocolVersion,
method: this.method,
params: this.params,
secure: this.secure,
dps: this.dps,
nonce: this.nonce,
timestamp: this.timestamp,
});
}
else {
return this;
}
}
}
//# sourceMappingURL=requestMessage.js.map