@foxglove/ros1
Version:
Standalone TypeScript implementation of the ROS 1 (Robot Operating System) protocol with a pluggable transport layer
47 lines • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RosXmlRpcClient = void 0;
const xmlrpc_1 = require("@foxglove/xmlrpc");
class RosXmlRpcClient {
constructor(url) {
this._methodCall = async (methodName, args) => {
const res = await this._client.methodCall(methodName, args);
if (!Array.isArray(res) || res.length !== 3) {
throw new Error(`Malformed XML-RPC response`);
}
const [code, msg] = res;
if (typeof code !== "number" || typeof msg !== "string") {
// workaround for https://github.com/typescript-eslint/typescript-eslint/issues/10632
throw new Error(`Invalid code/msg, code="${code}", msg="${msg}"`);
}
return res;
};
this._multiMethodCall = async (requests) => {
const res = await this._client.multiMethodCall(requests);
const output = [];
for (const entry of res) {
if (entry instanceof xmlrpc_1.XmlRpcFault) {
output.push(entry);
}
else if (!Array.isArray(entry) || entry.length !== 3) {
throw new Error(`Malformed XML-RPC multicall response`);
}
else {
const [code, msg] = entry;
if (typeof code !== "number" || typeof msg !== "string") {
// workaround for https://github.com/typescript-eslint/typescript-eslint/issues/10632
throw new Error(`Invalid code/msg, code="${code}", msg="${msg}"`);
}
output.push(entry);
}
}
return output;
};
this._client = new xmlrpc_1.XmlRpcClient(url, { encoding: "utf-8" });
}
url() {
return this._client.url;
}
}
exports.RosXmlRpcClient = RosXmlRpcClient;
//# sourceMappingURL=RosXmlRpcClient.js.map