@remix_labs/hub-client 2.2061.0 → 2.2063.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/common.js +21 -14
  2. package/package.json +1 -1
package/common.js CHANGED
@@ -430,21 +430,15 @@ class Channel {
430
430
  }
431
431
  }
432
432
 
433
- // This class starts the web worker for the hub. Should only be instantiated
434
- // once.
435
- class Worker {
433
+ // This class starts the web worker for the hub. It comes in two flavors:
434
+ // - ScopedWorker: an independent instance of the worker
435
+ // - Worker: the global instance of the worker, i.e. "new Worker()" gets
436
+ // you every time the same worker
437
+ class ScopedWorker {
436
438
  constructor() {
437
- if (globalThis.RmxMessagingHub) {
438
- this.worker = globalThis.RmxMessagingHub.worker;
439
- this.expect = globalThis.RmxMessagingHub.expect;
440
- this.noreconfigure = true;
441
- return;
442
- };
443
-
444
439
  // injected by either index.js or node.js
445
440
  this.worker = globalThis.GetHubWorker();
446
441
 
447
- globalThis.RmxMessagingHub = this;
448
442
  let thisworker = this;
449
443
  this.expect = new Array(0);
450
444
  // sigh, browser/node have a different API for this
@@ -461,7 +455,6 @@ class Worker {
461
455
  }
462
456
 
463
457
  this.noreconfigure = false;
464
- terminate(() => thisworker.worker.terminate());
465
458
  }
466
459
 
467
460
  configure(config_obj) {
@@ -527,5 +520,19 @@ class Worker {
527
520
  }
528
521
  }
529
522
 
530
- export { Worker, Channel, JSONMessage, TextMessage, BinaryMessage, LocalMessage,
531
- EOF }
523
+ class Worker extends ScopedWorker {
524
+ constructor() {
525
+ if (globalThis.RmxMessagingHub) {
526
+ this.worker = globalThis.RmxMessagingHub.worker;
527
+ this.expect = globalThis.RmxMessagingHub.expect;
528
+ this.noreconfigure = true;
529
+ return;
530
+ };
531
+ super();
532
+ globalThis.RmxMessagingHub = this;
533
+ terminate(() => thisworker.worker.terminate());
534
+ }
535
+ }
536
+
537
+ export { Worker, ScopedWorker, Channel,
538
+ JSONMessage, TextMessage, BinaryMessage, LocalMessage, EOF }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix_labs/hub-client",
3
- "version": "2.2061.0",
3
+ "version": "2.2063.0-dev",
4
4
  "description": "talk to the Hub web worker",
5
5
  "main": "node.js",
6
6
  "browser": "index.js",