Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to node style listener to avoid using undici's (node dep) MessageEvent class #704

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ const Flatted = require('flatted'),
__uvm_emit = function (postMessage, args) {
postMessage({__id_uvm: "${id}", __emit_uvm: args});
}.bind(null, __self.postMessage.bind(__self));
__uvm_addEventListener = __self.addEventListener.bind(__self);
__uvm_on = __self.on.bind(__self);
${bridgeClientCode()}
(function (emit, id) {
__uvm_addEventListener("message", function (e) {
const { __emit_uvm, __id_uvm } = e?.data || e || {};
__uvm_on("message", function (e) {
const { __emit_uvm, __id_uvm } = e || {};
if (typeof __emit_uvm === 'string' && __id_uvm === id) {
emit(__emit_uvm);
}
});
}(__uvm_dispatch, "${id}"));
__uvm_dispatch = null; delete __uvm_dispatch;
__uvm_addEventListener = null; delete __uvm_addEventListener;
__uvm_on = null; delete __uvm_on;
(function (self, bridge, setTimeout) {
${Worker.__exceptionHandler}
Expand Down
9 changes: 8 additions & 1 deletion lib/worker.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ class WebWorker {
callback && callback();
}

static __self = 'self';
static __self = `(function () {
self.on = function (name, listener) {
return self.addEventListener(name, function (e) {
listener(e.data);
});
};
return self;
}())`;

static __exceptionHandler = `
((close) => {
Expand Down
Loading