interconnect

import { interconnect } from '@hullo/browser'

Inside main file:

const hub = new MessageChannel();
const worker: Worker = new Worker("...", { name: "other" });
worker.postMessage({
type: "interconnect",
hubIn: hub.port1,
hubOut: hub.port2
});
interconnect("main", hub.port1, hub.port2);
// and whenever you're ready
hub.port1.start();
hub.port2.start();

Inside worker file:

addEventListener("message", event => {
if ("type" in event.data && event.data.type === "interconnect") {
interconnect("other", event.data.hubIn, event.data.hubOut);
}
});