[adapters] 修复 Worker 主动向主线程通信无效的问题

This commit is contained in:
SmallMain 2024-10-28 17:22:22 +08:00
parent bc989c3e14
commit 6114dba7aa
No known key found for this signature in database
2 changed files with 8 additions and 8 deletions

View File

@ -41,7 +41,7 @@ var handlers = {};
function callToMain(cmd, args) { function callToMain(cmd, args) {
const id = ++_cmdId; const id = ++_cmdId;
args.unshift(id, cmd); const msg = [id, cmd, args];
if (typeof args[args.length - 1] === "function") { if (typeof args[args.length - 1] === "function") {
const callback = args.pop(); const callback = args.pop();
@ -49,13 +49,13 @@ function callToMain(cmd, args) {
} }
if (CC_WORKER_DEBUG) { if (CC_WORKER_DEBUG) {
console.log("worker send call:", args); console.log("worker send call:", msg);
} }
if (CC_WORKER_SCHEDULER) { if (CC_WORKER_SCHEDULER) {
sendScheduler.send(args); sendScheduler.send(msg);
} else { } else {
worker.postMessage(args); worker.postMessage(msg);
} }
} }

View File

@ -169,7 +169,7 @@ const ipcMain = {
const desc = descs[key]; const desc = descs[key];
if (typeof desc.value === "function") { if (typeof desc.value === "function") {
const cmd = ++this._cmd; const cmd = --this._cmd;
this.handlers[cmd] = { this.handlers[cmd] = {
name, name,
key, key,
@ -178,7 +178,7 @@ const ipcMain = {
}; };
} else { } else {
// getter/setter // getter/setter
const cmd1 = ++this._cmd; const cmd1 = --this._cmd;
this.handlers[cmd1] = { this.handlers[cmd1] = {
name, name,
key: "get_" + key, key: "get_" + key,
@ -187,7 +187,7 @@ const ipcMain = {
}, },
callback: null, callback: null,
}; };
const cmd2 = ++this._cmd; const cmd2 = --this._cmd;
this.handlers[cmd2] = { this.handlers[cmd2] = {
name, name,
key: "set_" + key, key: "set_" + key,
@ -195,7 +195,7 @@ const ipcMain = {
obj[key] = args[0]; obj[key] = args[0];
} }
}; };
const cmd3 = ++this._cmd; const cmd3 = --this._cmd;
this.handlers[cmd3] = { this.handlers[cmd3] = {
name, name,
key: "write_" + key, key: "write_" + key,