node-opcua-server 2.73.1 → 2.74.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/LICENSE +3 -1
- package/dist/opcua_server.js +21 -19
- package/dist/opcua_server.js.map +1 -1
- package/dist/server_publish_engine.d.ts +5 -4
- package/dist/server_publish_engine.js +14 -8
- package/dist/server_publish_engine.js.map +1 -1
- package/dist/server_subscription.js +7 -5
- package/dist/server_subscription.js.map +1 -1
- package/package.json +48 -48
- package/source/opcua_server.ts +22 -23
- package/source/server_publish_engine.ts +24 -19
- package/source/server_subscription.ts +9 -6
|
@@ -11,7 +11,7 @@ import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
|
|
|
11
11
|
import { ObjectRegistry } from "node-opcua-object-registry";
|
|
12
12
|
import { StatusCode, StatusCodes } from "node-opcua-status-code";
|
|
13
13
|
|
|
14
|
-
import { PublishRequest, PublishResponse, SubscriptionAcknowledgement } from "node-opcua-types";
|
|
14
|
+
import { PublishRequest, PublishResponse, ServiceFault, SubscriptionAcknowledgement } from "node-opcua-types";
|
|
15
15
|
import { Subscription } from "./server_subscription";
|
|
16
16
|
import { SubscriptionState } from "./server_subscription";
|
|
17
17
|
import { IServerSidePublishEngine, INotifMsg, IClosedOrTransferredSubscription } from "./i_server_side_publish_engine";
|
|
@@ -36,7 +36,7 @@ interface PublishData {
|
|
|
36
36
|
request: PublishRequest;
|
|
37
37
|
serverTimeWhenReceived: number;
|
|
38
38
|
results: StatusCode[];
|
|
39
|
-
callback: (request: PublishRequest, response: PublishResponse) => void;
|
|
39
|
+
callback: (request: PublishRequest, response: PublishResponse | ServiceFault) => void;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function _assertValidPublishData(publishData: PublishData) {
|
|
@@ -137,7 +137,7 @@ export class ServerSidePublishEngine extends EventEmitter implements IServerSide
|
|
|
137
137
|
|
|
138
138
|
const tmp = srcPublishEngine.detach_subscription(subscription);
|
|
139
139
|
destPublishEngine.add_subscription(tmp);
|
|
140
|
-
|
|
140
|
+
|
|
141
141
|
subscription.resetLifeTimeCounter();
|
|
142
142
|
if (sendInitialValues) {
|
|
143
143
|
/* A Boolean parameter with the following values:
|
|
@@ -327,11 +327,12 @@ export class ServerSidePublishEngine extends EventEmitter implements IServerSide
|
|
|
327
327
|
public on_close_subscription(subscription: IClosedOrTransferredSubscription): void {
|
|
328
328
|
doDebug && debugLog("ServerSidePublishEngine#on_close_subscription", subscription.id);
|
|
329
329
|
if (subscription.hasPendingNotifications) {
|
|
330
|
-
doDebug &&
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
330
|
+
doDebug &&
|
|
331
|
+
debugLog(
|
|
332
|
+
"ServerSidePublishEngine#on_close_subscription storing subscription",
|
|
333
|
+
subscription.id,
|
|
334
|
+
" to _closed_subscriptions because it has pending notification"
|
|
335
|
+
);
|
|
335
336
|
this._closed_subscriptions.push(subscription);
|
|
336
337
|
} else {
|
|
337
338
|
doDebug && debugLog("ServerSidePublishEngine#on_close_subscription disposing subscription", subscription.id);
|
|
@@ -402,7 +403,7 @@ export class ServerSidePublishEngine extends EventEmitter implements IServerSide
|
|
|
402
403
|
*/
|
|
403
404
|
public _on_PublishRequest(
|
|
404
405
|
request: PublishRequest,
|
|
405
|
-
callback?: (request1: PublishRequest, response: PublishResponse) => void
|
|
406
|
+
callback?: (request1: PublishRequest, response: PublishResponse| ServiceFault) => void
|
|
406
407
|
): void {
|
|
407
408
|
callback = callback || dummy_function;
|
|
408
409
|
assert(typeof callback === "function");
|
|
@@ -483,9 +484,10 @@ export class ServerSidePublishEngine extends EventEmitter implements IServerSide
|
|
|
483
484
|
s.timeToKeepAlive +
|
|
484
485
|
" m?=" +
|
|
485
486
|
s.hasUncollectedMonitoredItemNotifications +
|
|
486
|
-
" " +
|
|
487
|
+
" " +
|
|
487
488
|
SubscriptionState[s.state] +
|
|
488
|
-
" " +
|
|
489
|
+
" " +
|
|
490
|
+
s.messageSent +
|
|
489
491
|
"]"
|
|
490
492
|
)
|
|
491
493
|
.join(" \n")
|
|
@@ -508,7 +510,8 @@ export class ServerSidePublishEngine extends EventEmitter implements IServerSide
|
|
|
508
510
|
}
|
|
509
511
|
const starving_subscription = this._find_starving_subscription();
|
|
510
512
|
if (starving_subscription) {
|
|
511
|
-
doDebug &&
|
|
513
|
+
doDebug &&
|
|
514
|
+
debugLog(chalk.bgWhite.red("feeding most late subscription subscriptionId = "), starving_subscription.id);
|
|
512
515
|
starving_subscription.process_subscription();
|
|
513
516
|
}
|
|
514
517
|
});
|
|
@@ -537,10 +540,10 @@ export class ServerSidePublishEngine extends EventEmitter implements IServerSide
|
|
|
537
540
|
|
|
538
541
|
private _send_error_for_request(publishData: PublishData, statusCode: StatusCode): void {
|
|
539
542
|
_assertValidPublishData(publishData);
|
|
540
|
-
const
|
|
543
|
+
const response = new ServiceFault({
|
|
541
544
|
responseHeader: { serviceResult: statusCode }
|
|
542
545
|
});
|
|
543
|
-
this._send_response_for_request(publishData,
|
|
546
|
+
this._send_response_for_request(publishData, response);
|
|
544
547
|
}
|
|
545
548
|
|
|
546
549
|
private _cancelPendingPublishRequest(statusCode: StatusCode): void {
|
|
@@ -629,7 +632,7 @@ export class ServerSidePublishEngine extends EventEmitter implements IServerSide
|
|
|
629
632
|
assert(this.pendingPublishRequestCount > 0);
|
|
630
633
|
assert(response.subscriptionId !== 0xffffff);
|
|
631
634
|
const publishData = this._publish_request_queue.shift()!;
|
|
632
|
-
this.
|
|
635
|
+
this._send_valid_response_for_request(publishData, response);
|
|
633
636
|
}
|
|
634
637
|
|
|
635
638
|
public _on_tick(): void {
|
|
@@ -654,15 +657,17 @@ export class ServerSidePublishEngine extends EventEmitter implements IServerSide
|
|
|
654
657
|
this._send_error_for_request(publishData, StatusCodes.BadTimeout);
|
|
655
658
|
}
|
|
656
659
|
}
|
|
657
|
-
|
|
658
|
-
|
|
660
|
+
public _send_response_for_request(publishData: PublishData, response: PublishResponse | ServiceFault): void {
|
|
661
|
+
response.responseHeader.requestHandle = publishData.request.requestHeader.requestHandle;
|
|
662
|
+
publishData.callback(publishData.request, response);
|
|
663
|
+
}
|
|
664
|
+
public _send_valid_response_for_request(publishData: PublishData, response: PublishResponse): void {
|
|
659
665
|
if (doDebug) {
|
|
660
666
|
debugLog("_send_response_for_request ", response.toString());
|
|
661
667
|
}
|
|
662
668
|
_assertValidPublishData(publishData);
|
|
663
669
|
// xx assert(response.responseHeader.requestHandle !== 0,"expecting a valid requestHandle");
|
|
664
670
|
response.results = publishData.results;
|
|
665
|
-
|
|
666
|
-
publishData.callback(publishData.request, response);
|
|
671
|
+
this._send_response_for_request(publishData, response);
|
|
667
672
|
}
|
|
668
673
|
}
|
|
@@ -629,7 +629,7 @@ export class Subscription extends EventEmitter {
|
|
|
629
629
|
this.messageSent = false;
|
|
630
630
|
|
|
631
631
|
this.timerId = null;
|
|
632
|
-
this._start_timer();
|
|
632
|
+
this._start_timer({ firstTime: true });
|
|
633
633
|
|
|
634
634
|
debugLog(chalk.green(`creating subscription ${this.id}`));
|
|
635
635
|
|
|
@@ -686,7 +686,7 @@ export class Subscription extends EventEmitter {
|
|
|
686
686
|
// todo
|
|
687
687
|
}
|
|
688
688
|
this._stop_timer();
|
|
689
|
-
this._start_timer();
|
|
689
|
+
this._start_timer({ firstTime: false });
|
|
690
690
|
}
|
|
691
691
|
|
|
692
692
|
/**
|
|
@@ -732,7 +732,7 @@ export class Subscription extends EventEmitter {
|
|
|
732
732
|
public increaseLifeTimeCounter(): void {
|
|
733
733
|
this._life_time_counter += 1;
|
|
734
734
|
if (this._life_time_counter >= this.lifeTimeCount) {
|
|
735
|
-
|
|
735
|
+
this.emit("lifeTimeExpired");
|
|
736
736
|
}
|
|
737
737
|
this.emit("lifeTimeCounterChanged", this._life_time_counter);
|
|
738
738
|
}
|
|
@@ -1458,7 +1458,7 @@ export class Subscription extends EventEmitter {
|
|
|
1458
1458
|
}
|
|
1459
1459
|
}
|
|
1460
1460
|
|
|
1461
|
-
private _start_timer() {
|
|
1461
|
+
private _start_timer({ firstTime }: { firstTime: boolean }) {
|
|
1462
1462
|
debugLog(
|
|
1463
1463
|
chalk.bgWhite.blue("Subscription#_start_timer subscriptionId="),
|
|
1464
1464
|
this.id,
|
|
@@ -1478,8 +1478,11 @@ export class Subscription extends EventEmitter {
|
|
|
1478
1478
|
// make sure that a keep-alive Message will be send at the end of the first publishing cycle
|
|
1479
1479
|
// if there are no Notifications ready.
|
|
1480
1480
|
this._keep_alive_counter = 0; // this.maxKeepAliveCount;
|
|
1481
|
-
|
|
1482
|
-
|
|
1481
|
+
|
|
1482
|
+
if (firstTime) {
|
|
1483
|
+
assert(this.messageSent === false);
|
|
1484
|
+
assert(this.state === SubscriptionState.CREATING);
|
|
1485
|
+
}
|
|
1483
1486
|
|
|
1484
1487
|
assert(this.publishingInterval >= Subscription.minimumPublishingInterval);
|
|
1485
1488
|
this.timerId = setInterval(this._tick.bind(this), this.publishingInterval);
|