48 lines
2.2 KiB
JavaScript
48 lines
2.2 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { createRequire } from "node:module";
|
|
import { parentPort, workerData } from "node:worker_threads";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
const facade = await import(workerData.facadePath);
|
|
const envelope = await import(workerData.envelopePath);
|
|
globalThis.__dirname = `${workerData.buildDirectory}${path.sep}`;
|
|
globalThis.require = createRequire(import.meta.url);
|
|
const loader = await import(pathToFileURL(path.join(workerData.buildDirectory, "FreeCADWebRobotRuntimeProbe.js")));
|
|
const kernel = await loader.default({
|
|
wasmBinary: fs.readFileSync(path.join(workerData.buildDirectory, "FreeCADWebRobotRuntimeProbe.wasm")),
|
|
print: () => {},
|
|
printErr: () => {},
|
|
});
|
|
let queue = new envelope.FacadeSerialQueue();
|
|
const records = [
|
|
{ apiId: "py:Robot:class:Robot6Axis", name: "Robot6Axis", family: "generic-object" },
|
|
{ apiId: "py:Robot:class:RobotWorkbench", name: "RobotWorkbench", family: "generic-object" },
|
|
{ apiId: "py:Robot:class:Trajectory", name: "Trajectory", family: "generic-object" },
|
|
{ apiId: "py:Robot:class:Waypoint", name: "Waypoint", family: "geometry-value" },
|
|
{ apiId: "py:Robot:method:RobotObject.getRobot", name: "RobotObject.getRobot", family: "generic-object" },
|
|
];
|
|
|
|
parentPort.postMessage({ kind: "ready", action: facade.ROBOT_PYTHON_FAMILY_COMMAND });
|
|
parentPort.on("message", async (message) => {
|
|
if (message.kind === "reset") {
|
|
queue = new envelope.FacadeSerialQueue();
|
|
parentPort.postMessage({ kind: "reset", requestId: message.requestId });
|
|
return;
|
|
}
|
|
if (envelope.isFacadeCancel(message)) {
|
|
if (!queue.cancel(message)) parentPort.postMessage(envelope.createFailure(message.requestId, "cancel_rejected", "request is not active"));
|
|
return;
|
|
}
|
|
if (!facade.isRobotPythonFamilyRequest(message)) {
|
|
parentPort.postMessage(envelope.createFailure("invalid", "invalid_request", "Robot Python family envelope is invalid"));
|
|
return;
|
|
}
|
|
const source = message.requestId === "robot-family-cancel-1"
|
|
? new Promise((resolve) => setTimeout(() => resolve(kernel), 25))
|
|
: kernel;
|
|
parentPort.postMessage(await facade.dispatchRobotPythonFamily(queue, message, source));
|
|
});
|
|
|
|
export { records };
|