@remix_labs/hub-client 2.12816.0 → 2.12820.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 +17 -0
  2. package/package.json +1 -1
package/common.js CHANGED
@@ -309,6 +309,14 @@ class Channel {
309
309
  })
310
310
  }
311
311
 
312
+ // Releases the channel: asks the hub to drop this channel's subscriptions and its end of
313
+ // the MessagePort, then closes ours. The channel must not be used afterwards.
314
+ close() {
315
+ try { this.port.postMessage({ _rmx_type: "msg_hub_closeChannel" }); } catch (_) {}
316
+ try { this.port.onmessage = null; this.port.close(); } catch (_) {}
317
+ this.expect.clear();
318
+ }
319
+
312
320
  publish(topic, msg, retained) {
313
321
  return new Promise((resolve, reject) => {
314
322
  let reqId = this.reqId + 1;
@@ -538,6 +546,8 @@ class Worker {
538
546
  if (resp.data.error == null) {
539
547
  let port = resp.ports !== undefined ? resp.ports[0] : resp.data.port;
540
548
  let hubch = new Channel(port);
549
+ // the hub worker wraps its replies as {data: msg}
550
+ hubch.chanId = (resp.data.data !== undefined ? resp.data.data : resp.data).chanId;
541
551
  resolve(hubch);
542
552
  } else
543
553
  reject(resp.data)
@@ -548,6 +558,13 @@ class Worker {
548
558
  })
549
559
  }
550
560
 
561
+ // Closes the hub's end of a channel whose own end lives elsewhere (e.g. was transferred to a
562
+ // worker that has since been terminated). No reply.
563
+ closeChannelById(chanId) {
564
+ if (chanId === undefined) return;
565
+ try { this.worker.postMessage({ "_rmx_type": "msg_hub_closeChannelId", chanId: chanId }); } catch (_) {}
566
+ }
567
+
551
568
  newJSONMessage(rmxType, sender, payload) {
552
569
  return new JSONMessage(rmxType, sender, payload);
553
570
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix_labs/hub-client",
3
- "version": "2.12816.0",
3
+ "version": "2.12820.0-dev",
4
4
  "description": "talk to the Hub web worker",
5
5
  "main": "node.js",
6
6
  "browser": "index.js",