You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
924 B
35 lines
924 B
/**
|
|
* @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
|
|
|