@resolveio/server-lib 22.0.3 → 22.0.5
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.
|
@@ -959,7 +959,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
959
959
|
// Subscribe to publication
|
|
960
960
|
SubscriptionManager.prototype.subscribe = function (messageRoute, messageDate, ws, messageId, publication, subscriptionData) {
|
|
961
961
|
return __awaiter(this, void 0, void 0, function () {
|
|
962
|
-
var pub, valObj, valKeys, rootKeys, i, staleRouteMessage, urlData, urlModule_1, urlNext, otherRouteSubs, normalizedSubscriptionData, subscriptionKey_1, sub;
|
|
962
|
+
var pub, valObj, valKeys, rootKeys, i, staleRouteMessage, urlData, urlModule_1, urlNext, otherRouteSubs, normalizedSubscriptionData, subscriptionKey_1, sub, isAiPublication, wsId_1, wsUserId, existingIndex, existingClient, i;
|
|
963
963
|
var _this = this;
|
|
964
964
|
var _a;
|
|
965
965
|
return __generator(this, function (_b) {
|
|
@@ -1052,9 +1052,34 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1052
1052
|
normalizedSubscriptionData = Array.isArray(subscriptionData) ? subscriptionData : [];
|
|
1053
1053
|
subscriptionKey_1 = JSON.stringify(normalizedSubscriptionData);
|
|
1054
1054
|
sub = this._subscriptions.find(function (a) { return a.publication === publication && a.subscriptionKey === subscriptionKey_1; });
|
|
1055
|
+
isAiPublication = this.isAiPublication(publication);
|
|
1056
|
+
wsId_1 = ws ? ws['id_socket'] : null;
|
|
1057
|
+
wsUserId = ws ? ws['id_user'] : null;
|
|
1055
1058
|
// If sub found (another user watching same data), add client to same sub
|
|
1056
1059
|
if (sub) {
|
|
1057
|
-
if (
|
|
1060
|
+
if (isAiPublication && wsId_1) {
|
|
1061
|
+
existingIndex = sub.clients.findIndex(function (a) { return a.id_socket === wsId_1; });
|
|
1062
|
+
if (existingIndex >= 0) {
|
|
1063
|
+
existingClient = sub.clients[existingIndex];
|
|
1064
|
+
for (i = sub.clients.length - 1; i >= 0; i--) {
|
|
1065
|
+
if (i !== existingIndex && sub.clients[i].id_socket === wsId_1) {
|
|
1066
|
+
sub.clients.splice(i, 1);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
existingClient.id_user = wsUserId;
|
|
1070
|
+
existingClient.messageId = messageId;
|
|
1071
|
+
existingClient.messageRoute = messageRoute;
|
|
1072
|
+
}
|
|
1073
|
+
else {
|
|
1074
|
+
sub.clients.push({
|
|
1075
|
+
id_user: wsUserId,
|
|
1076
|
+
messageId: messageId,
|
|
1077
|
+
id_socket: wsId_1,
|
|
1078
|
+
messageRoute: messageRoute
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
else if (!sub.clients.some(function (a) { return a.id_socket === ws['id_socket'] && a.messageId === messageId; })) {
|
|
1058
1083
|
sub.clients.push({
|
|
1059
1084
|
id_user: ws['id_user'],
|
|
1060
1085
|
messageId: messageId,
|
|
@@ -1150,8 +1175,12 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1150
1175
|
var subscriptionKey_2 = JSON.stringify(normalizedSubscriptionData);
|
|
1151
1176
|
var sub = this._subscriptions.find(function (a) { return a.publication === publication && a.subscriptionKey === subscriptionKey_2; });
|
|
1152
1177
|
if (sub) {
|
|
1178
|
+
var isAiPublication = this.isAiPublication(publication);
|
|
1153
1179
|
for (var i = sub.clients.length - 1; i >= 0; i--) {
|
|
1154
|
-
if (
|
|
1180
|
+
if (isAiPublication && sub.clients[i].id_socket === ws['id_socket']) {
|
|
1181
|
+
sub.clients.splice(i, 1);
|
|
1182
|
+
}
|
|
1183
|
+
else if (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {
|
|
1155
1184
|
sub.clients.splice(i, 1);
|
|
1156
1185
|
}
|
|
1157
1186
|
}
|
|
@@ -2458,12 +2487,23 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2458
2487
|
// Fetch pub once, send to all clients linked to this pub
|
|
2459
2488
|
SubscriptionManager.prototype.sendDataToAll = function (sub, collection, type) {
|
|
2460
2489
|
return __awaiter(this, void 0, void 0, function () {
|
|
2461
|
-
var activeClients, _a, _b, client, ws, subIndex, monitor, res, dependencySnapshot, execution, packedRes, passThrough, payloadBytes, shouldCache,
|
|
2490
|
+
var isAiPublication, seenSockets_1, activeClients, _a, _b, client, ws, subIndex, monitor, res, dependencySnapshot, execution, packedRes, passThrough, payloadBytes, shouldCache, cachedBuffer, isSame, sendStartMs, sentClients, activeClients_1, activeClients_1_1, entry, client, ws, serverRes, sendStartMs, sentClients, activeClients_2, activeClients_2_1, entry, client, ws, serverRes, nodeCacheSize, deleteCount, subArr, zz, err_2, _c, normalizedError, correlationId, _d, _e, client, ws, serverRes, errorPayload;
|
|
2462
2491
|
var e_6, _f, e_7, _g, e_8, _h, e_9, _j;
|
|
2463
2492
|
var _k, _l;
|
|
2464
2493
|
return __generator(this, function (_m) {
|
|
2465
2494
|
switch (_m.label) {
|
|
2466
2495
|
case 0:
|
|
2496
|
+
isAiPublication = this.isAiPublication(sub.publication);
|
|
2497
|
+
if (isAiPublication && sub.clients.length > 1) {
|
|
2498
|
+
seenSockets_1 = new Set();
|
|
2499
|
+
sub.clients = sub.clients.filter(function (client) {
|
|
2500
|
+
if (seenSockets_1.has(client.id_socket)) {
|
|
2501
|
+
return false;
|
|
2502
|
+
}
|
|
2503
|
+
seenSockets_1.add(client.id_socket);
|
|
2504
|
+
return true;
|
|
2505
|
+
});
|
|
2506
|
+
}
|
|
2467
2507
|
activeClients = [];
|
|
2468
2508
|
if (sub.clients.length) {
|
|
2469
2509
|
try {
|
|
@@ -2516,7 +2556,6 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
2516
2556
|
passThrough = !!execution.workerUsed;
|
|
2517
2557
|
payloadBytes = packedRes ? packedRes.byteLength : null;
|
|
2518
2558
|
shouldCache = this.shouldCachePayload(sub, packedRes);
|
|
2519
|
-
isAiPublication = this.isAiPublication(sub.publication);
|
|
2520
2559
|
if (sub.cacheId) {
|
|
2521
2560
|
cachedBuffer = this.getCacheBuffer(this._nodeCache.get(sub.cacheId));
|
|
2522
2561
|
isSame = this.buffersEqual(cachedBuffer, packedRes);
|