node-opcua-server 2.167.0 → 2.168.0
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.
- package/dist/addressSpace_accessor.d.ts +6 -6
- package/dist/addressSpace_accessor.js +2 -2
- package/dist/addressSpace_accessor.js.map +1 -1
- package/dist/base_server.d.ts +14 -3
- package/dist/base_server.js +63 -41
- package/dist/base_server.js.map +1 -1
- package/dist/extract_password_from_blob.js +1 -3
- package/dist/extract_password_from_blob.js.map +1 -1
- package/dist/factory.d.ts +2 -3
- package/dist/factory.js.map +1 -1
- package/dist/filter/check_where_clause_on_address_space.d.ts +2 -2
- package/dist/filter/check_where_clause_on_address_space.js +1 -2
- package/dist/filter/check_where_clause_on_address_space.js.map +1 -1
- package/dist/filter/extract_event_fields.d.ts +3 -3
- package/dist/filter/extract_event_fields.js +1 -2
- package/dist/filter/extract_event_fields.js.map +1 -1
- package/dist/helper.d.ts +3 -3
- package/dist/helper.js +4 -8
- package/dist/helper.js.map +1 -1
- package/dist/i_address_space_accessor.d.ts +4 -4
- package/dist/i_channel_data.d.ts +1 -1
- package/dist/i_register_server_manager.d.ts +1 -1
- package/dist/i_server_side_publish_engine.d.ts +8 -6
- package/dist/i_server_side_publish_engine.js +7 -2
- package/dist/i_server_side_publish_engine.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/invalidate_server_certificate_cache.d.ts +16 -0
- package/dist/invalidate_server_certificate_cache.js +28 -0
- package/dist/invalidate_server_certificate_cache.js.map +1 -0
- package/dist/monitored_item.d.ts +10 -11
- package/dist/monitored_item.js +38 -39
- package/dist/monitored_item.js.map +1 -1
- package/dist/node_sampler.d.ts +1 -1
- package/dist/node_sampler.js +2 -4
- package/dist/node_sampler.js.map +1 -1
- package/dist/opcua_server.d.ts +57 -62
- package/dist/opcua_server.js +7 -7
- package/dist/opcua_server.js.map +1 -1
- package/dist/register_server_manager_hidden.d.ts +1 -1
- package/dist/register_server_manager_hidden.js +2 -4
- package/dist/register_server_manager_hidden.js.map +1 -1
- package/dist/register_server_manager_mdns_only.d.ts +1 -1
- package/dist/register_server_manager_mdns_only.js.map +1 -1
- package/dist/sampling_func.d.ts +2 -2
- package/dist/server_capabilities.d.ts +3 -3
- package/dist/server_capabilities.js.map +1 -1
- package/dist/server_end_point.d.ts +45 -2
- package/dist/server_end_point.js +130 -32
- package/dist/server_end_point.js.map +1 -1
- package/dist/server_engine.js +29 -25
- package/dist/server_engine.js.map +1 -1
- package/dist/server_publish_engine.d.ts +5 -5
- package/dist/server_publish_engine.js +29 -23
- package/dist/server_publish_engine.js.map +1 -1
- package/dist/server_publish_engine_for_orphan_subscriptions.d.ts +2 -2
- package/dist/server_publish_engine_for_orphan_subscriptions.js.map +1 -1
- package/dist/server_session.d.ts +9 -10
- package/dist/server_session.js +11 -12
- package/dist/server_session.js.map +1 -1
- package/dist/server_subscription.d.ts +13 -13
- package/dist/server_subscription.js +100 -79
- package/dist/server_subscription.js.map +1 -1
- package/dist/sessions_compatible_for_transfer.d.ts +1 -1
- package/dist/sessions_compatible_for_transfer.js +1 -1
- package/dist/sessions_compatible_for_transfer.js.map +1 -1
- package/dist/user_manager.d.ts +4 -4
- package/dist/user_manager.js +1 -1
- package/dist/user_manager.js.map +1 -1
- package/dist/user_manager_ua.d.ts +2 -2
- package/dist/user_manager_ua.js +2 -2
- package/dist/user_manager_ua.js.map +1 -1
- package/dist/validate_filter.d.ts +7 -4
- package/dist/validate_filter.js +5 -6
- package/dist/validate_filter.js.map +1 -1
- package/package.json +46 -46
- package/source/addressSpace_accessor.ts +24 -24
- package/source/base_server.ts +73 -59
- package/source/extract_password_from_blob.ts +3 -11
- package/source/factory.ts +2 -4
- package/source/filter/check_where_clause_on_address_space.ts +4 -7
- package/source/filter/extract_event_fields.ts +4 -5
- package/source/helper.ts +9 -13
- package/source/i_address_space_accessor.ts +13 -4
- package/source/i_channel_data.ts +1 -1
- package/source/i_register_server_manager.ts +2 -4
- package/source/i_server_side_publish_engine.ts +16 -9
- package/source/index.ts +10 -9
- package/source/invalidate_server_certificate_cache.ts +26 -0
- package/source/monitored_item.ts +44 -42
- package/source/node_sampler.ts +9 -11
- package/source/opcua_server.ts +68 -88
- package/source/register_server_manager_hidden.ts +3 -5
- package/source/register_server_manager_mdns_only.ts +1 -3
- package/source/sampling_func.ts +2 -2
- package/source/server_capabilities.ts +9 -6
- package/source/server_end_point.ts +142 -42
- package/source/server_engine.ts +22 -22
- package/source/server_publish_engine.ts +35 -30
- package/source/server_publish_engine_for_orphan_subscriptions.ts +3 -3
- package/source/server_session.ts +36 -33
- package/source/server_subscription.ts +182 -184
- package/source/sessions_compatible_for_transfer.ts +9 -9
- package/source/user_manager.ts +7 -7
- package/source/user_manager_ua.ts +3 -5
- package/source/validate_filter.ts +9 -11
|
@@ -8,7 +8,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.Subscription = exports.SubscriptionState = void 0;
|
|
11
|
-
const
|
|
11
|
+
const node_events_1 = require("node:events");
|
|
12
12
|
const chalk_1 = __importDefault(require("chalk"));
|
|
13
13
|
const node_opcua_address_space_1 = require("node-opcua-address-space");
|
|
14
14
|
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
@@ -20,13 +20,12 @@ const node_opcua_object_registry_1 = require("node-opcua-object-registry");
|
|
|
20
20
|
const node_opcua_secure_channel_1 = require("node-opcua-secure-channel");
|
|
21
21
|
const node_opcua_service_filter_1 = require("node-opcua-service-filter");
|
|
22
22
|
const node_opcua_service_subscription_1 = require("node-opcua-service-subscription");
|
|
23
|
-
const node_opcua_service_subscription_2 = require("node-opcua-service-subscription");
|
|
24
23
|
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
25
24
|
const node_opcua_types_1 = require("node-opcua-types");
|
|
26
|
-
const
|
|
25
|
+
const i_server_side_publish_engine_1 = require("./i_server_side_publish_engine");
|
|
27
26
|
const monitored_item_1 = require("./monitored_item");
|
|
27
|
+
const queue_1 = require("./queue");
|
|
28
28
|
const validate_filter_1 = require("./validate_filter");
|
|
29
|
-
const i_server_side_publish_engine_1 = require("./i_server_side_publish_engine");
|
|
30
29
|
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
31
30
|
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
32
31
|
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
@@ -95,10 +94,10 @@ function _adjust_maxNotificationsPerPublish(maxNotificationsPerPublish) {
|
|
|
95
94
|
return maxNotificationsPerPublish;
|
|
96
95
|
}
|
|
97
96
|
function w(s, length) {
|
|
98
|
-
return
|
|
97
|
+
return `000${s}`.padStart(length);
|
|
99
98
|
}
|
|
100
99
|
function t(d) {
|
|
101
|
-
return w(d.getHours(), 2)
|
|
100
|
+
return `${w(d.getHours(), 2)}:${w(d.getMinutes(), 2)}:${w(d.getSeconds(), 2)}:${w(d.getMilliseconds(), 3)}`;
|
|
102
101
|
}
|
|
103
102
|
function _getSequenceNumbers(arr) {
|
|
104
103
|
return arr.map((notificationMessage) => notificationMessage.sequenceNumber);
|
|
@@ -116,12 +115,12 @@ function analyzeEventFilterResult(node, eventFilter) {
|
|
|
116
115
|
whereClauseResult
|
|
117
116
|
});
|
|
118
117
|
}
|
|
119
|
-
function analyzeDataChangeFilterResult(
|
|
120
|
-
(0, node_opcua_assert_1.assert)(dataChangeFilter instanceof
|
|
118
|
+
function analyzeDataChangeFilterResult(_node, dataChangeFilter) {
|
|
119
|
+
(0, node_opcua_assert_1.assert)(dataChangeFilter instanceof node_opcua_service_subscription_1.DataChangeFilter);
|
|
121
120
|
// the opcua specification doesn't provide dataChangeFilterResult
|
|
122
121
|
return null;
|
|
123
122
|
}
|
|
124
|
-
function analyzeAggregateFilterResult(
|
|
123
|
+
function analyzeAggregateFilterResult(_node, aggregateFilter) {
|
|
125
124
|
(0, node_opcua_assert_1.assert)(aggregateFilter instanceof node_opcua_service_subscription_1.AggregateFilter);
|
|
126
125
|
return new node_opcua_types_1.AggregateFilterResult({});
|
|
127
126
|
}
|
|
@@ -132,7 +131,7 @@ function _process_filter(node, filter) {
|
|
|
132
131
|
if (filter instanceof node_opcua_service_filter_1.EventFilter) {
|
|
133
132
|
return analyzeEventFilterResult(node, filter);
|
|
134
133
|
}
|
|
135
|
-
else if (filter instanceof
|
|
134
|
+
else if (filter instanceof node_opcua_service_subscription_1.DataChangeFilter) {
|
|
136
135
|
return analyzeDataChangeFilterResult(node, filter);
|
|
137
136
|
}
|
|
138
137
|
else if (filter instanceof node_opcua_service_subscription_1.AggregateFilter) {
|
|
@@ -147,67 +146,70 @@ function _process_filter(node, filter) {
|
|
|
147
146
|
function createSubscriptionDiagnostics(subscription) {
|
|
148
147
|
(0, node_opcua_assert_1.assert)(subscription instanceof Subscription);
|
|
149
148
|
const subscriptionDiagnostics = new node_opcua_common_1.SubscriptionDiagnosticsDataType({});
|
|
150
|
-
const
|
|
151
|
-
|
|
149
|
+
const sd = subscriptionDiagnostics;
|
|
150
|
+
sd.$subscription = subscription;
|
|
151
|
+
const defineGetter = (name, getter) => {
|
|
152
|
+
Object.defineProperty(sd, name, { get: getter, configurable: true });
|
|
153
|
+
};
|
|
152
154
|
// "sessionId"
|
|
153
|
-
|
|
155
|
+
defineGetter("sessionId", function () {
|
|
154
156
|
if (!this.$subscription) {
|
|
155
157
|
return node_opcua_nodeid_1.NodeId.nullNodeId;
|
|
156
158
|
}
|
|
157
159
|
return this.$subscription.getSessionId();
|
|
158
160
|
});
|
|
159
|
-
|
|
161
|
+
defineGetter("subscriptionId", function () {
|
|
160
162
|
if (!this.$subscription) {
|
|
161
163
|
return 0;
|
|
162
164
|
}
|
|
163
165
|
return this.$subscription.id;
|
|
164
166
|
});
|
|
165
|
-
|
|
167
|
+
defineGetter("priority", function () {
|
|
166
168
|
if (!this.$subscription) {
|
|
167
169
|
return 0;
|
|
168
170
|
}
|
|
169
171
|
return this.$subscription.priority;
|
|
170
172
|
});
|
|
171
|
-
|
|
173
|
+
defineGetter("publishingInterval", function () {
|
|
172
174
|
if (!this.$subscription) {
|
|
173
175
|
return 0;
|
|
174
176
|
}
|
|
175
177
|
return this.$subscription.publishingInterval;
|
|
176
178
|
});
|
|
177
|
-
|
|
179
|
+
defineGetter("maxLifetimeCount", function () {
|
|
178
180
|
return this.$subscription.lifeTimeCount;
|
|
179
181
|
});
|
|
180
|
-
|
|
182
|
+
defineGetter("maxKeepAliveCount", function () {
|
|
181
183
|
if (!this.$subscription) {
|
|
182
184
|
return 0;
|
|
183
185
|
}
|
|
184
186
|
return this.$subscription.maxKeepAliveCount;
|
|
185
187
|
});
|
|
186
|
-
|
|
188
|
+
defineGetter("maxNotificationsPerPublish", function () {
|
|
187
189
|
if (!this.$subscription) {
|
|
188
190
|
return 0;
|
|
189
191
|
}
|
|
190
192
|
return this.$subscription.maxNotificationsPerPublish;
|
|
191
193
|
});
|
|
192
|
-
|
|
194
|
+
defineGetter("publishingEnabled", function () {
|
|
193
195
|
if (!this.$subscription) {
|
|
194
196
|
return false;
|
|
195
197
|
}
|
|
196
198
|
return this.$subscription.publishingEnabled;
|
|
197
199
|
});
|
|
198
|
-
|
|
200
|
+
defineGetter("monitoredItemCount", function () {
|
|
199
201
|
if (!this.$subscription) {
|
|
200
202
|
return 0;
|
|
201
203
|
}
|
|
202
204
|
return this.$subscription.monitoredItemCount;
|
|
203
205
|
});
|
|
204
|
-
|
|
206
|
+
defineGetter("nextSequenceNumber", function () {
|
|
205
207
|
if (!this.$subscription) {
|
|
206
208
|
return 0;
|
|
207
209
|
}
|
|
208
210
|
return this.$subscription.futureSequenceNumber;
|
|
209
211
|
});
|
|
210
|
-
|
|
212
|
+
defineGetter("disabledMonitoredItemCount", function () {
|
|
211
213
|
if (!this.$subscription) {
|
|
212
214
|
return 0;
|
|
213
215
|
}
|
|
@@ -237,13 +239,13 @@ function createSubscriptionDiagnostics(subscription) {
|
|
|
237
239
|
"monitoringQueueOverflowCount",
|
|
238
240
|
"eventQueueOverflowCount"
|
|
239
241
|
*/
|
|
240
|
-
|
|
242
|
+
defineGetter("currentKeepAliveCount", function () {
|
|
241
243
|
if (!this.$subscription) {
|
|
242
244
|
return 0;
|
|
243
245
|
}
|
|
244
246
|
return this.$subscription.currentKeepAliveCount;
|
|
245
247
|
});
|
|
246
|
-
|
|
248
|
+
defineGetter("currentLifetimeCount", function () {
|
|
247
249
|
if (!this.$subscription) {
|
|
248
250
|
return 0;
|
|
249
251
|
}
|
|
@@ -286,7 +288,7 @@ const INVALID_ID = -1;
|
|
|
286
288
|
/**
|
|
287
289
|
* The Subscription class used in the OPCUA server side.
|
|
288
290
|
*/
|
|
289
|
-
class Subscription extends
|
|
291
|
+
class Subscription extends node_events_1.EventEmitter {
|
|
290
292
|
static minimumPublishingInterval = 50; // fastest possible
|
|
291
293
|
static defaultPublishingInterval = 1000; // one second
|
|
292
294
|
static maximumPublishingInterval = 1000 * 60; // one minute
|
|
@@ -427,13 +429,13 @@ class Subscription extends events_1.EventEmitter {
|
|
|
427
429
|
}
|
|
428
430
|
toString() {
|
|
429
431
|
let str = "Subscription:\n";
|
|
430
|
-
str +=
|
|
431
|
-
str +=
|
|
432
|
-
str +=
|
|
433
|
-
str +=
|
|
434
|
-
str +=
|
|
435
|
-
str +=
|
|
436
|
-
str +=
|
|
432
|
+
str += ` subscriptionId ${this.id}\n`;
|
|
433
|
+
str += ` sessionId ${this.getSessionId()?.toString()}\n`;
|
|
434
|
+
str += ` publishingEnabled ${this.publishingEnabled}\n`;
|
|
435
|
+
str += ` maxKeepAliveCount ${this.maxKeepAliveCount}\n`;
|
|
436
|
+
str += ` publishingInterval ${this.publishingInterval}\n`;
|
|
437
|
+
str += ` lifeTimeCount ${this.lifeTimeCount}\n`;
|
|
438
|
+
str += ` maxKeepAliveCount ${this.maxKeepAliveCount}\n`;
|
|
437
439
|
return str;
|
|
438
440
|
}
|
|
439
441
|
/**
|
|
@@ -525,7 +527,6 @@ class Subscription extends events_1.EventEmitter {
|
|
|
525
527
|
*
|
|
526
528
|
*/
|
|
527
529
|
terminate() {
|
|
528
|
-
(0, node_opcua_assert_1.assert)(arguments.length === 0);
|
|
529
530
|
debugLog("Subscription#terminate status", SubscriptionState[this.state]);
|
|
530
531
|
if (this.state === SubscriptionState.CLOSED) {
|
|
531
532
|
// todo verify if asserting is required here
|
|
@@ -541,7 +542,7 @@ class Subscription extends events_1.EventEmitter {
|
|
|
541
542
|
(0, node_opcua_assert_1.assert)(status === node_opcua_status_code_1.StatusCodes.Good);
|
|
542
543
|
}
|
|
543
544
|
(0, node_opcua_assert_1.assert)(this.monitoredItemCount === 0);
|
|
544
|
-
if (this.$session
|
|
545
|
+
if (this.$session?._unexposeSubscriptionDiagnostics) {
|
|
545
546
|
this.$session._unexposeSubscriptionDiagnostics(this);
|
|
546
547
|
}
|
|
547
548
|
this.state = SubscriptionState.CLOSED;
|
|
@@ -646,7 +647,7 @@ class Subscription extends events_1.EventEmitter {
|
|
|
646
647
|
*/
|
|
647
648
|
get disabledMonitoredItemCount() {
|
|
648
649
|
return Object.values(this.monitoredItems).reduce((sum, monitoredItem) => {
|
|
649
|
-
return sum + (monitoredItem.monitoringMode ===
|
|
650
|
+
return sum + (monitoredItem.monitoringMode === node_opcua_service_subscription_1.MonitoringMode.Disabled ? 1 : 0);
|
|
650
651
|
}, 0);
|
|
651
652
|
}
|
|
652
653
|
/**
|
|
@@ -707,16 +708,17 @@ class Subscription extends events_1.EventEmitter {
|
|
|
707
708
|
* @param monitoredItemCreateRequest - the parameters describing the monitored Item to create
|
|
708
709
|
*/
|
|
709
710
|
preCreateMonitoredItem(addressSpace, timestampsToReturn, monitoredItemCreateRequest) {
|
|
710
|
-
(0, node_opcua_assert_1.assert)(monitoredItemCreateRequest instanceof
|
|
711
|
+
(0, node_opcua_assert_1.assert)(monitoredItemCreateRequest instanceof node_opcua_service_subscription_1.MonitoredItemCreateRequest);
|
|
711
712
|
function handle_error(statusCode) {
|
|
712
713
|
return {
|
|
713
|
-
createResult: new
|
|
714
|
+
createResult: new node_opcua_service_subscription_1.MonitoredItemCreateResult({ statusCode }),
|
|
714
715
|
monitoredItemCreateRequest
|
|
715
716
|
};
|
|
716
717
|
}
|
|
717
718
|
const itemToMonitor = monitoredItemCreateRequest.itemToMonitor;
|
|
718
719
|
const node = addressSpace.findNode(itemToMonitor.nodeId);
|
|
719
|
-
if (!node ||
|
|
720
|
+
if (!node ||
|
|
721
|
+
(node.nodeClass !== node_opcua_data_model_1.NodeClass.Variable && node.nodeClass !== node_opcua_data_model_1.NodeClass.Object && node.nodeClass !== node_opcua_data_model_1.NodeClass.Method)) {
|
|
720
722
|
return handle_error(node_opcua_status_code_1.StatusCodes.BadNodeIdUnknown);
|
|
721
723
|
}
|
|
722
724
|
if (itemToMonitor.attributeId === node_opcua_data_model_1.AttributeIds.Value && !(node.nodeClass === node_opcua_data_model_1.NodeClass.Variable)) {
|
|
@@ -769,11 +771,14 @@ class Subscription extends events_1.EventEmitter {
|
|
|
769
771
|
await functor(m);
|
|
770
772
|
}
|
|
771
773
|
}
|
|
772
|
-
postCreateMonitoredItem(monitoredItem, monitoredItemCreateRequest,
|
|
774
|
+
postCreateMonitoredItem(monitoredItem, monitoredItemCreateRequest, _createResult) {
|
|
773
775
|
this._createMonitoredItemStep3(monitoredItem, monitoredItemCreateRequest);
|
|
774
776
|
}
|
|
775
777
|
async createMonitoredItem(addressSpace, timestampsToReturn, monitoredItemCreateRequest) {
|
|
776
778
|
const { monitoredItem, createResult } = this.preCreateMonitoredItem(addressSpace, timestampsToReturn, monitoredItemCreateRequest);
|
|
779
|
+
if (!monitoredItem) {
|
|
780
|
+
return createResult;
|
|
781
|
+
}
|
|
777
782
|
this.postCreateMonitoredItem(monitoredItem, monitoredItemCreateRequest, createResult);
|
|
778
783
|
return createResult;
|
|
779
784
|
}
|
|
@@ -791,7 +796,7 @@ class Subscription extends events_1.EventEmitter {
|
|
|
791
796
|
*/
|
|
792
797
|
removeMonitoredItem(monitoredItemId) {
|
|
793
798
|
debugLog("Removing monitoredIem ", monitoredItemId);
|
|
794
|
-
if (!Object.
|
|
799
|
+
if (!Object.hasOwn(this.monitoredItems, monitoredItemId.toString())) {
|
|
795
800
|
return node_opcua_status_code_1.StatusCodes.BadMonitoredItemIdInvalid;
|
|
796
801
|
}
|
|
797
802
|
const monitoredItem = this.monitoredItems[monitoredItemId];
|
|
@@ -841,8 +846,8 @@ class Subscription extends events_1.EventEmitter {
|
|
|
841
846
|
* @param notification
|
|
842
847
|
*/
|
|
843
848
|
notificationHasExpired(notification) {
|
|
844
|
-
(0, node_opcua_assert_1.assert)(Object.
|
|
845
|
-
(0, node_opcua_assert_1.assert)(isFinite(notification.start_tick + this.maxKeepAliveCount));
|
|
849
|
+
(0, node_opcua_assert_1.assert)(Object.hasOwn(notification, "start_tick"));
|
|
850
|
+
(0, node_opcua_assert_1.assert)(Number.isFinite(notification.start_tick + this.maxKeepAliveCount));
|
|
846
851
|
return notification.start_tick + this.maxKeepAliveCount < this.publishIntervalCount;
|
|
847
852
|
}
|
|
848
853
|
/**
|
|
@@ -901,6 +906,10 @@ class Subscription extends events_1.EventEmitter {
|
|
|
901
906
|
const monitoredItemId = monitoredItems[index];
|
|
902
907
|
const serverHandle = parseInt(monitoredItemId, 10);
|
|
903
908
|
const monitoredItem = this.getMonitoredItem(serverHandle);
|
|
909
|
+
// c8 ignore next
|
|
910
|
+
if (!monitoredItem) {
|
|
911
|
+
throw new Error("monitoredItem is null");
|
|
912
|
+
}
|
|
904
913
|
result.clientHandles[index] = monitoredItem.clientHandle;
|
|
905
914
|
// TODO: serverHandle is defined anywhere in the OPCUA Specification 1.02
|
|
906
915
|
// I am not sure what shall be reported for serverHandle...
|
|
@@ -946,10 +955,10 @@ class Subscription extends events_1.EventEmitter {
|
|
|
946
955
|
// a StatusChangeNotification notificationMessage with the status code
|
|
947
956
|
// Good_SubscriptionTransferred to the old Session.
|
|
948
957
|
debugLog(chalk_1.default.red(" Subscription => Notifying Transfer "));
|
|
949
|
-
const notificationData = new
|
|
958
|
+
const notificationData = new node_opcua_service_subscription_1.StatusChangeNotification({
|
|
950
959
|
status: node_opcua_status_code_1.StatusCodes.GoodSubscriptionTransferred
|
|
951
960
|
});
|
|
952
|
-
if (this.publishEngine
|
|
961
|
+
if (this.publishEngine?.pendingPublishRequestCount) {
|
|
953
962
|
// the GoodSubscriptionTransferred can be processed immediately
|
|
954
963
|
this._addNotificationMessage(notificationData);
|
|
955
964
|
debugLog(chalk_1.default.red("pendingPublishRequestCount"), this.publishEngine?.pendingPublishRequestCount);
|
|
@@ -957,6 +966,11 @@ class Subscription extends events_1.EventEmitter {
|
|
|
957
966
|
}
|
|
958
967
|
else {
|
|
959
968
|
debugLog(chalk_1.default.red("Cannot send GoodSubscriptionTransferred => lets create a TransferredSubscription "));
|
|
969
|
+
// c8 ignore next
|
|
970
|
+
if (!this.publishEngine) {
|
|
971
|
+
warningLog("notifyTransfer: publishEngine is not available");
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
960
974
|
const ts = new i_server_side_publish_engine_1.TransferredSubscription({
|
|
961
975
|
generator: this._sequence_number_generator,
|
|
962
976
|
id: this.id,
|
|
@@ -981,18 +995,18 @@ class Subscription extends events_1.EventEmitter {
|
|
|
981
995
|
_updateCounters(notificationMessage) {
|
|
982
996
|
for (const notificationData of notificationMessage.notificationData || []) {
|
|
983
997
|
// update diagnostics
|
|
984
|
-
if (notificationData instanceof
|
|
985
|
-
const nbNotifs = notificationData.monitoredItems
|
|
998
|
+
if (notificationData instanceof node_opcua_service_subscription_1.DataChangeNotification) {
|
|
999
|
+
const nbNotifs = notificationData.monitoredItems?.length || 0;
|
|
986
1000
|
this.subscriptionDiagnostics.dataChangeNotificationsCount += nbNotifs;
|
|
987
1001
|
this.subscriptionDiagnostics.notificationsCount += nbNotifs;
|
|
988
1002
|
}
|
|
989
|
-
else if (notificationData instanceof
|
|
990
|
-
const nbNotifs = notificationData.events
|
|
1003
|
+
else if (notificationData instanceof node_opcua_service_subscription_1.EventNotificationList) {
|
|
1004
|
+
const nbNotifs = notificationData.events?.length || 0;
|
|
991
1005
|
this.subscriptionDiagnostics.eventNotificationsCount += nbNotifs;
|
|
992
1006
|
this.subscriptionDiagnostics.notificationsCount += nbNotifs;
|
|
993
1007
|
}
|
|
994
1008
|
else {
|
|
995
|
-
(0, node_opcua_assert_1.assert)(notificationData instanceof
|
|
1009
|
+
(0, node_opcua_assert_1.assert)(notificationData instanceof node_opcua_service_subscription_1.StatusChangeNotification);
|
|
996
1010
|
// TODO
|
|
997
1011
|
// note: :there is no way to count StatusChangeNotifications in opcua yet.
|
|
998
1012
|
}
|
|
@@ -1008,23 +1022,27 @@ class Subscription extends events_1.EventEmitter {
|
|
|
1008
1022
|
*/
|
|
1009
1023
|
_publish_pending_notifications() {
|
|
1010
1024
|
const publishEngine = this.publishEngine;
|
|
1025
|
+
// c8 ignore next
|
|
1026
|
+
if (!publishEngine) {
|
|
1027
|
+
throw new Error("publishEngine is null");
|
|
1028
|
+
}
|
|
1011
1029
|
const subscriptionId = this.id;
|
|
1012
1030
|
// preconditions
|
|
1013
1031
|
(0, node_opcua_assert_1.assert)(publishEngine.pendingPublishRequestCount > 0);
|
|
1014
1032
|
(0, node_opcua_assert_1.assert)(this.hasPendingNotifications);
|
|
1015
1033
|
const notificationMessage = this._popNotificationToSend();
|
|
1016
|
-
if (notificationMessage.notificationData
|
|
1034
|
+
if (notificationMessage.notificationData?.length === 0) {
|
|
1017
1035
|
return; // nothing to do
|
|
1018
1036
|
}
|
|
1019
1037
|
const moreNotifications = this.hasPendingNotifications;
|
|
1020
1038
|
this.emit("notification", notificationMessage);
|
|
1021
1039
|
// Update counters ....
|
|
1022
1040
|
this._updateCounters(notificationMessage);
|
|
1023
|
-
(0, node_opcua_assert_1.assert)(Object.
|
|
1024
|
-
(0, node_opcua_assert_1.assert)(Object.
|
|
1041
|
+
(0, node_opcua_assert_1.assert)(Object.hasOwn(notificationMessage, "sequenceNumber"));
|
|
1042
|
+
(0, node_opcua_assert_1.assert)(Object.hasOwn(notificationMessage, "notificationData"));
|
|
1025
1043
|
// update diagnostics
|
|
1026
1044
|
this.subscriptionDiagnostics.publishRequestCount += 1;
|
|
1027
|
-
const response = new
|
|
1045
|
+
const response = new node_opcua_service_subscription_1.PublishResponse({
|
|
1028
1046
|
moreNotifications,
|
|
1029
1047
|
notificationMessage: {
|
|
1030
1048
|
notificationData: notificationMessage.notificationData,
|
|
@@ -1048,13 +1066,13 @@ class Subscription extends events_1.EventEmitter {
|
|
|
1048
1066
|
// debugLog(notificationMessage.toString());
|
|
1049
1067
|
}
|
|
1050
1068
|
if (this.state !== SubscriptionState.CLOSED) {
|
|
1051
|
-
(0, node_opcua_assert_1.assert)(notificationMessage.notificationData
|
|
1069
|
+
(0, node_opcua_assert_1.assert)((notificationMessage.notificationData?.length || 0) > 0, "We are not expecting a keep-alive message here");
|
|
1052
1070
|
this.state = SubscriptionState.NORMAL;
|
|
1053
|
-
debugLog(
|
|
1071
|
+
debugLog(`subscription ${this.id}${chalk_1.default.bgYellow(" set to NORMAL")}`);
|
|
1054
1072
|
}
|
|
1055
1073
|
}
|
|
1056
1074
|
process_subscription() {
|
|
1057
|
-
(0, node_opcua_assert_1.assert)(this.publishEngine
|
|
1075
|
+
(0, node_opcua_assert_1.assert)((this.publishEngine?.pendingPublishRequestCount || 0) > 0);
|
|
1058
1076
|
if (!this.publishingEnabled) {
|
|
1059
1077
|
// no publish to do, except keep alive
|
|
1060
1078
|
debugLog(" -> no publish to do, except keep alive");
|
|
@@ -1153,10 +1171,10 @@ class Subscription extends events_1.EventEmitter {
|
|
|
1153
1171
|
this.discardOldSentNotifications();
|
|
1154
1172
|
// c8 ignore next
|
|
1155
1173
|
if (doDebug) {
|
|
1156
|
-
debugLog(t(new Date())
|
|
1174
|
+
debugLog(`${t(new Date())} ${this._life_time_counter}/${this.lifeTimeCount}${chalk_1.default.cyan(" Subscription#_tick")}`, " processing subscriptionId=", this.id, "hasUncollectedMonitoredItemNotifications = ", this.hasUncollectedMonitoredItemNotifications, " publishingIntervalCount =", this.publishIntervalCount);
|
|
1157
1175
|
}
|
|
1158
1176
|
// give a chance to the publish engine to cancel timed out publish requests
|
|
1159
|
-
this.publishEngine
|
|
1177
|
+
this.publishEngine?._on_tick();
|
|
1160
1178
|
this.publishIntervalCount += 1;
|
|
1161
1179
|
if (this.state === SubscriptionState.LATE) {
|
|
1162
1180
|
this.increaseLifeTimeCounter();
|
|
@@ -1172,12 +1190,15 @@ class Subscription extends events_1.EventEmitter {
|
|
|
1172
1190
|
this.emit("expired");
|
|
1173
1191
|
// notify new terminated status only when subscription has timeout.
|
|
1174
1192
|
doDebug && debugLog("adding StatusChangeNotification notification message for BadTimeout subscription = ", this.id);
|
|
1175
|
-
this._addNotificationMessage(new
|
|
1193
|
+
this._addNotificationMessage(new node_opcua_service_subscription_1.StatusChangeNotification({ status: node_opcua_status_code_1.StatusCodes.BadTimeout }));
|
|
1176
1194
|
// kill timer and delete monitored items and transfer pending notification messages
|
|
1177
1195
|
this.terminate();
|
|
1178
1196
|
return;
|
|
1179
1197
|
}
|
|
1180
1198
|
const publishEngine = this.publishEngine;
|
|
1199
|
+
if (!publishEngine) {
|
|
1200
|
+
throw new Error("publishEngine is null");
|
|
1201
|
+
}
|
|
1181
1202
|
// c8 ignore next
|
|
1182
1203
|
doDebug && debugLog("Subscription#_tick self._pending_notifications= ", this._pending_notifications.size);
|
|
1183
1204
|
if (publishEngine.pendingPublishRequestCount === 0 &&
|
|
@@ -1214,7 +1235,7 @@ class Subscription extends events_1.EventEmitter {
|
|
|
1214
1235
|
*/
|
|
1215
1236
|
_sendKeepAliveResponse() {
|
|
1216
1237
|
const future_sequence_number = this._get_future_sequence_number();
|
|
1217
|
-
if (this.publishEngine
|
|
1238
|
+
if (this.publishEngine?.send_keep_alive_response(this.id, future_sequence_number)) {
|
|
1218
1239
|
this.messageSent = true;
|
|
1219
1240
|
// c8 ignore next
|
|
1220
1241
|
doDebug &&
|
|
@@ -1277,15 +1298,15 @@ class Subscription extends events_1.EventEmitter {
|
|
|
1277
1298
|
*/
|
|
1278
1299
|
_popNotificationToSend() {
|
|
1279
1300
|
(0, node_opcua_assert_1.assert)(this._pending_notifications.size > 0);
|
|
1280
|
-
const notificationMessage = new
|
|
1301
|
+
const notificationMessage = new node_opcua_service_subscription_1.NotificationMessage({
|
|
1281
1302
|
sequenceNumber: 0xffffffff,
|
|
1282
1303
|
notificationData: [],
|
|
1283
1304
|
publishTime: new Date()
|
|
1284
1305
|
}); //
|
|
1285
|
-
const dataChangeNotifications = new
|
|
1306
|
+
const dataChangeNotifications = new node_opcua_service_subscription_1.DataChangeNotification({
|
|
1286
1307
|
monitoredItems: []
|
|
1287
1308
|
});
|
|
1288
|
-
const eventNotificationList = new
|
|
1309
|
+
const eventNotificationList = new node_opcua_service_subscription_1.EventNotificationList({
|
|
1289
1310
|
events: []
|
|
1290
1311
|
});
|
|
1291
1312
|
let statusChangeNotification;
|
|
@@ -1295,36 +1316,36 @@ class Subscription extends events_1.EventEmitter {
|
|
|
1295
1316
|
const m = this.maxNotificationsPerPublish;
|
|
1296
1317
|
while (i < m && this._pending_notifications.size > 0) {
|
|
1297
1318
|
if (hasEventFieldList || hasMonitoredItemNotification) {
|
|
1298
|
-
const notification1 = this._pending_notifications.first()
|
|
1299
|
-
if (notification1 instanceof
|
|
1319
|
+
const notification1 = this._pending_notifications.first()?.notification;
|
|
1320
|
+
if (notification1 instanceof node_opcua_service_subscription_1.StatusChangeNotification) {
|
|
1300
1321
|
break;
|
|
1301
1322
|
}
|
|
1302
1323
|
}
|
|
1303
|
-
const notification = this._pending_notifications.shift()
|
|
1304
|
-
if (notification instanceof
|
|
1324
|
+
const notification = this._pending_notifications.shift()?.notification;
|
|
1325
|
+
if (notification instanceof node_opcua_service_subscription_1.MonitoredItemNotification) {
|
|
1305
1326
|
(0, node_opcua_assert_1.assert)(notification.clientHandle !== 4294967295);
|
|
1306
|
-
dataChangeNotifications.monitoredItems
|
|
1327
|
+
dataChangeNotifications.monitoredItems?.push(notification);
|
|
1307
1328
|
hasMonitoredItemNotification = 1;
|
|
1308
1329
|
}
|
|
1309
1330
|
else if (notification instanceof node_opcua_types_1.EventFieldList) {
|
|
1310
|
-
eventNotificationList.events
|
|
1331
|
+
eventNotificationList.events?.push(notification);
|
|
1311
1332
|
hasEventFieldList = 1;
|
|
1312
1333
|
}
|
|
1313
|
-
else if (notification instanceof
|
|
1334
|
+
else if (notification instanceof node_opcua_service_subscription_1.StatusChangeNotification) {
|
|
1314
1335
|
// to do
|
|
1315
1336
|
statusChangeNotification = notification;
|
|
1316
1337
|
break;
|
|
1317
1338
|
}
|
|
1318
1339
|
i += 1;
|
|
1319
1340
|
}
|
|
1320
|
-
if (dataChangeNotifications.monitoredItems
|
|
1321
|
-
notificationMessage.notificationData
|
|
1341
|
+
if (dataChangeNotifications.monitoredItems?.length) {
|
|
1342
|
+
notificationMessage.notificationData?.push(dataChangeNotifications);
|
|
1322
1343
|
}
|
|
1323
|
-
if (eventNotificationList.events
|
|
1324
|
-
notificationMessage.notificationData
|
|
1344
|
+
if (eventNotificationList.events?.length) {
|
|
1345
|
+
notificationMessage.notificationData?.push(eventNotificationList);
|
|
1325
1346
|
}
|
|
1326
1347
|
if (statusChangeNotification) {
|
|
1327
|
-
notificationMessage.notificationData
|
|
1348
|
+
notificationMessage.notificationData?.push(statusChangeNotification);
|
|
1328
1349
|
}
|
|
1329
1350
|
return notificationMessage;
|
|
1330
1351
|
}
|
|
@@ -1360,7 +1381,7 @@ class Subscription extends events_1.EventEmitter {
|
|
|
1360
1381
|
_createMonitoredItemStep2(timestampsToReturn, monitoredItemCreateRequest, node) {
|
|
1361
1382
|
// note : most of the parameter inconsistencies shall have been handled by the caller
|
|
1362
1383
|
// any error here will raise an assert here
|
|
1363
|
-
(0, node_opcua_assert_1.assert)(monitoredItemCreateRequest instanceof
|
|
1384
|
+
(0, node_opcua_assert_1.assert)(monitoredItemCreateRequest instanceof node_opcua_service_subscription_1.MonitoredItemCreateRequest);
|
|
1364
1385
|
const itemToMonitor = monitoredItemCreateRequest.itemToMonitor;
|
|
1365
1386
|
// xx check if attribute Id invalid (we only support Value or EventNotifier )
|
|
1366
1387
|
// xx assert(itemToMonitor.attributeId !== AttributeIds.INVALID);
|
|
@@ -1381,7 +1402,7 @@ class Subscription extends events_1.EventEmitter {
|
|
|
1381
1402
|
this.globalCounter.totalMonitoredItemCount += 1;
|
|
1382
1403
|
(0, node_opcua_assert_1.assert)(monitoredItem.clientHandle !== 4294967295);
|
|
1383
1404
|
const filterResult = _process_filter(node, requestedParameters.filter);
|
|
1384
|
-
const monitoredItemCreateResult = new
|
|
1405
|
+
const monitoredItemCreateResult = new node_opcua_service_subscription_1.MonitoredItemCreateResult({
|
|
1385
1406
|
filterResult,
|
|
1386
1407
|
monitoredItemId,
|
|
1387
1408
|
revisedQueueSize: monitoredItem.queueSize,
|
|
@@ -1401,7 +1422,7 @@ class Subscription extends events_1.EventEmitter {
|
|
|
1401
1422
|
if (!monitoredItem) {
|
|
1402
1423
|
return;
|
|
1403
1424
|
}
|
|
1404
|
-
(0, node_opcua_assert_1.assert)(monitoredItem.monitoringMode ===
|
|
1425
|
+
(0, node_opcua_assert_1.assert)(monitoredItem.monitoringMode === node_opcua_service_subscription_1.MonitoringMode.Invalid);
|
|
1405
1426
|
(0, node_opcua_assert_1.assert)(typeof monitoredItem.samplingFunc === "function", " expecting a sampling function here");
|
|
1406
1427
|
const monitoringMode = monitoredItemCreateRequest.monitoringMode; // Disabled, Sampling, Reporting
|
|
1407
1428
|
monitoredItem.setMonitoringMode(monitoringMode);
|