node-opcua-client 2.97.0 → 2.98.1
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.d.ts +49 -49
- package/dist/alarms_and_conditions/client_alarm.js +109 -109
- package/dist/alarms_and_conditions/client_alarm_list.d.ts +25 -25
- package/dist/alarms_and_conditions/client_alarm_list.js +97 -97
- package/dist/alarms_and_conditions/client_alarm_tools.d.ts +4 -4
- package/dist/alarms_and_conditions/client_alarm_tools.js +156 -156
- package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.d.ts +18 -18
- package/dist/alarms_and_conditions/client_alarm_tools_acknowledge_all_conditions.js +192 -192
- package/dist/alarms_and_conditions/client_alarm_tools_dump_event.d.ts +9 -9
- package/dist/alarms_and_conditions/client_alarm_tools_dump_event.js +72 -72
- package/dist/alarms_and_conditions/client_alarm_tools_dump_event.js.map +1 -1
- package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.d.ts +3 -3
- package/dist/alarms_and_conditions/client_alarm_tools_extractConditionFields.js +118 -118
- package/dist/alarms_and_conditions/client_tools.d.ts +7 -7
- package/dist/alarms_and_conditions/client_tools.js +179 -179
- package/dist/client_base.d.ts +277 -277
- package/dist/client_base.js +14 -14
- package/dist/client_base.js.map +1 -1
- package/dist/client_monitored_item.d.ts +21 -21
- package/dist/client_monitored_item.js +11 -11
- package/dist/client_monitored_item_base.d.ts +39 -39
- package/dist/client_monitored_item_base.js +2 -2
- package/dist/client_monitored_item_group.d.ts +21 -21
- package/dist/client_monitored_item_group.js +13 -13
- package/dist/client_monitored_item_toolbox.d.ts +15 -15
- package/dist/client_monitored_item_toolbox.js +116 -116
- package/dist/client_session.d.ts +529 -529
- package/dist/client_session.js +10 -10
- package/dist/client_session_keepalive_manager.d.ts +34 -34
- package/dist/client_session_keepalive_manager.js +149 -149
- package/dist/client_subscription.d.ts +241 -241
- package/dist/client_subscription.js +14 -14
- package/dist/client_subscription.js.map +1 -1
- package/dist/client_utils.d.ts +22 -22
- package/dist/client_utils.js +87 -87
- package/dist/common.d.ts +17 -17
- package/dist/common.js +5 -5
- package/dist/index.d.ts +56 -56
- package/dist/index.js +94 -94
- package/dist/opcua_client.d.ts +118 -118
- package/dist/opcua_client.js +33 -33
- package/dist/private/client_base_impl.d.ts +160 -160
- package/dist/private/client_base_impl.js +1348 -1348
- package/dist/private/client_monitored_item_base_impl.d.ts +3 -3
- package/dist/private/client_monitored_item_base_impl.js +4 -4
- package/dist/private/client_monitored_item_group_impl.d.ts +53 -53
- package/dist/private/client_monitored_item_group_impl.js +159 -159
- package/dist/private/client_monitored_item_impl.d.ts +93 -93
- package/dist/private/client_monitored_item_impl.js +304 -304
- package/dist/private/client_publish_engine.d.ts +62 -62
- package/dist/private/client_publish_engine.js +408 -408
- package/dist/private/client_publish_engine.js.map +1 -1
- package/dist/private/client_session_impl.d.ts +631 -631
- package/dist/private/client_session_impl.js +1348 -1348
- package/dist/private/client_subscription_impl.d.ts +93 -93
- package/dist/private/client_subscription_impl.js +763 -763
- package/dist/private/i_private_client.d.ts +21 -21
- package/dist/private/i_private_client.js +2 -2
- package/dist/private/opcua_client_impl.d.ts +166 -166
- package/dist/private/opcua_client_impl.js +1000 -1000
- package/dist/private/opcua_client_impl.js.map +1 -1
- package/dist/private/performance.d.ts +1 -1
- package/dist/private/performance.js +18 -18
- package/dist/reconnection.d.ts +9 -9
- package/dist/reconnection.js +381 -381
- package/dist/tools/findservers.d.ts +20 -20
- package/dist/tools/findservers.js +61 -61
- package/dist/tools/read_history_server_capabilities.d.ts +6 -6
- package/dist/tools/read_history_server_capabilities.js +98 -98
- package/dist/user_identity_info.d.ts +1 -1
- package/dist/user_identity_info.js +2 -2
- package/dist/verify.d.ts +5 -5
- package/dist/verify.js +134 -134
- package/package.json +49 -45
- package/source/alarms_and_conditions/client_alarm_tools_dump_event.ts +1 -1
- package/.nycrc.json +0 -14
- package/test_helpers/create_certificates.js +0 -1
- package/typedoc.js +0 -20
package/dist/client_session.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module node-opcua-client
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ExtensionObject = exports.ExtraDataTypeManager = void 0;
|
|
7
|
-
var node_opcua_client_dynamic_extension_object_1 = require("node-opcua-client-dynamic-extension-object");
|
|
8
|
-
Object.defineProperty(exports, "ExtraDataTypeManager", { enumerable: true, get: function () { return node_opcua_client_dynamic_extension_object_1.ExtraDataTypeManager; } });
|
|
9
|
-
var node_opcua_extension_object_1 = require("node-opcua-extension-object");
|
|
10
|
-
Object.defineProperty(exports, "ExtensionObject", { enumerable: true, get: function () { return node_opcua_extension_object_1.ExtensionObject; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-client
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ExtensionObject = exports.ExtraDataTypeManager = void 0;
|
|
7
|
+
var node_opcua_client_dynamic_extension_object_1 = require("node-opcua-client-dynamic-extension-object");
|
|
8
|
+
Object.defineProperty(exports, "ExtraDataTypeManager", { enumerable: true, get: function () { return node_opcua_client_dynamic_extension_object_1.ExtraDataTypeManager; } });
|
|
9
|
+
var node_opcua_extension_object_1 = require("node-opcua-extension-object");
|
|
10
|
+
Object.defineProperty(exports, "ExtensionObject", { enumerable: true, get: function () { return node_opcua_extension_object_1.ExtensionObject; } });
|
|
11
11
|
//# sourceMappingURL=client_session.js.map
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/**
|
|
3
|
-
* @module node-opcua-client
|
|
4
|
-
*/
|
|
5
|
-
import { EventEmitter } from "events";
|
|
6
|
-
import { ServerState } from "node-opcua-common";
|
|
7
|
-
import { ClientSessionImpl } from "./private/client_session_impl";
|
|
8
|
-
export interface ClientSessionKeepAliveManagerEvents {
|
|
9
|
-
on(event: "keepalive", eventHandler: (lastKnownServerState: ServerState, count: number) => void): this;
|
|
10
|
-
on(event: "failure", eventHandler: () => void): this;
|
|
11
|
-
}
|
|
12
|
-
export declare class ClientSessionKeepAliveManager extends EventEmitter implements ClientSessionKeepAliveManagerEvents {
|
|
13
|
-
private readonly session;
|
|
14
|
-
private timerId?;
|
|
15
|
-
private pingTimeout;
|
|
16
|
-
private lastKnownState?;
|
|
17
|
-
private checkInterval;
|
|
18
|
-
private transactionInProgress;
|
|
19
|
-
count: number;
|
|
20
|
-
constructor(session: ClientSessionImpl);
|
|
21
|
-
start(): void;
|
|
22
|
-
stop(): void;
|
|
23
|
-
private ping_server;
|
|
24
|
-
/**
|
|
25
|
-
* @method ping_server
|
|
26
|
-
* @internal
|
|
27
|
-
* when a session is opened on a server, the client shall send request on a regular basis otherwise the server
|
|
28
|
-
* session object might time out.
|
|
29
|
-
* start_ping make sure that ping_server is called on a regular basis to prevent session to timeout.
|
|
30
|
-
*
|
|
31
|
-
* @param callback
|
|
32
|
-
*/
|
|
33
|
-
private _ping_server;
|
|
34
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* @module node-opcua-client
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from "events";
|
|
6
|
+
import { ServerState } from "node-opcua-common";
|
|
7
|
+
import { ClientSessionImpl } from "./private/client_session_impl";
|
|
8
|
+
export interface ClientSessionKeepAliveManagerEvents {
|
|
9
|
+
on(event: "keepalive", eventHandler: (lastKnownServerState: ServerState, count: number) => void): this;
|
|
10
|
+
on(event: "failure", eventHandler: () => void): this;
|
|
11
|
+
}
|
|
12
|
+
export declare class ClientSessionKeepAliveManager extends EventEmitter implements ClientSessionKeepAliveManagerEvents {
|
|
13
|
+
private readonly session;
|
|
14
|
+
private timerId?;
|
|
15
|
+
private pingTimeout;
|
|
16
|
+
private lastKnownState?;
|
|
17
|
+
private checkInterval;
|
|
18
|
+
private transactionInProgress;
|
|
19
|
+
count: number;
|
|
20
|
+
constructor(session: ClientSessionImpl);
|
|
21
|
+
start(): void;
|
|
22
|
+
stop(): void;
|
|
23
|
+
private ping_server;
|
|
24
|
+
/**
|
|
25
|
+
* @method ping_server
|
|
26
|
+
* @internal
|
|
27
|
+
* when a session is opened on a server, the client shall send request on a regular basis otherwise the server
|
|
28
|
+
* session object might time out.
|
|
29
|
+
* start_ping make sure that ping_server is called on a regular basis to prevent session to timeout.
|
|
30
|
+
*
|
|
31
|
+
* @param callback
|
|
32
|
+
*/
|
|
33
|
+
private _ping_server;
|
|
34
|
+
}
|
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ClientSessionKeepAliveManager = void 0;
|
|
13
|
-
/**
|
|
14
|
-
* @module node-opcua-client
|
|
15
|
-
*/
|
|
16
|
-
const events_1 = require("events");
|
|
17
|
-
const chalk = require("chalk");
|
|
18
|
-
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
19
|
-
const node_opcua_common_1 = require("node-opcua-common");
|
|
20
|
-
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
21
|
-
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
22
|
-
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
23
|
-
const serverStatusStateNodeId = (0, node_opcua_nodeid_1.coerceNodeId)(node_opcua_constants_1.VariableIds.Server_ServerStatus_State);
|
|
24
|
-
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
25
|
-
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
26
|
-
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
27
|
-
class ClientSessionKeepAliveManager extends events_1.EventEmitter {
|
|
28
|
-
constructor(session) {
|
|
29
|
-
super();
|
|
30
|
-
this.transactionInProgress = false;
|
|
31
|
-
this.count = 0;
|
|
32
|
-
this.session = session;
|
|
33
|
-
this.timerId = undefined;
|
|
34
|
-
this.pingTimeout = 0;
|
|
35
|
-
this.checkInterval = 0;
|
|
36
|
-
this.count = 0;
|
|
37
|
-
}
|
|
38
|
-
start() {
|
|
39
|
-
(0, node_opcua_assert_1.assert)(!this.timerId);
|
|
40
|
-
/* istanbul ignore next*/
|
|
41
|
-
if (this.session.timeout < 600) {
|
|
42
|
-
warningLog(`[NODE-OPCUA-W13] ClientSessionKeepAliveManager detected that the session timeout (${this.session.timeout} ms) is really too small: please adjust it to a greater value ( at least 1000))`);
|
|
43
|
-
}
|
|
44
|
-
/* istanbul ignore next*/
|
|
45
|
-
if (this.session.timeout < 100) {
|
|
46
|
-
throw new Error(`ClientSessionKeepAliveManager detected that the session timeout (${this.session.timeout} ms) is really too small: please adjust it to a greater value ( at least 1000))`);
|
|
47
|
-
}
|
|
48
|
-
this.pingTimeout = Math.min(this.session.timeout / 3, 20000);
|
|
49
|
-
this.checkInterval = Math.max(50, Math.min((this.session.timeout * 2) / 3, 20000));
|
|
50
|
-
// make sure first one is almost immediate
|
|
51
|
-
this.timerId = setTimeout(() => this.ping_server(), this.pingTimeout);
|
|
52
|
-
}
|
|
53
|
-
stop() {
|
|
54
|
-
if (this.timerId) {
|
|
55
|
-
debugLog("ClientSessionKeepAliveManager#stop");
|
|
56
|
-
clearTimeout(this.timerId);
|
|
57
|
-
this.timerId = undefined;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
debugLog("warning ClientSessionKeepAliveManager#stop ignore (already stopped)");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
ping_server() {
|
|
64
|
-
this._ping_server().then((delta) => {
|
|
65
|
-
if (!this.session || this.session.hasBeenClosed()) {
|
|
66
|
-
return; // stop here
|
|
67
|
-
}
|
|
68
|
-
if (this.timerId) {
|
|
69
|
-
const timeout = Math.max(1, this.checkInterval - delta);
|
|
70
|
-
this.timerId = setTimeout(() => this.ping_server(), timeout);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* @method ping_server
|
|
76
|
-
* @internal
|
|
77
|
-
* when a session is opened on a server, the client shall send request on a regular basis otherwise the server
|
|
78
|
-
* session object might time out.
|
|
79
|
-
* start_ping make sure that ping_server is called on a regular basis to prevent session to timeout.
|
|
80
|
-
*
|
|
81
|
-
* @param callback
|
|
82
|
-
*/
|
|
83
|
-
_ping_server() {
|
|
84
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
const session = this.session;
|
|
86
|
-
if (!session || session.isReconnecting) {
|
|
87
|
-
debugLog("ClientSessionKeepAliveManager#ping_server => no session available");
|
|
88
|
-
return 0;
|
|
89
|
-
}
|
|
90
|
-
if (!this.timerId) {
|
|
91
|
-
return 0; // keep-alive has been canceled ....
|
|
92
|
-
}
|
|
93
|
-
const now = Date.now();
|
|
94
|
-
const timeSinceLastServerContact = now - session.lastResponseReceivedTime.getTime();
|
|
95
|
-
if (timeSinceLastServerContact < this.pingTimeout) {
|
|
96
|
-
debugLog("ClientSessionKeepAliveManager#ping_server skipped because last communication with server was not that long ago ping timeout=", Math.round(this.pingTimeout), "timeSinceLastServerContact = ", timeSinceLastServerContact);
|
|
97
|
-
// no need to send a ping yet
|
|
98
|
-
// console.log("Skipping ",timeSinceLastServerContact,this.session.timeout);
|
|
99
|
-
return timeSinceLastServerContact - this.pingTimeout;
|
|
100
|
-
}
|
|
101
|
-
if (session.isReconnecting) {
|
|
102
|
-
debugLog("ClientSessionKeepAliveManager#ping_server skipped because client is reconnecting");
|
|
103
|
-
return 0;
|
|
104
|
-
}
|
|
105
|
-
if (session.hasBeenClosed()) {
|
|
106
|
-
debugLog("ClientSessionKeepAliveManager#ping_server skipped because client is reconnecting");
|
|
107
|
-
return 0;
|
|
108
|
-
}
|
|
109
|
-
debugLog("ClientSessionKeepAliveManager#ping_server timeSinceLastServerContact=", timeSinceLastServerContact, "timeout", this.session.timeout);
|
|
110
|
-
if (this.transactionInProgress) {
|
|
111
|
-
// readVariable already taking place ! Ignore
|
|
112
|
-
return 0;
|
|
113
|
-
}
|
|
114
|
-
this.transactionInProgress = true;
|
|
115
|
-
// Server_ServerStatus_State
|
|
116
|
-
return new Promise((resolve) => {
|
|
117
|
-
session.readVariableValue(serverStatusStateNodeId, (err, dataValue) => {
|
|
118
|
-
this.transactionInProgress = false;
|
|
119
|
-
if (err || !dataValue || !dataValue.value) {
|
|
120
|
-
if (err) {
|
|
121
|
-
warningLog(chalk.cyan(" warning : ClientSessionKeepAliveManager#ping_server "), chalk.yellow(err.message));
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* @event failure
|
|
125
|
-
* raised when the server is not responding or is responding with en error to
|
|
126
|
-
* the keep alive read Variable value transaction
|
|
127
|
-
*/
|
|
128
|
-
this.emit("failure");
|
|
129
|
-
resolve(0);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
if (dataValue.statusCode.isGood()) {
|
|
133
|
-
const newState = dataValue.value.value;
|
|
134
|
-
// istanbul ignore next
|
|
135
|
-
if (newState !== this.lastKnownState && this.lastKnownState) {
|
|
136
|
-
warningLog("ClientSessionKeepAliveManager#Server state has changed = ", node_opcua_common_1.ServerState[newState], " was ", node_opcua_common_1.ServerState[this.lastKnownState]);
|
|
137
|
-
}
|
|
138
|
-
this.lastKnownState = newState;
|
|
139
|
-
this.count++; // increase successful counter
|
|
140
|
-
}
|
|
141
|
-
debugLog("emit keepalive");
|
|
142
|
-
this.emit("keepalive", this.lastKnownState, this.count);
|
|
143
|
-
resolve(0);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
exports.ClientSessionKeepAliveManager = ClientSessionKeepAliveManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ClientSessionKeepAliveManager = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* @module node-opcua-client
|
|
15
|
+
*/
|
|
16
|
+
const events_1 = require("events");
|
|
17
|
+
const chalk = require("chalk");
|
|
18
|
+
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
19
|
+
const node_opcua_common_1 = require("node-opcua-common");
|
|
20
|
+
const node_opcua_constants_1 = require("node-opcua-constants");
|
|
21
|
+
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
22
|
+
const node_opcua_nodeid_1 = require("node-opcua-nodeid");
|
|
23
|
+
const serverStatusStateNodeId = (0, node_opcua_nodeid_1.coerceNodeId)(node_opcua_constants_1.VariableIds.Server_ServerStatus_State);
|
|
24
|
+
const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
|
|
25
|
+
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
|
|
26
|
+
const warningLog = (0, node_opcua_debug_1.make_warningLog)(__filename);
|
|
27
|
+
class ClientSessionKeepAliveManager extends events_1.EventEmitter {
|
|
28
|
+
constructor(session) {
|
|
29
|
+
super();
|
|
30
|
+
this.transactionInProgress = false;
|
|
31
|
+
this.count = 0;
|
|
32
|
+
this.session = session;
|
|
33
|
+
this.timerId = undefined;
|
|
34
|
+
this.pingTimeout = 0;
|
|
35
|
+
this.checkInterval = 0;
|
|
36
|
+
this.count = 0;
|
|
37
|
+
}
|
|
38
|
+
start() {
|
|
39
|
+
(0, node_opcua_assert_1.assert)(!this.timerId);
|
|
40
|
+
/* istanbul ignore next*/
|
|
41
|
+
if (this.session.timeout < 600) {
|
|
42
|
+
warningLog(`[NODE-OPCUA-W13] ClientSessionKeepAliveManager detected that the session timeout (${this.session.timeout} ms) is really too small: please adjust it to a greater value ( at least 1000))`);
|
|
43
|
+
}
|
|
44
|
+
/* istanbul ignore next*/
|
|
45
|
+
if (this.session.timeout < 100) {
|
|
46
|
+
throw new Error(`ClientSessionKeepAliveManager detected that the session timeout (${this.session.timeout} ms) is really too small: please adjust it to a greater value ( at least 1000))`);
|
|
47
|
+
}
|
|
48
|
+
this.pingTimeout = Math.min(this.session.timeout / 3, 20000);
|
|
49
|
+
this.checkInterval = Math.max(50, Math.min((this.session.timeout * 2) / 3, 20000));
|
|
50
|
+
// make sure first one is almost immediate
|
|
51
|
+
this.timerId = setTimeout(() => this.ping_server(), this.pingTimeout);
|
|
52
|
+
}
|
|
53
|
+
stop() {
|
|
54
|
+
if (this.timerId) {
|
|
55
|
+
debugLog("ClientSessionKeepAliveManager#stop");
|
|
56
|
+
clearTimeout(this.timerId);
|
|
57
|
+
this.timerId = undefined;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
debugLog("warning ClientSessionKeepAliveManager#stop ignore (already stopped)");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
ping_server() {
|
|
64
|
+
this._ping_server().then((delta) => {
|
|
65
|
+
if (!this.session || this.session.hasBeenClosed()) {
|
|
66
|
+
return; // stop here
|
|
67
|
+
}
|
|
68
|
+
if (this.timerId) {
|
|
69
|
+
const timeout = Math.max(1, this.checkInterval - delta);
|
|
70
|
+
this.timerId = setTimeout(() => this.ping_server(), timeout);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @method ping_server
|
|
76
|
+
* @internal
|
|
77
|
+
* when a session is opened on a server, the client shall send request on a regular basis otherwise the server
|
|
78
|
+
* session object might time out.
|
|
79
|
+
* start_ping make sure that ping_server is called on a regular basis to prevent session to timeout.
|
|
80
|
+
*
|
|
81
|
+
* @param callback
|
|
82
|
+
*/
|
|
83
|
+
_ping_server() {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const session = this.session;
|
|
86
|
+
if (!session || session.isReconnecting) {
|
|
87
|
+
debugLog("ClientSessionKeepAliveManager#ping_server => no session available");
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
if (!this.timerId) {
|
|
91
|
+
return 0; // keep-alive has been canceled ....
|
|
92
|
+
}
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
const timeSinceLastServerContact = now - session.lastResponseReceivedTime.getTime();
|
|
95
|
+
if (timeSinceLastServerContact < this.pingTimeout) {
|
|
96
|
+
debugLog("ClientSessionKeepAliveManager#ping_server skipped because last communication with server was not that long ago ping timeout=", Math.round(this.pingTimeout), "timeSinceLastServerContact = ", timeSinceLastServerContact);
|
|
97
|
+
// no need to send a ping yet
|
|
98
|
+
// console.log("Skipping ",timeSinceLastServerContact,this.session.timeout);
|
|
99
|
+
return timeSinceLastServerContact - this.pingTimeout;
|
|
100
|
+
}
|
|
101
|
+
if (session.isReconnecting) {
|
|
102
|
+
debugLog("ClientSessionKeepAliveManager#ping_server skipped because client is reconnecting");
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
if (session.hasBeenClosed()) {
|
|
106
|
+
debugLog("ClientSessionKeepAliveManager#ping_server skipped because client is reconnecting");
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
debugLog("ClientSessionKeepAliveManager#ping_server timeSinceLastServerContact=", timeSinceLastServerContact, "timeout", this.session.timeout);
|
|
110
|
+
if (this.transactionInProgress) {
|
|
111
|
+
// readVariable already taking place ! Ignore
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
this.transactionInProgress = true;
|
|
115
|
+
// Server_ServerStatus_State
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
session.readVariableValue(serverStatusStateNodeId, (err, dataValue) => {
|
|
118
|
+
this.transactionInProgress = false;
|
|
119
|
+
if (err || !dataValue || !dataValue.value) {
|
|
120
|
+
if (err) {
|
|
121
|
+
warningLog(chalk.cyan(" warning : ClientSessionKeepAliveManager#ping_server "), chalk.yellow(err.message));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @event failure
|
|
125
|
+
* raised when the server is not responding or is responding with en error to
|
|
126
|
+
* the keep alive read Variable value transaction
|
|
127
|
+
*/
|
|
128
|
+
this.emit("failure");
|
|
129
|
+
resolve(0);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (dataValue.statusCode.isGood()) {
|
|
133
|
+
const newState = dataValue.value.value;
|
|
134
|
+
// istanbul ignore next
|
|
135
|
+
if (newState !== this.lastKnownState && this.lastKnownState) {
|
|
136
|
+
warningLog("ClientSessionKeepAliveManager#Server state has changed = ", node_opcua_common_1.ServerState[newState], " was ", node_opcua_common_1.ServerState[this.lastKnownState]);
|
|
137
|
+
}
|
|
138
|
+
this.lastKnownState = newState;
|
|
139
|
+
this.count++; // increase successful counter
|
|
140
|
+
}
|
|
141
|
+
debugLog("emit keepalive");
|
|
142
|
+
this.emit("keepalive", this.lastKnownState, this.count);
|
|
143
|
+
resolve(0);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.ClientSessionKeepAliveManager = ClientSessionKeepAliveManager;
|
|
150
150
|
//# sourceMappingURL=client_session_keepalive_manager.js.map
|