@remix_labs/hub-client 1.1874.0-dev → 1.1880.0-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +25 -10
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -434,41 +434,54 @@ class Channel {
434
434
  // once.
435
435
  class Worker {
436
436
  constructor() {
437
+ console.log("building worker");
437
438
  if (globalThis.RmxMessagingHub) {
439
+ console.log("worker: global hub exists");
438
440
  this.worker = globalThis.RmxMessagingHub.worker;
439
441
  this.expect = globalThis.RmxMessagingHub.expect;
440
442
  this.noreconfigure = true;
441
443
  return;
442
444
  };
443
- let bundle;
444
445
  if (globalThis.ThisIsNode) {
445
- bundle = new URL("../../hub-worker/src/node.js", import.meta.url);
446
- } else if (globalThis.GROOVEBOX_URL_PREFIX) {
447
- // FIXME: Stopgap solution until we figure out a way to bundle groovebox correctly
448
- bundle = new URL(`${globalThis.GROOVEBOX_URL_PREFIX}/hub-worker.js`, window.location.href);
446
+ this.worker = globalThis.getHubWorker();
447
+ //this.worker = new globalThis.Worker(new URL("./hub-worker.js", import.meta.url));
448
+ console.log("made a worker for hub-worker");
449
449
  } else {
450
- bundle = new URL("/g/hub-worker.js", window.location.href);
450
+ let bundle;
451
+ if (globalThis.GROOVEBOX_URL_PREFIX) {
452
+ // FIXME: Stopgap solution until we figure out a way to bundle groovebox correctly
453
+ bundle = new URL(`${globalThis.GROOVEBOX_URL_PREFIX}/hub-worker.js`, window.location.href);
454
+ } else {
455
+ bundle = new URL("/g/hub-worker.js", window.location.href);
456
+ }
457
+ this.worker = new globalThis.Worker(bundle);
451
458
  }
452
- this.worker = new globalThis.Worker(bundle);
453
459
  globalThis.RmxMessagingHub = this;
454
460
  let thisworker = this;
455
461
  this.expect = new Array(0);
456
- this.worker.onmessage = (ev => {
462
+ // TODO: does this work on web, too?
463
+ this.worker.on("message", (ev => {
464
+ console.log("hub-client got message");
457
465
  let f = thisworker.expect.shift();
458
- f(ev)
459
- });
466
+ f(ev);
467
+ console.log("hub-client handled message");
468
+ }));
469
+
460
470
  this.noreconfigure = false;
461
471
  terminate(() => thisworker.worker.terminate());
462
472
  }
463
473
 
464
474
  configure(config_obj) {
475
+ console.log("worker.configure");
465
476
  if (this.noreconfigure) {
466
477
  console.warn("The global hub-client is already configured");
467
478
  return;
468
479
  };
469
480
  let thisworker = this;
470
481
  return new Promise((resolve, reject) => {
482
+ console.log("in promise");
471
483
  thisworker.expect.push(resp => {
484
+ console.log("in expect.push callback");
472
485
  if (resp.data.error == null)
473
486
  resolve(resp.data);
474
487
  else
@@ -482,7 +495,9 @@ class Worker {
482
495
  "token": config_obj.token,
483
496
  "standalone": config_obj.standalone === true
484
497
  };
498
+ console.log("posting msg");
485
499
  thisworker.worker.postMessage(config_msg);
500
+ console.log("posted msg");
486
501
  })
487
502
  }
488
503
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix_labs/hub-client",
3
- "version": "1.1874.0-dev",
3
+ "version": "1.1880.0-dev",
4
4
  "description": "talk to the Hub web worker",
5
5
  "main": "node.js",
6
6
  "browser": "index.js",
@@ -11,7 +11,7 @@
11
11
  "author": "Remixlabs staff",
12
12
  "license": "ISC",
13
13
  "dependencies": {
14
- "@remix_labs/web-worker-onlymain": "1.1874.0-dev"
14
+ "@remix_labs/web-worker-onlymain": "1.1880.0-dev"
15
15
  },
16
16
  "repository": "https://github.com/remixlabs/groovebox.git"
17
17
  }