node-opcua-client 2.71.0 → 2.72.2

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 (81) hide show
  1. package/dist/alarms_and_conditions/client_alarm.d.ts +45 -43
  2. package/dist/alarms_and_conditions/client_alarm.js +101 -84
  3. package/dist/alarms_and_conditions/client_alarm.js.map +1 -1
  4. package/dist/alarms_and_conditions/client_alarm_list.d.ts +25 -21
  5. package/dist/alarms_and_conditions/client_alarm_list.js +97 -97
  6. package/dist/alarms_and_conditions/client_alarm_list.js.map +1 -1
  7. package/dist/alarms_and_conditions/client_alarm_tools.d.ts +4 -4
  8. package/dist/alarms_and_conditions/client_alarm_tools.js +152 -139
  9. package/dist/alarms_and_conditions/client_alarm_tools.js.map +1 -1
  10. package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.d.ts +18 -18
  11. package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.js +190 -190
  12. package/dist/alarms_and_conditions/client_alarm_tools_dump_event.d.ts +9 -9
  13. package/dist/alarms_and_conditions/client_alarm_tools_dump_event.js +73 -73
  14. package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.d.ts +8 -8
  15. package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.js +120 -120
  16. package/dist/alarms_and_conditions/client_tools.d.ts +7 -7
  17. package/dist/alarms_and_conditions/client_tools.js +180 -180
  18. package/dist/alarms_and_conditions/client_tools.js.map +1 -1
  19. package/dist/client_base.d.ts +294 -290
  20. package/dist/client_base.js +13 -13
  21. package/dist/client_base.js.map +1 -1
  22. package/dist/client_monitored_item.d.ts +21 -21
  23. package/dist/client_monitored_item.js +11 -11
  24. package/dist/client_monitored_item_base.d.ts +39 -39
  25. package/dist/client_monitored_item_base.js +2 -2
  26. package/dist/client_monitored_item_group.d.ts +18 -18
  27. package/dist/client_monitored_item_group.js +13 -13
  28. package/dist/client_monitored_item_toolbox.d.ts +15 -15
  29. package/dist/client_monitored_item_toolbox.js +117 -117
  30. package/dist/client_session.d.ts +484 -484
  31. package/dist/client_session.js +10 -10
  32. package/dist/client_session_keepalive_manager.d.ts +34 -34
  33. package/dist/client_session_keepalive_manager.js +150 -150
  34. package/dist/client_subscription.d.ts +241 -241
  35. package/dist/client_subscription.js +14 -14
  36. package/dist/client_utils.d.ts +22 -22
  37. package/dist/client_utils.js +88 -88
  38. package/dist/common.d.ts +17 -17
  39. package/dist/common.js +5 -5
  40. package/dist/index.d.ts +55 -55
  41. package/dist/index.js +93 -93
  42. package/dist/opcua_client.d.ts +132 -132
  43. package/dist/opcua_client.js +33 -33
  44. package/dist/opcua_client.js.map +1 -1
  45. package/dist/private/client_base_impl.d.ts +169 -169
  46. package/dist/private/client_base_impl.js +1324 -1316
  47. package/dist/private/client_base_impl.js.map +1 -1
  48. package/dist/private/client_monitored_item_base_impl.d.ts +3 -3
  49. package/dist/private/client_monitored_item_base_impl.js +4 -4
  50. package/dist/private/client_monitored_item_group_impl.d.ts +53 -53
  51. package/dist/private/client_monitored_item_group_impl.js +159 -159
  52. package/dist/private/client_monitored_item_impl.d.ts +93 -93
  53. package/dist/private/client_monitored_item_impl.js +304 -304
  54. package/dist/private/client_publish_engine.d.ts +62 -62
  55. package/dist/private/client_publish_engine.js +408 -408
  56. package/dist/private/client_session_impl.d.ts +621 -621
  57. package/dist/private/client_session_impl.js +1301 -1301
  58. package/dist/private/client_subscription_impl.d.ts +93 -93
  59. package/dist/private/client_subscription_impl.js +743 -734
  60. package/dist/private/client_subscription_impl.js.map +1 -1
  61. package/dist/private/i_private_client.d.ts +18 -18
  62. package/dist/private/i_private_client.js +2 -2
  63. package/dist/private/opcua_client_impl.d.ts +169 -169
  64. package/dist/private/opcua_client_impl.js +978 -978
  65. package/dist/reconnection.d.ts +9 -9
  66. package/dist/reconnection.js +362 -362
  67. package/dist/tools/findservers.d.ts +20 -20
  68. package/dist/tools/findservers.js +61 -61
  69. package/dist/tools/read_history_server_capabilities.d.ts +6 -6
  70. package/dist/tools/read_history_server_capabilities.js +99 -99
  71. package/dist/verify.d.ts +5 -5
  72. package/dist/verify.js +134 -134
  73. package/package.json +30 -30
  74. package/source/alarms_and_conditions/client_alarm.ts +21 -1
  75. package/source/alarms_and_conditions/client_alarm_list.ts +6 -2
  76. package/source/alarms_and_conditions/client_alarm_tools.ts +32 -15
  77. package/source/alarms_and_conditions/client_tools.ts +4 -4
  78. package/source/client_base.ts +6 -3
  79. package/source/opcua_client.ts +0 -2
  80. package/source/private/client_base_impl.ts +22 -13
  81. package/source/private/client_subscription_impl.ts +8 -0
@@ -1,305 +1,305 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClientMonitoredItemImpl = void 0;
4
- /**
5
- * @module node-opcua-client-private
6
- */
7
- // tslint:disable:unified-signatures
8
- // tslint:disable:no-empty
9
- const events_1 = require("events");
10
- const node_opcua_assert_1 = require("node-opcua-assert");
11
- const node_opcua_data_model_1 = require("node-opcua-data-model");
12
- const node_opcua_data_value_1 = require("node-opcua-data-value");
13
- const node_opcua_debug_1 = require("node-opcua-debug");
14
- const node_opcua_service_filter_1 = require("node-opcua-service-filter");
15
- const node_opcua_service_read_1 = require("node-opcua-service-read");
16
- const node_opcua_service_subscription_1 = require("node-opcua-service-subscription");
17
- const node_opcua_status_code_1 = require("node-opcua-status-code");
18
- const client_monitored_item_1 = require("../client_monitored_item");
19
- const client_monitored_item_toolbox_1 = require("../client_monitored_item_toolbox");
20
- const client_subscription_impl_1 = require("./client_subscription_impl");
21
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
22
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
23
- /**
24
- * ClientMonitoredItem
25
- * @class ClientMonitoredItem
26
- * @extends ClientMonitoredItemBase
27
- *
28
- * event:
29
- * "initialized"
30
- * "err"
31
- * "changed"
32
- *
33
- * note: this.monitoringMode = subscription_service.MonitoringMode.Reporting;
34
- */
35
- class ClientMonitoredItemImpl extends events_1.EventEmitter {
36
- constructor(subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode = node_opcua_service_subscription_1.MonitoringMode.Reporting) {
37
- super();
38
- this.statusCode = node_opcua_status_code_1.StatusCodes.BadDataUnavailable;
39
- (0, node_opcua_assert_1.assert)(subscription.constructor.name === "ClientSubscriptionImpl");
40
- this.subscription = subscription;
41
- this.itemToMonitor = new node_opcua_service_read_1.ReadValueId(itemToMonitor);
42
- this.monitoringParameters = new node_opcua_service_subscription_1.MonitoringParameters(monitoringParameters);
43
- this.monitoringMode = monitoringMode;
44
- (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle === 0xffffffff, "should not have a client handle yet");
45
- (0, node_opcua_assert_1.assert)(subscription.session, "expecting session");
46
- timestampsToReturn = (0, node_opcua_data_value_1.coerceTimestampsToReturn)(timestampsToReturn);
47
- (0, node_opcua_assert_1.assert)(subscription.constructor.name === "ClientSubscriptionImpl");
48
- this.timestampsToReturn = timestampsToReturn;
49
- }
50
- toString() {
51
- var _a, _b;
52
- let ret = "";
53
- ret += "itemToMonitor: " + this.itemToMonitor.toString() + "\n";
54
- ret += "monitoringParameters: " + this.monitoringParameters.toString() + "\n";
55
- ret += "timestampsToReturn: " + this.timestampsToReturn.toString() + "\n";
56
- ret += "itemToMonitor " + this.itemToMonitor.nodeId + "\n";
57
- ret += "statusCode " + ((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.toString()) + "\n";
58
- ret += "result =" + ((_b = this.result) === null || _b === void 0 ? void 0 : _b.toString()) + "\n";
59
- return ret;
60
- }
61
- terminate(...args) {
62
- const done = args[0];
63
- (0, node_opcua_assert_1.assert)(typeof done === "function");
64
- const subscription = this.subscription;
65
- subscription._delete_monitored_items([this], (err) => {
66
- if (done) {
67
- done(err);
68
- }
69
- });
70
- }
71
- modify(...args) {
72
- if (args.length === 2) {
73
- return this.modify(args[0], null, args[1]);
74
- }
75
- const parameters = args[0];
76
- const timestampsToReturn = args[1];
77
- const callback = args[2];
78
- this.timestampsToReturn = timestampsToReturn || this.timestampsToReturn;
79
- client_monitored_item_toolbox_1.ClientMonitoredItemToolbox._toolbox_modify(this.subscription, [this], parameters, this.timestampsToReturn, (err, results) => {
80
- if (err) {
81
- return callback(err);
82
- }
83
- if (!results) {
84
- return callback(new Error("internal error"));
85
- }
86
- (0, node_opcua_assert_1.assert)(results.length === 1);
87
- callback(null, results[0]);
88
- });
89
- }
90
- setMonitoringMode(...args) {
91
- const monitoringMode = args[0];
92
- const callback = args[1];
93
- client_monitored_item_toolbox_1.ClientMonitoredItemToolbox._toolbox_setMonitoringMode(this.subscription, [this], monitoringMode, (err, statusCodes) => {
94
- callback(err ? err : null, statusCodes[0]);
95
- });
96
- }
97
- /**
98
- * @internal
99
- * @param value
100
- * @private
101
- */
102
- _notify_value_change(value) {
103
- var _a;
104
- // it is possible that the first notification arrives before the CreateMonitoredItemsRequest is fully proceed
105
- // in this case we need to put the dataValue aside so we can send the notification changed after
106
- // the node-opcua client had time to fully install the on("changed") event handler
107
- if (((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.value) === node_opcua_status_code_1.StatusCodes.BadDataUnavailable.value) {
108
- this._pendingDataValue = this._pendingDataValue || [];
109
- this._pendingDataValue.push(value);
110
- return;
111
- }
112
- /**
113
- * Notify the observers that the MonitoredItem value has changed on the server side.
114
- * @event changed
115
- * @param value
116
- */
117
- try {
118
- this.emit("changed", value);
119
- }
120
- catch (err) {
121
- debugLog("Exception raised inside the event handler called by ClientMonitoredItem.on('change')", err);
122
- debugLog("Please verify the application using this node-opcua client");
123
- }
124
- }
125
- /**
126
- * @internal
127
- * @param eventFields
128
- * @private
129
- */
130
- _notify_event(eventFields) {
131
- var _a;
132
- if (((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.value) === node_opcua_status_code_1.StatusCodes.BadDataUnavailable.value) {
133
- this._pendingEvents = this._pendingEvents || [];
134
- this._pendingEvents.push(eventFields);
135
- return;
136
- }
137
- /**
138
- * Notify the observers that the MonitoredItem value has changed on the server side.
139
- * @event changed
140
- * @param value
141
- */
142
- try {
143
- this.emit("changed", eventFields);
144
- }
145
- catch (err) {
146
- debugLog("Exception raised inside the event handler called by ClientMonitoredItem.on('change')", err);
147
- debugLog("Please verify the application using this node-opcua client");
148
- }
149
- }
150
- /**
151
- * @internal
152
- * @private
153
- */
154
- _prepare_for_monitoring() {
155
- (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle === 4294967295, "should not have a client handle yet");
156
- const subscription = this.subscription;
157
- this.monitoringParameters.clientHandle = subscription.nextClientHandle();
158
- (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle > 0 && this.monitoringParameters.clientHandle !== 4294967295);
159
- // If attributeId is EventNotifier then monitoring parameters need a filter.
160
- // The filter must then either be DataChangeFilter, EventFilter or AggregateFilter.
161
- // todo can be done in another way?
162
- // todo implement AggregateFilter
163
- // todo support DataChangeFilter
164
- // todo support whereClause
165
- if (this.itemToMonitor.attributeId === node_opcua_data_model_1.AttributeIds.EventNotifier) {
166
- //
167
- // see OPCUA Spec 1.02 part 4 page 65 : 5.12.1.4 Filter
168
- // see part 4 page 130: 7.16.3 EventFilter
169
- // part 3 page 11 : 4.6 Event Model
170
- // To monitor for Events, the attributeId element of the ReadValueId structure is the
171
- // the id of the EventNotifierAttribute
172
- // OPC Unified Architecture 1.02, Part 4 5.12.1.2 Sampling interval page 64:
173
- // "A Client shall define a sampling interval of 0 if it subscribes for Events."
174
- // toDO
175
- // note : the EventFilter is used when monitoring Events.
176
- this.monitoringParameters.filter = this.monitoringParameters.filter || new node_opcua_service_filter_1.EventFilter({});
177
- const filter = this.monitoringParameters.filter;
178
- // istanbul ignore next
179
- if (!filter) {
180
- return { error: "Internal Error" };
181
- }
182
- if (filter.schema.name !== "EventFilter") {
183
- return {
184
- error: "Mismatch between attributeId and filter in monitoring parameters : " +
185
- "Got a " +
186
- filter.schema.name +
187
- " but a EventFilter object is required " +
188
- "when itemToMonitor.attributeId== AttributeIds.EventNotifier"
189
- };
190
- }
191
- }
192
- else if (this.itemToMonitor.attributeId === node_opcua_data_model_1.AttributeIds.Value) {
193
- // the DataChangeFilter and the AggregateFilter are used when monitoring Variable Values
194
- // The Value Attribute is used when monitoring Variables. Variable values are monitored for a change
195
- // in value or a change in their status. The filters defined in this standard (see 7.16.2) and in Part 8 are
196
- // used to determine if the value change is large enough to cause a Notification to be generated for the
197
- // to do : check 'DataChangeFilter' && 'AggregateFilter'
198
- }
199
- else {
200
- if (this.monitoringParameters.filter) {
201
- return {
202
- error: "Mismatch between attributeId and filter in monitoring parameters : " +
203
- "no filter expected when attributeId is not Value or EventNotifier"
204
- };
205
- }
206
- }
207
- return {
208
- itemToMonitor: this.itemToMonitor,
209
- monitoringMode: this.monitoringMode,
210
- requestedParameters: this.monitoringParameters
211
- };
212
- }
213
- /**
214
- * @internal
215
- * @param monitoredItemResult
216
- * @private
217
- */
218
- _applyResult(monitoredItemResult) {
219
- this.statusCode = monitoredItemResult.statusCode;
220
- /* istanbul ignore else */
221
- if (monitoredItemResult.statusCode === node_opcua_status_code_1.StatusCodes.Good) {
222
- this.result = monitoredItemResult;
223
- this.monitoredItemId = monitoredItemResult.monitoredItemId;
224
- this.monitoringParameters.samplingInterval = monitoredItemResult.revisedSamplingInterval;
225
- this.monitoringParameters.queueSize = monitoredItemResult.revisedQueueSize;
226
- this.filterResult = monitoredItemResult.filterResult || undefined;
227
- }
228
- // some PublishRequest with DataNotificationChange might have been sent by the server, before the monitored
229
- // item has been fully initialized it is time to process now any pending notification that were put on hold.
230
- if (this._pendingDataValue) {
231
- const dataValues = this._pendingDataValue;
232
- this._pendingDataValue = undefined;
233
- setImmediate(() => {
234
- dataValues.map((dataValue) => this._notify_value_change(dataValue));
235
- });
236
- }
237
- if (this._pendingEvents) {
238
- const events = this._pendingEvents;
239
- this._pendingEvents = undefined;
240
- setImmediate(() => {
241
- events.map((event) => this._notify_event(event));
242
- });
243
- }
244
- }
245
- _before_create() {
246
- const subscription = this.subscription;
247
- subscription._add_monitored_item(this.monitoringParameters.clientHandle, this);
248
- }
249
- /**
250
- * @internal
251
- * @param monitoredItemResult
252
- * @private
253
- */
254
- _after_create(monitoredItemResult) {
255
- this._applyResult(monitoredItemResult);
256
- if (this.statusCode === node_opcua_status_code_1.StatusCodes.Good) {
257
- /**
258
- * Notify the observers that the monitored item is now fully initialized.
259
- * @event initialized
260
- */
261
- this.emit("initialized");
262
- }
263
- else {
264
- /**
265
- * Notify the observers that the monitored item has failed to initialize.
266
- * @event err
267
- * @param statusCode {StatusCode}
268
- */
269
- const err = new Error(monitoredItemResult.statusCode.toString());
270
- this._terminate_and_emit(err);
271
- }
272
- }
273
- _terminate_and_emit(err) {
274
- if (this.statusCode.value === node_opcua_status_code_1.StatusCodes.Bad.value) {
275
- return; // already terminated
276
- }
277
- if (err) {
278
- this.emit("err", err.message);
279
- }
280
- (0, node_opcua_assert_1.assert)(!this._terminated);
281
- this._terminated = true;
282
- /**
283
- * Notify the observer that this monitored item has been terminated.
284
- * @event terminated
285
- */
286
- this.emit("terminated", err);
287
- this.removeAllListeners();
288
- this.statusCode = node_opcua_status_code_1.StatusCodes.Bad;
289
- // also remove from subscription
290
- const clientHandle = this.monitoringParameters.clientHandle;
291
- delete this.subscription.monitoredItems[clientHandle];
292
- }
293
- }
294
- exports.ClientMonitoredItemImpl = ClientMonitoredItemImpl;
295
- // tslint:disable:no-var-requires
296
- // tslint:disable:max-line-length
297
- const thenify = require("thenify");
298
- const opts = { multiArgs: false };
299
- ClientMonitoredItemImpl.prototype.terminate = thenify.withCallback(ClientMonitoredItemImpl.prototype.terminate);
300
- ClientMonitoredItemImpl.prototype.setMonitoringMode = thenify.withCallback(ClientMonitoredItemImpl.prototype.setMonitoringMode);
301
- ClientMonitoredItemImpl.prototype.modify = thenify.withCallback(ClientMonitoredItemImpl.prototype.modify);
302
- client_monitored_item_1.ClientMonitoredItem.create = (subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode = node_opcua_service_subscription_1.MonitoringMode.Reporting) => {
303
- return (0, client_subscription_impl_1.ClientMonitoredItem_create)(subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode);
304
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientMonitoredItemImpl = void 0;
4
+ /**
5
+ * @module node-opcua-client-private
6
+ */
7
+ // tslint:disable:unified-signatures
8
+ // tslint:disable:no-empty
9
+ const events_1 = require("events");
10
+ const node_opcua_assert_1 = require("node-opcua-assert");
11
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
12
+ const node_opcua_data_value_1 = require("node-opcua-data-value");
13
+ const node_opcua_debug_1 = require("node-opcua-debug");
14
+ const node_opcua_service_filter_1 = require("node-opcua-service-filter");
15
+ const node_opcua_service_read_1 = require("node-opcua-service-read");
16
+ const node_opcua_service_subscription_1 = require("node-opcua-service-subscription");
17
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
18
+ const client_monitored_item_1 = require("../client_monitored_item");
19
+ const client_monitored_item_toolbox_1 = require("../client_monitored_item_toolbox");
20
+ const client_subscription_impl_1 = require("./client_subscription_impl");
21
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
22
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
23
+ /**
24
+ * ClientMonitoredItem
25
+ * @class ClientMonitoredItem
26
+ * @extends ClientMonitoredItemBase
27
+ *
28
+ * event:
29
+ * "initialized"
30
+ * "err"
31
+ * "changed"
32
+ *
33
+ * note: this.monitoringMode = subscription_service.MonitoringMode.Reporting;
34
+ */
35
+ class ClientMonitoredItemImpl extends events_1.EventEmitter {
36
+ constructor(subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode = node_opcua_service_subscription_1.MonitoringMode.Reporting) {
37
+ super();
38
+ this.statusCode = node_opcua_status_code_1.StatusCodes.BadDataUnavailable;
39
+ (0, node_opcua_assert_1.assert)(subscription.constructor.name === "ClientSubscriptionImpl");
40
+ this.subscription = subscription;
41
+ this.itemToMonitor = new node_opcua_service_read_1.ReadValueId(itemToMonitor);
42
+ this.monitoringParameters = new node_opcua_service_subscription_1.MonitoringParameters(monitoringParameters);
43
+ this.monitoringMode = monitoringMode;
44
+ (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle === 0xffffffff, "should not have a client handle yet");
45
+ (0, node_opcua_assert_1.assert)(subscription.session, "expecting session");
46
+ timestampsToReturn = (0, node_opcua_data_value_1.coerceTimestampsToReturn)(timestampsToReturn);
47
+ (0, node_opcua_assert_1.assert)(subscription.constructor.name === "ClientSubscriptionImpl");
48
+ this.timestampsToReturn = timestampsToReturn;
49
+ }
50
+ toString() {
51
+ var _a, _b;
52
+ let ret = "";
53
+ ret += "itemToMonitor: " + this.itemToMonitor.toString() + "\n";
54
+ ret += "monitoringParameters: " + this.monitoringParameters.toString() + "\n";
55
+ ret += "timestampsToReturn: " + this.timestampsToReturn.toString() + "\n";
56
+ ret += "itemToMonitor " + this.itemToMonitor.nodeId + "\n";
57
+ ret += "statusCode " + ((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.toString()) + "\n";
58
+ ret += "result =" + ((_b = this.result) === null || _b === void 0 ? void 0 : _b.toString()) + "\n";
59
+ return ret;
60
+ }
61
+ terminate(...args) {
62
+ const done = args[0];
63
+ (0, node_opcua_assert_1.assert)(typeof done === "function");
64
+ const subscription = this.subscription;
65
+ subscription._delete_monitored_items([this], (err) => {
66
+ if (done) {
67
+ done(err);
68
+ }
69
+ });
70
+ }
71
+ modify(...args) {
72
+ if (args.length === 2) {
73
+ return this.modify(args[0], null, args[1]);
74
+ }
75
+ const parameters = args[0];
76
+ const timestampsToReturn = args[1];
77
+ const callback = args[2];
78
+ this.timestampsToReturn = timestampsToReturn || this.timestampsToReturn;
79
+ client_monitored_item_toolbox_1.ClientMonitoredItemToolbox._toolbox_modify(this.subscription, [this], parameters, this.timestampsToReturn, (err, results) => {
80
+ if (err) {
81
+ return callback(err);
82
+ }
83
+ if (!results) {
84
+ return callback(new Error("internal error"));
85
+ }
86
+ (0, node_opcua_assert_1.assert)(results.length === 1);
87
+ callback(null, results[0]);
88
+ });
89
+ }
90
+ setMonitoringMode(...args) {
91
+ const monitoringMode = args[0];
92
+ const callback = args[1];
93
+ client_monitored_item_toolbox_1.ClientMonitoredItemToolbox._toolbox_setMonitoringMode(this.subscription, [this], monitoringMode, (err, statusCodes) => {
94
+ callback(err ? err : null, statusCodes[0]);
95
+ });
96
+ }
97
+ /**
98
+ * @internal
99
+ * @param value
100
+ * @private
101
+ */
102
+ _notify_value_change(value) {
103
+ var _a;
104
+ // it is possible that the first notification arrives before the CreateMonitoredItemsRequest is fully proceed
105
+ // in this case we need to put the dataValue aside so we can send the notification changed after
106
+ // the node-opcua client had time to fully install the on("changed") event handler
107
+ if (((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.value) === node_opcua_status_code_1.StatusCodes.BadDataUnavailable.value) {
108
+ this._pendingDataValue = this._pendingDataValue || [];
109
+ this._pendingDataValue.push(value);
110
+ return;
111
+ }
112
+ /**
113
+ * Notify the observers that the MonitoredItem value has changed on the server side.
114
+ * @event changed
115
+ * @param value
116
+ */
117
+ try {
118
+ this.emit("changed", value);
119
+ }
120
+ catch (err) {
121
+ debugLog("Exception raised inside the event handler called by ClientMonitoredItem.on('change')", err);
122
+ debugLog("Please verify the application using this node-opcua client");
123
+ }
124
+ }
125
+ /**
126
+ * @internal
127
+ * @param eventFields
128
+ * @private
129
+ */
130
+ _notify_event(eventFields) {
131
+ var _a;
132
+ if (((_a = this.statusCode) === null || _a === void 0 ? void 0 : _a.value) === node_opcua_status_code_1.StatusCodes.BadDataUnavailable.value) {
133
+ this._pendingEvents = this._pendingEvents || [];
134
+ this._pendingEvents.push(eventFields);
135
+ return;
136
+ }
137
+ /**
138
+ * Notify the observers that the MonitoredItem value has changed on the server side.
139
+ * @event changed
140
+ * @param value
141
+ */
142
+ try {
143
+ this.emit("changed", eventFields);
144
+ }
145
+ catch (err) {
146
+ debugLog("Exception raised inside the event handler called by ClientMonitoredItem.on('change')", err);
147
+ debugLog("Please verify the application using this node-opcua client");
148
+ }
149
+ }
150
+ /**
151
+ * @internal
152
+ * @private
153
+ */
154
+ _prepare_for_monitoring() {
155
+ (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle === 4294967295, "should not have a client handle yet");
156
+ const subscription = this.subscription;
157
+ this.monitoringParameters.clientHandle = subscription.nextClientHandle();
158
+ (0, node_opcua_assert_1.assert)(this.monitoringParameters.clientHandle > 0 && this.monitoringParameters.clientHandle !== 4294967295);
159
+ // If attributeId is EventNotifier then monitoring parameters need a filter.
160
+ // The filter must then either be DataChangeFilter, EventFilter or AggregateFilter.
161
+ // todo can be done in another way?
162
+ // todo implement AggregateFilter
163
+ // todo support DataChangeFilter
164
+ // todo support whereClause
165
+ if (this.itemToMonitor.attributeId === node_opcua_data_model_1.AttributeIds.EventNotifier) {
166
+ //
167
+ // see OPCUA Spec 1.02 part 4 page 65 : 5.12.1.4 Filter
168
+ // see part 4 page 130: 7.16.3 EventFilter
169
+ // part 3 page 11 : 4.6 Event Model
170
+ // To monitor for Events, the attributeId element of the ReadValueId structure is the
171
+ // the id of the EventNotifierAttribute
172
+ // OPC Unified Architecture 1.02, Part 4 5.12.1.2 Sampling interval page 64:
173
+ // "A Client shall define a sampling interval of 0 if it subscribes for Events."
174
+ // toDO
175
+ // note : the EventFilter is used when monitoring Events.
176
+ this.monitoringParameters.filter = this.monitoringParameters.filter || new node_opcua_service_filter_1.EventFilter({});
177
+ const filter = this.monitoringParameters.filter;
178
+ // istanbul ignore next
179
+ if (!filter) {
180
+ return { error: "Internal Error" };
181
+ }
182
+ if (filter.schema.name !== "EventFilter") {
183
+ return {
184
+ error: "Mismatch between attributeId and filter in monitoring parameters : " +
185
+ "Got a " +
186
+ filter.schema.name +
187
+ " but a EventFilter object is required " +
188
+ "when itemToMonitor.attributeId== AttributeIds.EventNotifier"
189
+ };
190
+ }
191
+ }
192
+ else if (this.itemToMonitor.attributeId === node_opcua_data_model_1.AttributeIds.Value) {
193
+ // the DataChangeFilter and the AggregateFilter are used when monitoring Variable Values
194
+ // The Value Attribute is used when monitoring Variables. Variable values are monitored for a change
195
+ // in value or a change in their status. The filters defined in this standard (see 7.16.2) and in Part 8 are
196
+ // used to determine if the value change is large enough to cause a Notification to be generated for the
197
+ // to do : check 'DataChangeFilter' && 'AggregateFilter'
198
+ }
199
+ else {
200
+ if (this.monitoringParameters.filter) {
201
+ return {
202
+ error: "Mismatch between attributeId and filter in monitoring parameters : " +
203
+ "no filter expected when attributeId is not Value or EventNotifier"
204
+ };
205
+ }
206
+ }
207
+ return {
208
+ itemToMonitor: this.itemToMonitor,
209
+ monitoringMode: this.monitoringMode,
210
+ requestedParameters: this.monitoringParameters
211
+ };
212
+ }
213
+ /**
214
+ * @internal
215
+ * @param monitoredItemResult
216
+ * @private
217
+ */
218
+ _applyResult(monitoredItemResult) {
219
+ this.statusCode = monitoredItemResult.statusCode;
220
+ /* istanbul ignore else */
221
+ if (monitoredItemResult.statusCode === node_opcua_status_code_1.StatusCodes.Good) {
222
+ this.result = monitoredItemResult;
223
+ this.monitoredItemId = monitoredItemResult.monitoredItemId;
224
+ this.monitoringParameters.samplingInterval = monitoredItemResult.revisedSamplingInterval;
225
+ this.monitoringParameters.queueSize = monitoredItemResult.revisedQueueSize;
226
+ this.filterResult = monitoredItemResult.filterResult || undefined;
227
+ }
228
+ // some PublishRequest with DataNotificationChange might have been sent by the server, before the monitored
229
+ // item has been fully initialized it is time to process now any pending notification that were put on hold.
230
+ if (this._pendingDataValue) {
231
+ const dataValues = this._pendingDataValue;
232
+ this._pendingDataValue = undefined;
233
+ setImmediate(() => {
234
+ dataValues.map((dataValue) => this._notify_value_change(dataValue));
235
+ });
236
+ }
237
+ if (this._pendingEvents) {
238
+ const events = this._pendingEvents;
239
+ this._pendingEvents = undefined;
240
+ setImmediate(() => {
241
+ events.map((event) => this._notify_event(event));
242
+ });
243
+ }
244
+ }
245
+ _before_create() {
246
+ const subscription = this.subscription;
247
+ subscription._add_monitored_item(this.monitoringParameters.clientHandle, this);
248
+ }
249
+ /**
250
+ * @internal
251
+ * @param monitoredItemResult
252
+ * @private
253
+ */
254
+ _after_create(monitoredItemResult) {
255
+ this._applyResult(monitoredItemResult);
256
+ if (this.statusCode === node_opcua_status_code_1.StatusCodes.Good) {
257
+ /**
258
+ * Notify the observers that the monitored item is now fully initialized.
259
+ * @event initialized
260
+ */
261
+ this.emit("initialized");
262
+ }
263
+ else {
264
+ /**
265
+ * Notify the observers that the monitored item has failed to initialize.
266
+ * @event err
267
+ * @param statusCode {StatusCode}
268
+ */
269
+ const err = new Error(monitoredItemResult.statusCode.toString());
270
+ this._terminate_and_emit(err);
271
+ }
272
+ }
273
+ _terminate_and_emit(err) {
274
+ if (this.statusCode.value === node_opcua_status_code_1.StatusCodes.Bad.value) {
275
+ return; // already terminated
276
+ }
277
+ if (err) {
278
+ this.emit("err", err.message);
279
+ }
280
+ (0, node_opcua_assert_1.assert)(!this._terminated);
281
+ this._terminated = true;
282
+ /**
283
+ * Notify the observer that this monitored item has been terminated.
284
+ * @event terminated
285
+ */
286
+ this.emit("terminated", err);
287
+ this.removeAllListeners();
288
+ this.statusCode = node_opcua_status_code_1.StatusCodes.Bad;
289
+ // also remove from subscription
290
+ const clientHandle = this.monitoringParameters.clientHandle;
291
+ delete this.subscription.monitoredItems[clientHandle];
292
+ }
293
+ }
294
+ exports.ClientMonitoredItemImpl = ClientMonitoredItemImpl;
295
+ // tslint:disable:no-var-requires
296
+ // tslint:disable:max-line-length
297
+ const thenify = require("thenify");
298
+ const opts = { multiArgs: false };
299
+ ClientMonitoredItemImpl.prototype.terminate = thenify.withCallback(ClientMonitoredItemImpl.prototype.terminate);
300
+ ClientMonitoredItemImpl.prototype.setMonitoringMode = thenify.withCallback(ClientMonitoredItemImpl.prototype.setMonitoringMode);
301
+ ClientMonitoredItemImpl.prototype.modify = thenify.withCallback(ClientMonitoredItemImpl.prototype.modify);
302
+ client_monitored_item_1.ClientMonitoredItem.create = (subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode = node_opcua_service_subscription_1.MonitoringMode.Reporting) => {
303
+ return (0, client_subscription_impl_1.ClientMonitoredItem_create)(subscription, itemToMonitor, monitoringParameters, timestampsToReturn, monitoringMode);
304
+ };
305
305
  //# sourceMappingURL=client_monitored_item_impl.js.map