node-opcua-client 2.77.0 → 2.79.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/client_monitored_item_group.d.ts +3 -0
- package/dist/client_monitored_item_group.js.map +1 -1
- package/dist/client_session.d.ts +46 -2
- package/dist/client_session.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/opcua_client.d.ts +7 -21
- package/dist/opcua_client.js.map +1 -1
- package/dist/private/client_base_impl.d.ts +2 -1
- package/dist/private/client_base_impl.js +1 -1
- package/dist/private/client_base_impl.js.map +1 -1
- package/dist/private/client_monitored_item_impl.js +4 -4
- package/dist/private/client_monitored_item_impl.js.map +1 -1
- package/dist/private/client_session_impl.d.ts +10 -2
- package/dist/private/client_session_impl.js +31 -2
- package/dist/private/client_session_impl.js.map +1 -1
- package/dist/private/i_private_client.d.ts +2 -1
- package/dist/private/opcua_client_impl.d.ts +7 -5
- package/dist/private/opcua_client_impl.js +24 -21
- package/dist/private/opcua_client_impl.js.map +1 -1
- package/dist/reconnection.js +2 -2
- package/dist/reconnection.js.map +1 -1
- package/dist/user_identity_info.d.ts +1 -0
- package/dist/user_identity_info.js +3 -0
- package/dist/user_identity_info.js.map +1 -0
- package/package.json +31 -31
- package/source/client_monitored_item_group.ts +4 -0
- package/source/client_session.ts +97 -15
- package/source/index.ts +1 -0
- package/source/opcua_client.ts +5 -20
- package/source/private/client_base_impl.ts +6 -1
- package/source/private/client_monitored_item_impl.ts +10 -4
- package/source/private/client_session_impl.ts +73 -3
- package/source/private/i_private_client.ts +6 -1
- package/source/private/opcua_client_impl.ts +64 -54
- package/source/reconnection.ts +32 -23
- package/source/user_identity_info.ts +6 -0
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
UserNameIdentityToken,
|
|
39
39
|
X509IdentityToken
|
|
40
40
|
} from "node-opcua-service-session";
|
|
41
|
-
import { StatusCodes } from "node-opcua-status-code";
|
|
41
|
+
import { CallbackT, StatusCode, StatusCodes } from "node-opcua-status-code";
|
|
42
42
|
import { ErrorCallback, Callback } from "node-opcua-status-code";
|
|
43
43
|
|
|
44
44
|
import { SignatureData, SignatureDataOptions, UserIdentityToken } from "node-opcua-types";
|
|
@@ -48,16 +48,14 @@ import { ClientSession } from "../client_session";
|
|
|
48
48
|
import { ClientSubscription, ClientSubscriptionOptions } from "../client_subscription";
|
|
49
49
|
import { Response } from "../common";
|
|
50
50
|
import {
|
|
51
|
-
AnonymousIdentity,
|
|
52
51
|
OPCUAClient,
|
|
53
52
|
OPCUAClientOptions,
|
|
54
|
-
UserIdentityInfo,
|
|
55
|
-
UserIdentityInfoUserName,
|
|
56
|
-
UserIdentityInfoX509,
|
|
57
53
|
WithSessionFuncP,
|
|
58
54
|
WithSubscriptionFuncP,
|
|
59
55
|
EndpointWithUserIdentity
|
|
60
56
|
} from "../opcua_client";
|
|
57
|
+
import { AnonymousIdentity, UserIdentityInfo, UserIdentityInfoUserName, UserIdentityInfoX509 } from "../user_identity_info";
|
|
58
|
+
|
|
61
59
|
import { repair_client_sessions } from "../reconnection";
|
|
62
60
|
import { ClientBaseImpl } from "./client_base_impl";
|
|
63
61
|
import { ClientSessionImpl } from "./client_session_impl";
|
|
@@ -332,7 +330,6 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
|
|
|
332
330
|
private endpointMustExist: boolean;
|
|
333
331
|
private requestedSessionTimeout: number;
|
|
334
332
|
private ___sessionName_counter: number;
|
|
335
|
-
private userIdentityInfo: UserIdentityInfo;
|
|
336
333
|
private serverUri?: string;
|
|
337
334
|
private clientNonce?: Nonce;
|
|
338
335
|
|
|
@@ -358,7 +355,6 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
|
|
|
358
355
|
this.requestedSessionTimeout = options.requestedSessionTimeout || 60000; // 1 minute
|
|
359
356
|
|
|
360
357
|
this.___sessionName_counter = 0;
|
|
361
|
-
this.userIdentityInfo = { type: UserTokenType.Anonymous };
|
|
362
358
|
this.endpoint = undefined;
|
|
363
359
|
}
|
|
364
360
|
|
|
@@ -396,8 +392,6 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
|
|
|
396
392
|
const userIdentityInfo = args[0] || { type: UserTokenType.Anonymous };
|
|
397
393
|
const callback = args[1];
|
|
398
394
|
|
|
399
|
-
this.userIdentityInfo = userIdentityInfo;
|
|
400
|
-
|
|
401
395
|
assert(typeof callback === "function");
|
|
402
396
|
|
|
403
397
|
this._createSession((err: Error | null, session?: ClientSession) => {
|
|
@@ -411,9 +405,13 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
|
|
|
411
405
|
|
|
412
406
|
this._addSession(session as ClientSessionImpl);
|
|
413
407
|
|
|
414
|
-
this._activateSession(
|
|
415
|
-
|
|
416
|
-
|
|
408
|
+
this._activateSession(
|
|
409
|
+
session as ClientSessionImpl,
|
|
410
|
+
userIdentityInfo,
|
|
411
|
+
(err1: Error | null, session2?: ClientSessionImpl) => {
|
|
412
|
+
callback(err1, session2);
|
|
413
|
+
}
|
|
414
|
+
);
|
|
417
415
|
}
|
|
418
416
|
});
|
|
419
417
|
}
|
|
@@ -460,26 +458,19 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
|
|
|
460
458
|
* @param userIdentityInfo
|
|
461
459
|
* @param callback
|
|
462
460
|
* @async
|
|
461
|
+
* @deprecated : use session.changeUser instead
|
|
463
462
|
*/
|
|
464
|
-
public async changeSessionIdentity(session: ClientSession, userIdentityInfo: UserIdentityInfo): Promise<
|
|
465
|
-
public changeSessionIdentity(session: ClientSession, userIdentityInfo: UserIdentityInfo, callback:
|
|
466
|
-
/**
|
|
467
|
-
* @internal
|
|
468
|
-
* @param args
|
|
469
|
-
*/
|
|
463
|
+
public async changeSessionIdentity(session: ClientSession, userIdentityInfo: UserIdentityInfo): Promise<StatusCode>;
|
|
464
|
+
public changeSessionIdentity(session: ClientSession, userIdentityInfo: UserIdentityInfo, callback: CallbackT<StatusCode>): void;
|
|
470
465
|
public changeSessionIdentity(...args: any[]): any {
|
|
466
|
+
warningLog(
|
|
467
|
+
"[NODE-OPCUA-W27] OPCUAClient.changeSessionIdentity(session,...) is deprecated use ClientSession.changeUser instead"
|
|
468
|
+
);
|
|
471
469
|
const session = args[0] as ClientSessionImpl;
|
|
472
470
|
const userIdentityInfo = args[1] as UserIdentityInfo;
|
|
473
471
|
const callback = args[2];
|
|
474
|
-
|
|
475
472
|
assert(typeof callback === "function");
|
|
476
|
-
|
|
477
|
-
const old_userIdentity = this.userIdentityInfo;
|
|
478
|
-
this.userIdentityInfo = userIdentityInfo;
|
|
479
|
-
|
|
480
|
-
this._activateSession(session as ClientSessionImpl, (err1: Error | null, session1?: ClientSessionImpl) => {
|
|
481
|
-
callback(err1 ? err1 : undefined);
|
|
482
|
-
});
|
|
473
|
+
session.changeUser(userIdentityInfo, callback);
|
|
483
474
|
}
|
|
484
475
|
|
|
485
476
|
/**
|
|
@@ -706,19 +697,29 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
|
|
|
706
697
|
typeof connectionPoint === "string" ? { type: UserTokenType.Anonymous } : connectionPoint.userIdentity;
|
|
707
698
|
|
|
708
699
|
await this.connect(endpointUrl);
|
|
709
|
-
const session = await this.createSession2(userIdentity);
|
|
710
700
|
|
|
711
|
-
|
|
701
|
+
this.on("backoff", (count, delay) => {
|
|
702
|
+
warningLog("cannot connect to ", endpointUrl, "attempt #" + count, " retrying in ", delay);
|
|
703
|
+
});
|
|
704
|
+
|
|
712
705
|
try {
|
|
713
|
-
|
|
706
|
+
const session = await this.createSession2(userIdentity);
|
|
707
|
+
let result;
|
|
708
|
+
try {
|
|
709
|
+
result = await func(session);
|
|
710
|
+
return result;
|
|
711
|
+
} catch (err) {
|
|
712
|
+
errorLog(err);
|
|
713
|
+
throw err;
|
|
714
|
+
} finally {
|
|
715
|
+
await session.close();
|
|
716
|
+
}
|
|
714
717
|
} catch (err) {
|
|
715
|
-
errorLog(err);
|
|
718
|
+
errorLog((err as Error).message);
|
|
716
719
|
throw err;
|
|
717
720
|
} finally {
|
|
718
|
-
await session.close();
|
|
719
721
|
await this.disconnect();
|
|
720
722
|
}
|
|
721
|
-
return result;
|
|
722
723
|
}
|
|
723
724
|
|
|
724
725
|
public async withSubscriptionAsync(
|
|
@@ -771,29 +772,33 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
|
|
|
771
772
|
|
|
772
773
|
debugLog("OPCUAClientImpl#reactivateSession");
|
|
773
774
|
|
|
774
|
-
this._activateSession(
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
775
|
+
this._activateSession(
|
|
776
|
+
internalSession,
|
|
777
|
+
internalSession.userIdentityInfo!,
|
|
778
|
+
(err: Error | null /*, newSession?: ClientSessionImpl*/) => {
|
|
779
|
+
if (!err) {
|
|
780
|
+
if (old_client !== this) {
|
|
781
|
+
// remove session from old client:
|
|
782
|
+
if (old_client) {
|
|
783
|
+
old_client._removeSession(internalSession);
|
|
784
|
+
assert(old_client._sessions.indexOf(internalSession) === -1);
|
|
785
|
+
}
|
|
782
786
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
787
|
+
this._addSession(internalSession);
|
|
788
|
+
assert(internalSession._client === this);
|
|
789
|
+
assert(!internalSession._closed, "session should not vbe closed");
|
|
790
|
+
assert(this._sessions.indexOf(internalSession) !== -1);
|
|
791
|
+
}
|
|
792
|
+
callback!();
|
|
793
|
+
} else {
|
|
794
|
+
// istanbul ignore next
|
|
795
|
+
if (doDebug) {
|
|
796
|
+
debugLog(chalk.red.bgWhite("reactivateSession has failed !"), err.message);
|
|
797
|
+
}
|
|
798
|
+
callback!(err);
|
|
793
799
|
}
|
|
794
|
-
callback!(err);
|
|
795
800
|
}
|
|
796
|
-
|
|
801
|
+
);
|
|
797
802
|
}
|
|
798
803
|
|
|
799
804
|
/**
|
|
@@ -939,7 +944,11 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
|
|
|
939
944
|
* @internal
|
|
940
945
|
* @private
|
|
941
946
|
*/
|
|
942
|
-
public _activateSession(
|
|
947
|
+
public _activateSession(
|
|
948
|
+
session: ClientSessionImpl,
|
|
949
|
+
userIdentityInfo: UserIdentityInfo,
|
|
950
|
+
callback: (err: Error | null, session?: ClientSessionImpl) => void
|
|
951
|
+
): void {
|
|
943
952
|
// see OPCUA Part 4 - $7.35
|
|
944
953
|
assert(typeof callback === "function");
|
|
945
954
|
|
|
@@ -968,7 +977,7 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
|
|
|
968
977
|
serverNonce: serverNonce! // please check this !
|
|
969
978
|
};
|
|
970
979
|
|
|
971
|
-
this.createUserIdentityToken(context,
|
|
980
|
+
this.createUserIdentityToken(context, userIdentityInfo, (err: Error | null, data?: TokenAndSignature | null) => {
|
|
972
981
|
if (err) {
|
|
973
982
|
session._client = _old_client;
|
|
974
983
|
return callback(err);
|
|
@@ -1044,6 +1053,7 @@ export class OPCUAClientImpl extends ClientBaseImpl implements OPCUAClient {
|
|
|
1044
1053
|
if (this.keepSessionAlive) {
|
|
1045
1054
|
session.startKeepAliveManager();
|
|
1046
1055
|
}
|
|
1056
|
+
session.userIdentityInfo = userIdentityInfo;
|
|
1047
1057
|
return callback(null, session);
|
|
1048
1058
|
} else {
|
|
1049
1059
|
// restore client
|
package/source/reconnection.ts
CHANGED
|
@@ -237,28 +237,32 @@ function repair_client_session_by_recreating_a_new_session(
|
|
|
237
237
|
}
|
|
238
238
|
debugLog(chalk.bgWhite.red(" => activating a new session ...."));
|
|
239
239
|
|
|
240
|
-
client._activateSession(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
240
|
+
client._activateSession(
|
|
241
|
+
newSession,
|
|
242
|
+
newSession.userIdentityInfo!,
|
|
243
|
+
(err: Error | null, session1?: ClientSessionImpl) => {
|
|
244
|
+
debugLog(chalk.bgWhite.cyan(" => activating a new session .... Done err=", err ? err.message : "null"));
|
|
245
|
+
if (err) {
|
|
246
|
+
debugLog(
|
|
247
|
+
chalk.bgWhite.cyan(
|
|
248
|
+
"reactivation of the new session has failed: let be smart and close it before failing this repair attempt"
|
|
249
|
+
)
|
|
250
|
+
);
|
|
251
|
+
// but just on the server side, not on the client side
|
|
252
|
+
const closeSessionRequest = new CloseSessionRequest({
|
|
253
|
+
deleteSubscriptions: true
|
|
254
|
+
});
|
|
255
|
+
session.performMessageTransaction(closeSessionRequest, (err2?: Error | null) => {
|
|
256
|
+
if (err2) {
|
|
257
|
+
warningLog("closing session", err2.message);
|
|
258
|
+
}
|
|
259
|
+
innerCallback(err);
|
|
260
|
+
});
|
|
261
|
+
} else {
|
|
262
|
+
innerCallback(err ? err : undefined);
|
|
263
|
+
}
|
|
260
264
|
}
|
|
261
|
-
|
|
265
|
+
);
|
|
262
266
|
},
|
|
263
267
|
|
|
264
268
|
function attempt_subscription_transfer(innerCallback: ErrorCallback) {
|
|
@@ -415,7 +419,7 @@ function _repair_client_session(client: IClientBase, session: ClientSessionImpl,
|
|
|
415
419
|
debugLog(chalk.yellow(" TRYING TO REACTIVATE EXISTING SESSION"), session.sessionId.toString());
|
|
416
420
|
debugLog(" SubscriptionIds :", session.getPublishEngine().getSubscriptionIds());
|
|
417
421
|
}
|
|
418
|
-
client._activateSession(session, (err: Error | null, session2?: ClientSessionImpl) => {
|
|
422
|
+
client._activateSession(session, session.userIdentityInfo!, (err: Error | null, session2?: ClientSessionImpl) => {
|
|
419
423
|
//
|
|
420
424
|
// Note: current limitation :
|
|
421
425
|
// - The reconnection doesn't work yet, if connection break is caused by a server that crashes and restarts.
|
|
@@ -454,7 +458,12 @@ export function repair_client_session(client: IClientBase, session: ClientSessio
|
|
|
454
458
|
_repair_client_session(client, session, (err) => {
|
|
455
459
|
privateSession._reconnecting.reconnecting = false;
|
|
456
460
|
if (err) {
|
|
457
|
-
errorLog(
|
|
461
|
+
errorLog(
|
|
462
|
+
chalk.red("session restoration has failed! err ="),
|
|
463
|
+
err.message,
|
|
464
|
+
session.sessionId.toString(),
|
|
465
|
+
" => Let's retry"
|
|
466
|
+
);
|
|
458
467
|
setTimeout(() => {
|
|
459
468
|
_repair_client_session(client, session, callback);
|
|
460
469
|
}, 2000);
|