node-opcua-samples 2.72.2 → 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 CHANGED
@@ -1,6 +1,8 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014-2021 Etienne Rossignon
3
+ Copyright (c) 2022 Sterfive SAS - 833264583 RCS ORLEANS - France (https://www.sterfive.com)
4
+
5
+ Copyright (c) 2014-2022 Etienne Rossignon
4
6
 
5
7
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
8
  this software and associated documentation files (the "Software"), to deal in
@@ -0,0 +1,97 @@
1
+ import { OPCUAServer, makeRoles, WellKnownRoles, NodeId, nodesets } from "node-opcua";
2
+
3
+ const port = 2510;
4
+ let server: OPCUAServer;
5
+ const users = [
6
+ {
7
+ username: "user1",
8
+ password: "passwor1",
9
+ roles: makeRoles([WellKnownRoles.AuthenticatedUser, WellKnownRoles.ConfigureAdmin])
10
+ }
11
+ ];
12
+
13
+ const userManager = {
14
+ isValidUser: (username: string, password: string): boolean => {
15
+ const uIndex = users.findIndex(function (u) {
16
+ return u.username === username;
17
+ });
18
+ if (uIndex < 0) {
19
+ return false;
20
+ }
21
+ if (users[uIndex].password !== password) {
22
+ return false;
23
+ }
24
+ return true;
25
+ },
26
+
27
+ getUserRoles: (username: string): NodeId[] => {
28
+ const uIndex = users.findIndex(function (x) {
29
+ return x.username === username;
30
+ });
31
+ if (uIndex < 0) {
32
+ return makeRoles("Anonymous");
33
+ }
34
+ const userRole = users[uIndex].roles;
35
+ return userRole;
36
+ }
37
+ };
38
+ async function startServer() {
39
+ server = new OPCUAServer({
40
+ port: port,
41
+ nodeset_filename: [nodesets.standard],
42
+ userManager,
43
+ maxConnectionsPerEndpoint: 1,
44
+ serverCapabilities: {
45
+ maxSessions: 2,
46
+ maxSubscriptions: 10,
47
+ maxSubscriptionsPerSession: 3
48
+ }
49
+ });
50
+ await server.initialize();
51
+ await server.start();
52
+
53
+ server.on("newChannel", () => {
54
+ console.log("server => new channel");
55
+ });
56
+ server.on("session_activated", () => {
57
+ console.log("server session activated");
58
+ });
59
+ server.on("connectionRefused", () => {
60
+ console.log("server connection refused");
61
+ });
62
+ server.on("session_closed", () => {
63
+ console.log("server sesion closed");
64
+ });
65
+ server.on("create_session", () => {
66
+ console.log("server create session");
67
+ });
68
+ return server;
69
+ }
70
+
71
+ (async () => {
72
+ let counter = 0;
73
+
74
+ process.on("SIGINT", () => {
75
+ if (counter > 5) {
76
+ process.exit();
77
+ }
78
+ });
79
+
80
+ while (true) {
81
+ users[0].password = `password${counter % 2}`;
82
+ counter++;
83
+ console.log("user: user1, password: ", users[0].password);
84
+ const server = await startServer();
85
+ console.log("server started at", server.getEndpointUrl());
86
+
87
+ await new Promise((resolve) => {
88
+ console.log("waiting for CTRL+C to cycle");
89
+ process.once("SIGINT", resolve);
90
+ });
91
+
92
+ console.log("now shutting down");
93
+
94
+ await server.shutdown(1000);
95
+ console.log("server stopped for maintenance");
96
+ }
97
+ })();
@@ -525,7 +525,7 @@ const paths = envPaths(productUri);
525
525
  }
526
526
  }
527
527
 
528
- const servicesToTrace = ["Publish", "TransferSubscriptions", "Republish", "CreateSubscription", "CreateMonitoredItems"];
528
+ const servicesToTrace = ["CreateSubscription"]; // "Publish", "TransferSubscriptions", "Republish", "CreateSubscription", "CreateMonitoredItems"];
529
529
  server.on("response", function (response) {
530
530
  if (argv.silent) {
531
531
  return;
@@ -0,0 +1,24 @@
1
+ process.env.NODEOPCUADEBUG = "CLIENT{TRACE};TRANSPORT{CHUNK-HELACK}";
2
+ import { OPCUAClient } from "node-opcua";
3
+
4
+ (async () => {
5
+ const client = OPCUAClient.create({
6
+ requestedSessionTimeout: 1000,
7
+ transportSettings: {
8
+ maxChunkCount: 1,
9
+ maxMessageSize: 1 * 8192, // should be at least 8192
10
+ receiveBufferSize: 8 * 1024,
11
+ sendBufferSize: 8 * 1024
12
+ },
13
+ connectionStrategy: {
14
+ initialDelay: 10,
15
+ maxDelay: 100,
16
+ maxRetry: 2
17
+ }
18
+ });
19
+
20
+ await client.connect("opc.tcp://localhost:48010");
21
+ // await client.connect("opc.tcp://localhost:53530");
22
+
23
+ await client.disconnect();
24
+ })();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,101 @@
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
+ const node_opcua_1 = require("node-opcua");
13
+ const port = 2510;
14
+ let server;
15
+ const users = [
16
+ {
17
+ username: "user1",
18
+ password: "passwor1",
19
+ roles: (0, node_opcua_1.makeRoles)([node_opcua_1.WellKnownRoles.AuthenticatedUser, node_opcua_1.WellKnownRoles.ConfigureAdmin])
20
+ }
21
+ ];
22
+ const userManager = {
23
+ isValidUser: (username, password) => {
24
+ const uIndex = users.findIndex(function (u) {
25
+ return u.username === username;
26
+ });
27
+ if (uIndex < 0) {
28
+ return false;
29
+ }
30
+ if (users[uIndex].password !== password) {
31
+ return false;
32
+ }
33
+ return true;
34
+ },
35
+ getUserRoles: (username) => {
36
+ const uIndex = users.findIndex(function (x) {
37
+ return x.username === username;
38
+ });
39
+ if (uIndex < 0) {
40
+ return (0, node_opcua_1.makeRoles)("Anonymous");
41
+ }
42
+ const userRole = users[uIndex].roles;
43
+ return userRole;
44
+ }
45
+ };
46
+ function startServer() {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ server = new node_opcua_1.OPCUAServer({
49
+ port: port,
50
+ nodeset_filename: [node_opcua_1.nodesets.standard],
51
+ userManager,
52
+ maxConnectionsPerEndpoint: 1,
53
+ serverCapabilities: {
54
+ maxSessions: 2,
55
+ maxSubscriptions: 10,
56
+ maxSubscriptionsPerSession: 3
57
+ }
58
+ });
59
+ yield server.initialize();
60
+ yield server.start();
61
+ server.on("newChannel", () => {
62
+ console.log("server => new channel");
63
+ });
64
+ server.on("session_activated", () => {
65
+ console.log("server session activated");
66
+ });
67
+ server.on("connectionRefused", () => {
68
+ console.log("server connection refused");
69
+ });
70
+ server.on("session_closed", () => {
71
+ console.log("server sesion closed");
72
+ });
73
+ server.on("create_session", () => {
74
+ console.log("server create session");
75
+ });
76
+ return server;
77
+ });
78
+ }
79
+ (() => __awaiter(void 0, void 0, void 0, function* () {
80
+ let counter = 0;
81
+ process.on("SIGINT", () => {
82
+ if (counter > 5) {
83
+ process.exit();
84
+ }
85
+ });
86
+ while (true) {
87
+ users[0].password = `password${counter % 2}`;
88
+ counter++;
89
+ console.log("user: user1, password: ", users[0].password);
90
+ const server = yield startServer();
91
+ console.log("server started at", server.getEndpointUrl());
92
+ yield new Promise((resolve) => {
93
+ console.log("waiting for CTRL+C to cycle");
94
+ process.once("SIGINT", resolve);
95
+ });
96
+ console.log("now shutting down");
97
+ yield server.shutdown(1000);
98
+ console.log("server stopped for maintenance");
99
+ }
100
+ }))();
101
+ //# sourceMappingURL=server_with_changing_password.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server_with_changing_password.js","sourceRoot":"","sources":["../bin/server_with_changing_password.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAAsF;AAEtF,MAAM,IAAI,GAAG,IAAI,CAAC;AAClB,IAAI,MAAmB,CAAC;AACxB,MAAM,KAAK,GAAG;IACV;QACI,QAAQ,EAAE,OAAO;QACjB,QAAQ,EAAE,UAAU;QACpB,KAAK,EAAE,IAAA,sBAAS,EAAC,CAAC,2BAAc,CAAC,iBAAiB,EAAE,2BAAc,CAA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,CAAC,CAAC;QAE1D,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC1B,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;YAC3C,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAEjC,MAAM,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5B,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;KACjD;AACL,CAAC,CAAA,CAAC,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
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
+ process.env.NODEOPCUADEBUG = "CLIENT{TRACE};TRANSPORT{CHUNK-HELACK}";
13
+ const node_opcua_1 = require("node-opcua");
14
+ (() => __awaiter(void 0, void 0, void 0, function* () {
15
+ const client = node_opcua_1.OPCUAClient.create({
16
+ requestedSessionTimeout: 1000,
17
+ transportSettings: {
18
+ maxChunkCount: 1,
19
+ maxMessageSize: 1 * 8192,
20
+ receiveBufferSize: 8 * 1024,
21
+ sendBufferSize: 8 * 1024
22
+ },
23
+ connectionStrategy: {
24
+ initialDelay: 10,
25
+ maxDelay: 100,
26
+ maxRetry: 2
27
+ }
28
+ });
29
+ yield client.connect("opc.tcp://localhost:48010");
30
+ // await client.connect("opc.tcp://localhost:53530");
31
+ yield client.disconnect();
32
+ }))();
33
+ //# sourceMappingURL=tiny_client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiny_client.js","sourceRoot":"","sources":["../bin/tiny_client.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,CAAC,GAAG,CAAC,cAAc,GAAG,uCAAuC,CAAC;AACrE,2CAAyC;AAEzC,CAAC,GAAS,EAAE;IACR,MAAM,MAAM,GAAG,wBAAW,CAAC,MAAM,CAAC;QAC9B,uBAAuB,EAAE,IAAI;QAC7B,iBAAiB,EAAE;YACf,aAAa,EAAE,CAAC;YAChB,cAAc,EAAE,CAAC,GAAG,IAAI;YACxB,iBAAiB,EAAE,CAAC,GAAG,IAAI;YAC3B,cAAc,EAAE,CAAC,GAAG,IAAI;SAC3B;QACD,kBAAkB,EAAE;YAChB,YAAY,EAAE,EAAE;YAChB,QAAQ,EAAE,GAAG;YACb,QAAQ,EAAE,CAAC;SACd;KACJ,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAClD,qDAAqD;IAErD,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;AAC9B,CAAC,CAAA,CAAC,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-samples",
3
- "version": "2.72.2",
3
+ "version": "2.74.0",
4
4
  "description": "pure nodejs OPCUA SDK - module -samples",
5
5
  "bin": {
6
6
  "simple_client": "./dist/simple_client_ts.js",
@@ -20,10 +20,10 @@
20
20
  "@types/yargs": "17.0.10",
21
21
  "easy-table": "^1.2.0",
22
22
  "exit": "^0.1.2",
23
- "node-opcua": "2.72.2",
24
- "node-opcua-assert": "2.66.0",
23
+ "node-opcua": "2.74.0",
24
+ "node-opcua-assert": "2.74.0",
25
25
  "node-opcua-pki": "^2.17.0",
26
- "node-opcua-server-configuration": "2.72.2",
26
+ "node-opcua-server-configuration": "2.74.0",
27
27
  "sprintf-js": "^1.1.2",
28
28
  "treeify": "^1.1.0",
29
29
  "underscore": "^1.13.4",
@@ -44,5 +44,5 @@
44
44
  "internet of things"
45
45
  ],
46
46
  "homepage": "http://node-opcua.github.io/",
47
- "gitHead": "07dcdd8e8c7f2b55544c6e23023093e35674829c"
47
+ "gitHead": "003ee041795f3b737afaaef5721045ee31ea9f77"
48
48
  }