demos/epcp/browser-webworkers-demo/src/index.js
/**
 * Create and initialize the browser-demo web worker in a DOM Worker.
 * Send the worker some configuration from this url's query params.
 */
Create and initialize the browser-demo web worker in a DOM Worker.
Send the worker some configuration from this url's query params.
Create and initialize the browser - demo web worker in a DOM Worker . Send the worker some configuration from this url ' s query params .
function bootWebWorker({ Worker }) {
  const webWorker = Object.assign(
    new Worker("pubcontrol-browser-demo.webworker.js"),
    {
      onmessage: event => {
        console.debug("Message received from worker", event.data.type, event);
      }
    }
  );
  webWorker.postMessage({
    type: "Hello",
    from: "browser",
    content: "Hello worker. I booted you out here in pubcontrol-browser-demo."
  });
  const url = new URL(global.location.href);
  const epcp = {
    uri: url.searchParams.get("epcp.uri"),
    defaultChannel: url.searchParams.get("epcp.defaultChannel")
  };
  const iss = url.searchParams.get("epcp.iss");
  if (iss != null) {
    epcp.iss = iss;
  }
  const key = url.searchParams.get("epcp.key");
  if (key != null) {
    epcp.key = key;
  }
  if (![epcp.uri, epcp.defaultChannel].every(Boolean)) {
    console.warn(
      "Missing one of ?epcp.uri or ?epcp.defaultChannel query params."
    );
  }
  webWorker.postMessage({
    type: "EPCPConfiguration",
    ...epcp
  });
}
function bootWebWorker ( { Worker } ) { const webWorker = Object . assign ( new Worker ( "pubcontrol-browser-demo.webworker.js" ) , { onmessage : event => { console . debug ( "Message received from worker" , event . data . type , event ) ; } } ) ; webWorker . postMessage ( { type : "Hello" , from : "browser" , content : "Hello worker. I booted you out here in pubcontrol-browser-demo." } ) ; const url = new URL ( global . location . href ) ; const epcp = { uri : url . searchParams . get ( "epcp.uri" ) , defaultChannel : url . searchParams . get ( "epcp.defaultChannel" ) } ; const iss = url . searchParams . get ( "epcp.iss" ) ; if ( iss != null ) { epcp . iss = iss ; } const key = url . searchParams . get ( "epcp.key" ) ; if ( key != null ) { epcp . key = key ; } if ( ! [ epcp . uri , epcp . defaultChannel ] . every ( Boolean ) ) { console . warn ( "Missing one of ?epcp.uri or ?epcp.defaultChannel query params." ) ; } webWorker . postMessage ( { type : "EPCPConfiguration" , ... epcp } ) ; }
Create and initialize the browser-demo web worker in a DOM Worker.
Create and initialize the browser - demo web worker in a DOM Worker .