securityos/node_modules/comlink/dist/esm/node-adapter.mjs

36 lines
924 B
JavaScript
Raw Normal View History

2024-09-06 15:32:35 +00:00
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
function nodeEndpoint(nep) {
const listeners = new WeakMap();
return {
postMessage: nep.postMessage.bind(nep),
addEventListener: (_, eh) => {
const l = (data) => {
if ("handleEvent" in eh) {
eh.handleEvent({ data });
}
else {
eh({ data });
}
};
nep.on("message", l);
listeners.set(eh, l);
},
removeEventListener: (_, eh) => {
const l = listeners.get(eh);
if (!l) {
return;
}
nep.off("message", l);
listeners.delete(eh);
},
start: nep.start && nep.start.bind(nep),
};
}
export { nodeEndpoint as default };
//# sourceMappingURL=node-adapter.mjs.map