versacall-core-library-react 2.0.86-dev → 2.0.87-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.
|
@@ -39,7 +39,7 @@ let packetIdCounter = 0;
|
|
|
39
39
|
* topic string → { channelKey, channelName }
|
|
40
40
|
* Maintained across reconnects so we can resubscribe automatically.
|
|
41
41
|
*/
|
|
42
|
-
const activeSubscriptions = new Map();
|
|
42
|
+
const activeSubscriptions = new Map(); // lookupKey → {channelKey, channelName, ports: Set}
|
|
43
43
|
|
|
44
44
|
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
45
45
|
|
|
@@ -57,6 +57,18 @@ function concat(a, b) {
|
|
|
57
57
|
out.set(b, a.length);
|
|
58
58
|
return out;
|
|
59
59
|
}
|
|
60
|
+
function cleanupPortSubscriptions(port) {
|
|
61
|
+
for (const [lookupKey, sub] of activeSubscriptions) {
|
|
62
|
+
sub.ports.delete(port);
|
|
63
|
+
if (sub.ports.size === 0) {
|
|
64
|
+
activeSubscriptions.delete(lookupKey);
|
|
65
|
+
const mqttTopic = "".concat(sub.channelKey, "/").concat(sub.channelName, "/");
|
|
66
|
+
if (mqttConnected) {
|
|
67
|
+
wsSend(buildUnsubscribe(nextPacketId(), mqttTopic));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
60
72
|
|
|
61
73
|
// ─── MQTT encoding ───────────────────────────────────────────────────────────
|
|
62
74
|
|
|
@@ -368,22 +380,34 @@ function handlePortMessage(port, msg) {
|
|
|
368
380
|
{
|
|
369
381
|
const mqttTopic = "".concat(msg.channelKey, "/").concat(msg.channelName, "/");
|
|
370
382
|
const lookupKey = "".concat(msg.channelName, "/");
|
|
371
|
-
activeSubscriptions.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
|
|
383
|
+
const existing = activeSubscriptions.get(lookupKey);
|
|
384
|
+
if (existing) {
|
|
385
|
+
existing.ports.add(port);
|
|
386
|
+
} else {
|
|
387
|
+
activeSubscriptions.set(lookupKey, {
|
|
388
|
+
channelKey: msg.channelKey,
|
|
389
|
+
channelName: msg.channelName,
|
|
390
|
+
ports: new Set([port])
|
|
391
|
+
});
|
|
392
|
+
if (mqttConnected) {
|
|
393
|
+
wsSend(buildSubscribe(nextPacketId(), mqttTopic));
|
|
394
|
+
}
|
|
377
395
|
}
|
|
378
396
|
break;
|
|
379
397
|
}
|
|
380
398
|
case 'UNSUBSCRIBE':
|
|
381
399
|
{
|
|
382
400
|
const lookupKey = "".concat(msg.channelName, "/");
|
|
383
|
-
activeSubscriptions.
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
401
|
+
const existing = activeSubscriptions.get(lookupKey);
|
|
402
|
+
if (existing) {
|
|
403
|
+
existing.ports.delete(port);
|
|
404
|
+
if (existing.ports.size === 0) {
|
|
405
|
+
activeSubscriptions.delete(lookupKey);
|
|
406
|
+
const mqttTopic = "".concat(msg.channelKey, "/").concat(msg.channelName, "/");
|
|
407
|
+
if (mqttConnected) {
|
|
408
|
+
wsSend(buildUnsubscribe(nextPacketId(), mqttTopic));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
387
411
|
}
|
|
388
412
|
break;
|
|
389
413
|
}
|
|
@@ -402,9 +426,9 @@ self.onconnect = event => {
|
|
|
402
426
|
const port = event.ports[0];
|
|
403
427
|
ports.add(port);
|
|
404
428
|
port.onmessage = ev => handlePortMessage(port, ev.data);
|
|
405
|
-
port.onmessageerror = () =>
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
429
|
+
port.onmessageerror = () => {
|
|
430
|
+
ports.delete(port);
|
|
431
|
+
cleanupPortSubscriptions(port);
|
|
432
|
+
};
|
|
409
433
|
port.start();
|
|
410
434
|
};
|
package/package.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"versacall": {
|
|
3
3
|
"title": "Versacall Core Library React",
|
|
4
4
|
"applicationType": "react-library",
|
|
5
|
-
"build":
|
|
5
|
+
"build": 87
|
|
6
6
|
},
|
|
7
7
|
"name": "versacall-core-library-react",
|
|
8
|
-
"version": "2.0.
|
|
8
|
+
"version": "2.0.87-dev",
|
|
9
9
|
"description": "Versacall Core Library",
|
|
10
10
|
"main": "dist/index.js",
|
|
11
11
|
"module": "dist/index.js",
|