node-opcua-client 2.166.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/alarms_and_conditions/client_alarm_tools.d.ts +1 -1
- package/dist/alarms_and_conditions/client_alarm_tools.js +2 -2
- package/dist/alarms_and_conditions/client_alarm_tools.js.map +1 -1
- package/dist/alarms_and_conditions/client_tools.d.ts +3 -0
- package/dist/alarms_and_conditions/client_tools.js +2 -2
- package/dist/alarms_and_conditions/client_tools.js.map +1 -1
- package/dist/client_base.d.ts +47 -40
- package/dist/client_base.js +5 -6
- package/dist/client_base.js.map +1 -1
- package/dist/client_monitored_item.d.ts +7 -7
- package/dist/client_monitored_item.js.map +1 -1
- package/dist/client_monitored_item_base.d.ts +12 -13
- package/dist/client_monitored_item_group.d.ts +5 -5
- package/dist/client_monitored_item_toolbox.d.ts +6 -7
- package/dist/client_monitored_item_toolbox.js.map +1 -1
- package/dist/client_session.d.ts +19 -23
- package/dist/client_session.js.map +1 -1
- package/dist/client_session_keepalive_manager.d.ts +1 -1
- package/dist/client_session_keepalive_manager.js +6 -6
- package/dist/client_session_keepalive_manager.js.map +1 -1
- package/dist/client_subscription.d.ts +11 -12
- package/dist/client_subscription.js.map +1 -1
- package/dist/client_utils.d.ts +3 -3
- package/dist/client_utils.js.map +1 -1
- package/dist/common.d.ts +12 -12
- package/dist/index.d.ts +26 -27
- package/dist/index.js +65 -66
- package/dist/index.js.map +1 -1
- package/dist/opcua_client.d.ts +17 -19
- package/dist/opcua_client.js.map +1 -1
- package/dist/private/client_base_impl.d.ts +19 -18
- package/dist/private/client_base_impl.js +220 -192
- package/dist/private/client_base_impl.js.map +1 -1
- package/dist/private/client_monitored_item_group_impl.d.ts +4 -5
- package/dist/private/client_monitored_item_group_impl.js +1 -1
- package/dist/private/client_monitored_item_group_impl.js.map +1 -1
- package/dist/private/client_monitored_item_impl.d.ts +9 -10
- package/dist/private/client_monitored_item_impl.js.map +1 -1
- package/dist/private/client_publish_engine.d.ts +3 -3
- package/dist/private/client_publish_engine.js +6 -7
- package/dist/private/client_publish_engine.js.map +1 -1
- package/dist/private/client_session_impl.d.ts +24 -25
- package/dist/private/client_session_impl.js +14 -10
- package/dist/private/client_session_impl.js.map +1 -1
- package/dist/private/client_subscription_impl.d.ts +10 -11
- package/dist/private/client_subscription_impl.js +12 -11
- package/dist/private/client_subscription_impl.js.map +1 -1
- package/dist/private/i_private_client.d.ts +7 -7
- package/dist/private/opcua_client_impl.d.ts +12 -9
- package/dist/private/opcua_client_impl.js +58 -48
- package/dist/private/opcua_client_impl.js.map +1 -1
- package/dist/private/performance.js.map +1 -1
- package/dist/private/reconnection/client_publish_engine_reconnection.d.ts +1 -1
- package/dist/private/reconnection/client_publish_engine_reconnection.js +54 -43
- package/dist/private/reconnection/client_publish_engine_reconnection.js.map +1 -1
- package/dist/private/reconnection/client_reconnection.d.ts +1 -1
- package/dist/private/reconnection/client_subscription_reconnection.d.ts +1 -1
- package/dist/private/reconnection/client_subscription_reconnection.js +2 -2
- package/dist/private/reconnection/client_subscription_reconnection.js.map +1 -1
- package/dist/private/reconnection/reconnection.d.ts +4 -4
- package/dist/private/reconnection/reconnection.js +200 -281
- package/dist/private/reconnection/reconnection.js.map +1 -1
- package/dist/tools/findservers.d.ts +7 -2
- package/dist/tools/findservers.js +41 -53
- package/dist/tools/findservers.js.map +1 -1
- package/dist/tools/read_history_server_capabilities.d.ts +1 -1
- package/dist/tools/read_history_server_capabilities.js +9 -8
- package/dist/tools/read_history_server_capabilities.js.map +1 -1
- package/dist/user_identity_info.d.ts +1 -1
- package/dist/verify.js.map +1 -1
- package/package.json +45 -45
- package/source/alarms_and_conditions/client_alarm_tools.ts +14 -8
- package/source/alarms_and_conditions/client_tools.ts +7 -6
- package/source/client_base.ts +93 -79
- package/source/client_monitored_item.ts +7 -8
- package/source/client_monitored_item_base.ts +12 -14
- package/source/client_monitored_item_group.ts +5 -5
- package/source/client_monitored_item_toolbox.ts +13 -14
- package/source/client_session.ts +37 -40
- package/source/client_session_keepalive_manager.ts +7 -10
- package/source/client_subscription.ts +11 -12
- package/source/client_utils.ts +6 -6
- package/source/common.ts +12 -12
- package/source/index.ts +44 -40
- package/source/opcua_client.ts +24 -23
- package/source/private/client_base_impl.ts +329 -290
- package/source/private/client_monitored_item_group_impl.ts +10 -14
- package/source/private/client_monitored_item_impl.ts +17 -17
- package/source/private/client_publish_engine.ts +11 -12
- package/source/private/client_session_impl.ts +85 -82
- package/source/private/client_subscription_impl.ts +42 -41
- package/source/private/i_private_client.ts +8 -8
- package/source/private/opcua_client_impl.ts +118 -97
- package/source/private/performance.ts +2 -3
- package/source/private/reconnection/client_publish_engine_reconnection.ts +76 -68
- package/source/private/reconnection/client_reconnection.ts +1 -1
- package/source/private/reconnection/client_subscription_reconnection.ts +16 -13
- package/source/private/reconnection/reconnection.ts +307 -301
- package/source/tools/findservers.ts +43 -62
- package/source/tools/read_history_server_capabilities.ts +20 -22
- package/source/user_identity_info.ts +5 -5
- package/source/verify.ts +25 -25
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
import { types } from "util";
|
|
2
|
-
import async from "async";
|
|
3
1
|
import chalk from "chalk";
|
|
4
2
|
import assert from "node-opcua-assert";
|
|
5
3
|
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
|
|
6
4
|
import { StatusCodes } from "node-opcua-status-code";
|
|
7
|
-
import { RepublishRequest, RepublishResponse } from "node-opcua-types";
|
|
8
|
-
import {
|
|
9
|
-
import { ClientSessionImpl } from "../client_session_impl";
|
|
10
|
-
import { ClientSubscriptionImpl } from "../client_subscription_impl";
|
|
11
|
-
import { ClientSidePublishEngine } from "../client_publish_engine";
|
|
5
|
+
import { RepublishRequest, type RepublishResponse } from "node-opcua-types";
|
|
6
|
+
import type { ClientSidePublishEngine } from "../client_publish_engine";
|
|
7
|
+
import type { ClientSessionImpl } from "../client_session_impl";
|
|
8
|
+
import type { ClientSubscriptionImpl } from "../client_subscription_impl";
|
|
12
9
|
import { recreateSubscriptionAndMonitoredItem } from "./client_subscription_reconnection";
|
|
13
10
|
import { _shouldNotContinue2 } from "./reconnection";
|
|
14
11
|
|
|
15
12
|
const debugLog = make_debugLog("RECONNECTION");
|
|
16
13
|
const doDebug = checkDebugFlag("RECONNECTION");
|
|
17
14
|
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
subscription: ClientSubscriptionImpl
|
|
21
|
-
|
|
22
|
-
) {
|
|
23
|
-
|
|
24
|
-
let isDone = false;
|
|
25
|
-
const session = engine.session as ClientSessionImpl;
|
|
26
|
-
|
|
27
|
-
const sendRepublishFunc = (callback2: (err?: Error) => void) => {
|
|
28
|
-
assert(isFinite(subscription.lastSequenceNumber) && subscription.lastSequenceNumber + 1 >= 0);
|
|
15
|
+
function _sendRepublish(
|
|
16
|
+
session: ClientSessionImpl,
|
|
17
|
+
subscription: ClientSubscriptionImpl
|
|
18
|
+
): Promise<{ isDone: boolean }> {
|
|
19
|
+
return new Promise<{ isDone: boolean }>((resolve, reject) => {
|
|
20
|
+
assert(Number.isFinite(subscription.lastSequenceNumber) && subscription.lastSequenceNumber + 1 >= 0);
|
|
29
21
|
|
|
30
22
|
const request = new RepublishRequest({
|
|
31
23
|
retransmitSequenceNumber: subscription.lastSequenceNumber + 1,
|
|
@@ -43,64 +35,76 @@ function _republish(
|
|
|
43
35
|
);
|
|
44
36
|
}
|
|
45
37
|
|
|
46
|
-
if (!session || session
|
|
38
|
+
if (!session || session._closeEventHasBeenEmitted) {
|
|
47
39
|
debugLog("ClientPublishEngine#_republish aborted ");
|
|
48
|
-
|
|
49
|
-
isDone = true;
|
|
50
|
-
return callback2();
|
|
40
|
+
return resolve({ isDone: true });
|
|
51
41
|
}
|
|
42
|
+
|
|
52
43
|
session.republish(request, (err: Error | null, response?: RepublishResponse) => {
|
|
53
|
-
|
|
44
|
+
if (!response) {
|
|
45
|
+
reject(err);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const statusCode = err ? StatusCodes.Bad : response.responseHeader.serviceResult;
|
|
54
49
|
if (!err && (statusCode.equals(StatusCodes.Good) || statusCode.equals(StatusCodes.BadMessageNotAvailable))) {
|
|
55
|
-
// reprocess notification message
|
|
50
|
+
// reprocess notification message and keep going
|
|
56
51
|
if (statusCode.equals(StatusCodes.Good)) {
|
|
57
|
-
subscription.onNotificationMessage(response
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
if (!err) {
|
|
61
|
-
err = new Error(response!.responseHeader.serviceResult.toString());
|
|
52
|
+
subscription.onNotificationMessage(response.notificationMessage);
|
|
62
53
|
}
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
return resolve({ isDone: false });
|
|
55
|
+
}
|
|
56
|
+
if (!err) {
|
|
57
|
+
err = new Error(response.responseHeader.serviceResult.toString());
|
|
65
58
|
}
|
|
66
|
-
|
|
59
|
+
debugLog(" _send_republish ends with ", err.message);
|
|
60
|
+
reject(err);
|
|
67
61
|
});
|
|
68
|
-
};
|
|
62
|
+
});
|
|
63
|
+
}
|
|
69
64
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
debugLog("nbPendingPublishRequest = ", engine.nbPendingPublishRequests);
|
|
76
|
-
debugLog(" _republish ends with ", err ? err.message : "null");
|
|
77
|
-
callback(err!);
|
|
78
|
-
}) as any // Wait for @type/async bug to be fixed !
|
|
79
|
-
);
|
|
80
|
-
};
|
|
65
|
+
async function _republish(
|
|
66
|
+
engine: ClientSidePublishEngine,
|
|
67
|
+
subscription: ClientSubscriptionImpl
|
|
68
|
+
): Promise<void> {
|
|
69
|
+
const session = engine.session as ClientSessionImpl;
|
|
81
70
|
|
|
82
|
-
|
|
71
|
+
// loop until done (all messages re-published or error)
|
|
72
|
+
let isDone = false;
|
|
73
|
+
while (!isDone) {
|
|
74
|
+
// yield to event loop before each iteration
|
|
75
|
+
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
76
|
+
const result = await _sendRepublish(session, subscription);
|
|
77
|
+
isDone = result.isDone;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
debugLog("nbPendingPublishRequest = ", engine.nbPendingPublishRequests);
|
|
81
|
+
debugLog(" _republish ends with ", "null");
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
function __askSubscriptionRepublish(
|
|
84
|
+
async function __askSubscriptionRepublish(
|
|
86
85
|
engine: ClientSidePublishEngine,
|
|
87
|
-
subscription: ClientSubscriptionImpl
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
subscription: ClientSubscriptionImpl
|
|
87
|
+
): Promise<void> {
|
|
88
|
+
try {
|
|
89
|
+
await _republish(engine, subscription);
|
|
90
|
+
} catch (err) {
|
|
92
91
|
// prettier-ignore
|
|
93
|
-
{
|
|
92
|
+
{
|
|
93
|
+
const _err = _shouldNotContinue2(subscription);
|
|
94
|
+
if (_err) {
|
|
95
|
+
throw _err;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
94
98
|
|
|
95
|
-
|
|
99
|
+
const error = err as Error;
|
|
96
100
|
|
|
97
|
-
debugLog("__askSubscriptionRepublish--------------------- err =",
|
|
101
|
+
debugLog("__askSubscriptionRepublish--------------------- err =", error.message);
|
|
98
102
|
|
|
99
|
-
if (
|
|
103
|
+
if (error.message.match(/BadSessionInvalid/)) {
|
|
100
104
|
// _republish failed because session is not valid anymore on server side.
|
|
101
|
-
|
|
105
|
+
throw error;
|
|
102
106
|
}
|
|
103
|
-
if (
|
|
107
|
+
if (error.message.match(/SubscriptionIdInvalid/)) {
|
|
104
108
|
// _republish failed because subscriptionId is not valid anymore on server side.
|
|
105
109
|
//
|
|
106
110
|
// This could happen when the subscription has timed out and has been deleted by server
|
|
@@ -113,13 +117,18 @@ function __askSubscriptionRepublish(
|
|
|
113
117
|
debugLog(
|
|
114
118
|
chalk.bgWhite.red("__askSubscriptionRepublish failed " + " subscriptionId is not valid anymore on server side.")
|
|
115
119
|
);
|
|
116
|
-
|
|
120
|
+
await recreateSubscriptionAndMonitoredItem(subscription);
|
|
121
|
+
return;
|
|
117
122
|
}
|
|
118
|
-
if (
|
|
123
|
+
if (error.message.match(/|MessageNotAvailable/)) {
|
|
119
124
|
// start engine and start monitoring
|
|
120
125
|
}
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
}
|
|
127
|
+
// check after successful republish too
|
|
128
|
+
const _err = _shouldNotContinue2(subscription);
|
|
129
|
+
if (_err) {
|
|
130
|
+
throw _err;
|
|
131
|
+
}
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
export function republish(engine: ClientSidePublishEngine, callback: () => void): void {
|
|
@@ -134,13 +143,12 @@ export function republish(engine: ClientSidePublishEngine, callback: () => void)
|
|
|
134
143
|
* call Republish continuously until all Notification messages of
|
|
135
144
|
* un-acknowledged notifications are reprocessed.
|
|
136
145
|
*/
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
__askSubscriptionRepublish(engine, subscription, innerCallback);
|
|
146
|
+
const processAll = async () => {
|
|
147
|
+
const entries = Object.entries(engine.subscriptionMap);
|
|
148
|
+
for (const [_subscriptionId, subscription] of entries) {
|
|
149
|
+
await __askSubscriptionRepublish(engine, subscription as ClientSubscriptionImpl);
|
|
150
|
+
}
|
|
143
151
|
};
|
|
144
152
|
|
|
145
|
-
|
|
153
|
+
processAll().then(() => callback()).catch(() => callback());
|
|
146
154
|
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { promisify } from "node:util";
|
|
2
2
|
import assert from "node-opcua-assert";
|
|
3
3
|
import { TimestampsToReturn } from "node-opcua-data-value";
|
|
4
|
-
import {
|
|
5
|
-
import { MonitoredItemCreateRequestOptions, CreateMonitoredItemsRequest, CreateMonitoredItemsResponse } from "node-opcua-types";
|
|
6
|
-
|
|
4
|
+
import { checkDebugFlag, make_debugLog, make_warningLog } from "node-opcua-debug";
|
|
7
5
|
import {
|
|
8
|
-
IBasicSessionReadAsync,
|
|
9
|
-
IBasicSessionWithSubscription,
|
|
10
6
|
createMonitoredItemsLimit,
|
|
7
|
+
type IBasicSessionReadAsync,
|
|
8
|
+
type IBasicSessionWithSubscription,
|
|
11
9
|
readOperationLimits
|
|
12
10
|
} from "node-opcua-pseudo-session";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
import {
|
|
12
|
+
CreateMonitoredItemsRequest,
|
|
13
|
+
type CreateMonitoredItemsResponse,
|
|
14
|
+
type MonitoredItemCreateRequestOptions
|
|
15
|
+
} from "node-opcua-types";
|
|
16
|
+
import type { ClientSubscription } from "../../client_subscription";
|
|
17
|
+
import type { ClientMonitoredItemImpl } from "../client_monitored_item_impl";
|
|
18
|
+
import { __create_subscription, type ClientSubscriptionImpl, TERMINATED_SUBSCRIPTION_ID } from "../client_subscription_impl";
|
|
16
19
|
import { _shouldNotContinue } from "./reconnection";
|
|
17
20
|
|
|
18
21
|
const debugLog = make_debugLog("RECONNECTION");
|
|
@@ -33,7 +36,7 @@ async function createMonitoredItemsAndRespectOperationalLimits(
|
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
async function adjustMonitoredItemNodeIds(subscription: ClientSubscription, oldMonitoredItems: any) {
|
|
36
|
-
// to Do
|
|
39
|
+
// to Do
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
42
|
* utility function to recreate new subscription
|
|
@@ -56,7 +59,9 @@ export async function recreateSubscriptionAndMonitoredItem(_subscription: Client
|
|
|
56
59
|
await promisify(__create_subscription)(subscription);
|
|
57
60
|
|
|
58
61
|
const _err = _shouldNotContinue(subscription.session);
|
|
59
|
-
if (_err) {
|
|
62
|
+
if (_err) {
|
|
63
|
+
throw _err;
|
|
64
|
+
}
|
|
60
65
|
|
|
61
66
|
const test = subscription.publishEngine.getSubscription(subscription.subscriptionId);
|
|
62
67
|
|
|
@@ -89,9 +94,7 @@ export async function recreateSubscriptionAndMonitoredItem(_subscription: Client
|
|
|
89
94
|
|
|
90
95
|
debugLog("Recreating ", itemsToCreate.length, " monitored items");
|
|
91
96
|
|
|
92
|
-
const response = await createMonitoredItemsAndRespectOperationalLimits(
|
|
93
|
-
session,
|
|
94
|
-
createMonitorItemsRequest);
|
|
97
|
+
const response = await createMonitoredItemsAndRespectOperationalLimits(session, createMonitorItemsRequest);
|
|
95
98
|
const monitoredItemResults = response.results || [];
|
|
96
99
|
|
|
97
100
|
let _errCount = 0;
|