worker: Fix wasm path
This commit is contained in:
parent
dd2c4614ba
commit
012a05ab9d
@ -221,12 +221,24 @@ Page({
|
|||||||
useExperimentalWorker: true,
|
useExperimentalWorker: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pass the WASM file path to the worker
|
// Send WASM path via message (this is the only supported method)
|
||||||
worker.wasmFilePath = this.data.wasmFilePath;
|
if (worker && this.data.wasmFilePath) {
|
||||||
|
console.log("Sending WASM path via message:", this.data.wasmFilePath);
|
||||||
|
worker.postMessage({
|
||||||
|
type: "wasm_path",
|
||||||
|
path: this.data.wasmFilePath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
worker.onMessage((msg) => {
|
worker.onMessage((msg) => {
|
||||||
console.log('Worker message:', msg.type);
|
console.log('Worker message:', msg.type);
|
||||||
|
|
||||||
|
if (msg.type === "ready") {
|
||||||
|
console.log('Worker is ready');
|
||||||
|
// Worker is ready to process frames
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (msg.type === "result") {
|
if (msg.type === "result") {
|
||||||
// Clear processing flag when we get a result
|
// Clear processing flag when we get a result
|
||||||
this.setData({ worker_processing: false });
|
this.setData({ worker_processing: false });
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
console.log("hello from emblemscanner worker");
|
console.log("hello from emblemscanner worker");
|
||||||
|
|
||||||
// Load qrtool module first, then set WASM path
|
// Load qrtool module first - WASM path will be set via message
|
||||||
// The wasmFilePath will be passed from the main thread when the worker is created
|
|
||||||
let qrtool = require('./qrtool.wx.js');
|
let qrtool = require('./qrtool.wx.js');
|
||||||
|
let wasmPathReceived = false;
|
||||||
|
|
||||||
if (typeof worker !== "undefined" && worker.wasmFilePath) {
|
console.log("QRTool loaded, waiting for WASM path via message...");
|
||||||
qrtool['setWasmPath'](worker.wasmFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -15,9 +13,14 @@ var qrtool_ready = false;
|
|||||||
qrtool.onRuntimeInitialized = () => {
|
qrtool.onRuntimeInitialized = () => {
|
||||||
console.log("emblemscanner qrtool ready");
|
console.log("emblemscanner qrtool ready");
|
||||||
qrtool_ready = true;
|
qrtool_ready = true;
|
||||||
worker.postMessage({
|
if (wasmPathReceived) {
|
||||||
type: "ready",
|
console.log("QRTool initialized successfully with WASM path");
|
||||||
});
|
worker.postMessage({
|
||||||
|
type: "ready",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log("QRTool initialized but WASM path not received yet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var submit_message = null;
|
var submit_message = null;
|
||||||
@ -51,6 +54,42 @@ function handle_frame(data, width, height, camera_sensitivity) {
|
|||||||
|
|
||||||
worker.onMessage((msg) => {
|
worker.onMessage((msg) => {
|
||||||
console.log("emblemscanner worker got message", msg.type);
|
console.log("emblemscanner worker got message", msg.type);
|
||||||
|
|
||||||
|
// Handle WASM path message for initialization
|
||||||
|
if (msg.type === "wasm_path" && msg.path) {
|
||||||
|
console.log("Received WASM path via message:", msg.path);
|
||||||
|
if (typeof qrtool !== "undefined" && qrtool['setWasmPath']) {
|
||||||
|
qrtool['setWasmPath'](msg.path);
|
||||||
|
wasmPathReceived = true;
|
||||||
|
console.log("WASM path set via message");
|
||||||
|
|
||||||
|
// If qrtool is already ready, send ready message immediately
|
||||||
|
if (qrtool_ready) {
|
||||||
|
console.log("QRTool is already ready, sending ready message");
|
||||||
|
worker.postMessage({
|
||||||
|
type: "ready",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log("Waiting for qrtool to become ready...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return; // Don't process further until qrtool is ready
|
||||||
|
}
|
||||||
|
|
||||||
|
// If WASM path hasn't been received yet, return error
|
||||||
|
if (!wasmPathReceived) {
|
||||||
|
console.log("WASM path not received yet, cannot process messages");
|
||||||
|
worker.postMessage({
|
||||||
|
type: "result",
|
||||||
|
res: {
|
||||||
|
ok: false,
|
||||||
|
err: "wasm_path not received yet",
|
||||||
|
},
|
||||||
|
processing_time: 0,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!qrtool_ready) {
|
if (!qrtool_ready) {
|
||||||
console.log("qrtool not ready");
|
console.log("qrtool not ready");
|
||||||
worker.postMessage({
|
worker.postMessage({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user