node-opcua-service-discovery 2.76.0 → 2.76.2

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/bonjour.d.ts CHANGED
@@ -1,40 +1,40 @@
1
- import { Bonjour, Service, ServiceConfig } from "sterfive-bonjour-service";
2
- export declare function acquireBonjour(): Bonjour;
3
- export declare function releaseBonjour(bonjour: Bonjour, callback: () => void): void;
4
- export declare function acquireBonjour2(): Bonjour;
5
- export declare function releaseBonjour2(bonjour: Bonjour): void;
6
- export interface Announcement {
7
- port: number;
8
- path: string;
9
- name: string;
10
- capabilities: string[];
11
- }
12
- export declare function announcementToServiceConfig(announcement: Announcement): ServiceConfig;
13
- export declare function isSameService(a?: ServiceConfig, b?: ServiceConfig): boolean;
14
- export declare const serviceToString: (service: ServiceConfig) => string;
15
- export declare function _announceServerOnMulticastSubnet(multicastDNS: Bonjour, serviceConfig: ServiceConfig): Promise<Service>;
16
- export declare class BonjourHolder {
17
- serviceConfig?: ServiceConfig;
18
- private _multicastDNS?;
19
- private _service?;
20
- private pendingAnnouncement;
21
- /**
22
- *
23
- * @param announcement
24
- * @returns
25
- */
26
- announcedOnMulticastSubnet(announcement: Announcement): Promise<boolean>;
27
- isStarted(): boolean;
28
- /**
29
- *
30
- * @param announcement
31
- * @param callback
32
- * @private
33
- */
34
- announcedOnMulticastSubnetWithCallback(announcement: Announcement, callback: (err: Error | null, result?: boolean) => void): void;
35
- /**
36
- * @private
37
- */
38
- stopAnnnouncedOnMulticastSubnet(): Promise<void>;
39
- stopAnnouncedOnMulticastSubnetWithCallback(callback: (err: Error | null) => void): void;
40
- }
1
+ import { Bonjour, Service, ServiceConfig } from "sterfive-bonjour-service";
2
+ export declare function acquireBonjour(): Bonjour;
3
+ export declare function releaseBonjour(bonjour: Bonjour, callback: () => void): void;
4
+ export declare function acquireBonjour2(): Bonjour;
5
+ export declare function releaseBonjour2(bonjour: Bonjour): void;
6
+ export interface Announcement {
7
+ port: number;
8
+ path: string;
9
+ name: string;
10
+ capabilities: string[];
11
+ }
12
+ export declare function announcementToServiceConfig(announcement: Announcement): ServiceConfig;
13
+ export declare function isSameService(a?: ServiceConfig, b?: ServiceConfig): boolean;
14
+ export declare const serviceToString: (service: ServiceConfig) => string;
15
+ export declare function _announceServerOnMulticastSubnet(multicastDNS: Bonjour, serviceConfig: ServiceConfig): Promise<Service>;
16
+ export declare class BonjourHolder {
17
+ serviceConfig?: ServiceConfig;
18
+ private _multicastDNS?;
19
+ private _service?;
20
+ private pendingAnnouncement;
21
+ /**
22
+ *
23
+ * @param announcement
24
+ * @returns
25
+ */
26
+ announcedOnMulticastSubnet(announcement: Announcement): Promise<boolean>;
27
+ isStarted(): boolean;
28
+ /**
29
+ *
30
+ * @param announcement
31
+ * @param callback
32
+ * @private
33
+ */
34
+ announcedOnMulticastSubnetWithCallback(announcement: Announcement, callback: (err: Error | null, result?: boolean) => void): void;
35
+ /**
36
+ * @private
37
+ */
38
+ stopAnnnouncedOnMulticastSubnet(): Promise<void>;
39
+ stopAnnouncedOnMulticastSubnetWithCallback(callback: (err: Error | null) => void): void;
40
+ }
package/dist/bonjour.js CHANGED
@@ -1,264 +1,264 @@
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.BonjourHolder = exports._announceServerOnMulticastSubnet = exports.serviceToString = exports.isSameService = exports.announcementToServiceConfig = exports.releaseBonjour2 = exports.acquireBonjour2 = exports.releaseBonjour = exports.acquireBonjour = void 0;
13
- /**
14
- * @module node-opcua-service-discovery
15
- */
16
- // tslint:disable:no-console
17
- const util_1 = require("util");
18
- const chalk = require("chalk");
19
- const node_opcua_assert_1 = require("node-opcua-assert");
20
- const node_opcua_debug_1 = require("node-opcua-debug");
21
- const node_opcua_object_registry_1 = require("node-opcua-object-registry");
22
- const sterfive_bonjour_service_1 = require("sterfive-bonjour-service");
23
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
24
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
25
- let gBonjour;
26
- let gBonjourRefCount = 0;
27
- const registry = new node_opcua_object_registry_1.ObjectRegistry();
28
- function errorCallback(err) {
29
- console.log(" ERROR received from Bonjour", err.message);
30
- }
31
- function acquireBonjour() {
32
- const bonjour = new sterfive_bonjour_service_1.Bonjour();
33
- registry.unregister(bonjour);
34
- return bonjour;
35
- }
36
- exports.acquireBonjour = acquireBonjour;
37
- function releaseBonjour(bonjour, callback) {
38
- bonjour.unpublishAll(() => {
39
- bonjour.destroy(callback);
40
- registry.unregister(bonjour);
41
- });
42
- }
43
- exports.releaseBonjour = releaseBonjour;
44
- function acquireBonjour2() {
45
- if (gBonjourRefCount === 0) {
46
- // will start the Bonjour service
47
- debugLog("Starting Bonjour");
48
- gBonjour = new sterfive_bonjour_service_1.Bonjour(undefined, errorCallback);
49
- registry.register(gBonjour);
50
- }
51
- gBonjourRefCount++;
52
- return gBonjour;
53
- }
54
- exports.acquireBonjour2 = acquireBonjour2;
55
- function releaseBonjour2(bonjour) {
56
- gBonjourRefCount--;
57
- (0, node_opcua_assert_1.assert)(gBonjourRefCount >= 0);
58
- if (gBonjourRefCount === 0) {
59
- if (!gBonjour) {
60
- throw new Error("internal error");
61
- }
62
- const tmp = gBonjour;
63
- gBonjour = undefined;
64
- // will stop the Bonjour service
65
- tmp.unpublishAll(() => {
66
- tmp.destroy();
67
- registry.unregister(tmp);
68
- debugLog("Releasing Bonjour");
69
- });
70
- }
71
- }
72
- exports.releaseBonjour2 = releaseBonjour2;
73
- function announcementToServiceConfig(announcement) {
74
- const serviceConfig = {
75
- name: announcement.name,
76
- port: announcement.port,
77
- protocol: "tcp",
78
- txt: {
79
- caps: announcement.capabilities.sort().join(","),
80
- path: announcement.path
81
- },
82
- type: "opcua-tcp"
83
- };
84
- return serviceConfig;
85
- }
86
- exports.announcementToServiceConfig = announcementToServiceConfig;
87
- function isSameService(a, b) {
88
- var _a, _b, _c, _d;
89
- if (!a && !b) {
90
- return true;
91
- }
92
- if (!a || !b) {
93
- return false;
94
- }
95
- return a.port === b.port && ((_a = a.txt) === null || _a === void 0 ? void 0 : _a.path) === ((_b = b.txt) === null || _b === void 0 ? void 0 : _b.path) && a.name === b.name && ((_c = a.txt) === null || _c === void 0 ? void 0 : _c.caps) === ((_d = b.txt) === null || _d === void 0 ? void 0 : _d.caps);
96
- }
97
- exports.isSameService = isSameService;
98
- const serviceToString = (service) => {
99
- return "type=" + service.type + service.name + " on port " + service.port + " txt " + JSON.stringify(service.txt);
100
- };
101
- exports.serviceToString = serviceToString;
102
- // function waitServiceUp(serviceConfig: ServiceConfig, callback: () => void) {
103
- // const multicastDNS = new Bonjour();
104
- // const browser = multicastDNS.find({
105
- // protocol: "tcp",
106
- // type: "opcua-tcp"
107
- // });
108
- // const onUp = (service: Service) => {
109
- // if (doDebug) {
110
- // debugLog(chalk.cyan(" waitServiceUp is up with ", serviceToString(service)));
111
- // }
112
- // if (isSameService(service, serviceConfig)) {
113
- // browser.removeAllListeners("up");
114
- // multicastDNS.destroy();
115
- // callback();
116
- // }
117
- // };
118
- // browser.on("up", onUp);
119
- // }
120
- // function waitServiceDown(serviceConfig: ServiceConfig, callback: () => void) {
121
- // const multicastDNS = new Bonjour();
122
- // const browser = multicastDNS.find({
123
- // protocol: "tcp",
124
- // type: "opcua-tcp"
125
- // });
126
- // const onDown = (service: Service) => {
127
- // if (doDebug) {
128
- // debugLog(chalk.cyan(" waitServiceDown down with ", serviceToString(service)));
129
- // }
130
- // if (isSameService(service, serviceConfig)) {
131
- // browser.removeAllListeners("down");
132
- // multicastDNS.destroy();
133
- // callback();
134
- // }
135
- // };
136
- // browser.on("down", onDown);
137
- // }
138
- function _announceServerOnMulticastSubnet(multicastDNS, serviceConfig) {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- return new Promise((resolve, reject) => {
141
- const port = serviceConfig.port;
142
- (0, node_opcua_assert_1.assert)(typeof port === "number");
143
- (0, node_opcua_assert_1.assert)(multicastDNS, "bonjour must have been initialized?");
144
- debugLog(chalk.cyan(" announceServerOnMulticastSubnet", (0, exports.serviceToString)(serviceConfig)));
145
- // waitServiceUp(serviceConfig, () => {
146
- // // istanbul ignore next
147
- // if (doDebug) {
148
- // debugLog(chalk.cyan(" announcedOnMulticastSubnet done ", serviceToString(serviceConfig)));
149
- // }
150
- // // resolve(service);
151
- // });
152
- const service = multicastDNS.publish(Object.assign(Object.assign({}, serviceConfig), { probe: false }));
153
- service.on("error", (err) => {
154
- debugLog("bonjour ERROR received ! ", err.message);
155
- debugLog("params = ", serviceConfig);
156
- });
157
- service.on("up", () => {
158
- debugLog("_announceServerOnMulticastSubnet: bonjour UP received ! ", (0, exports.serviceToString)(serviceConfig));
159
- resolve(service);
160
- });
161
- service.start();
162
- });
163
- });
164
- }
165
- exports._announceServerOnMulticastSubnet = _announceServerOnMulticastSubnet;
166
- class BonjourHolder {
167
- constructor() {
168
- this.pendingAnnouncement = false;
169
- }
170
- /**
171
- *
172
- * @param announcement
173
- * @returns
174
- */
175
- announcedOnMulticastSubnet(announcement) {
176
- return __awaiter(this, void 0, void 0, function* () {
177
- debugLog(chalk.yellow("\n\nentering announcedOnMulticastSubnet"));
178
- const serviceConfig = announcementToServiceConfig(announcement);
179
- if (this._service && this.serviceConfig) {
180
- // verify that Announcement has changed
181
- if (isSameService(serviceConfig, this.serviceConfig)) {
182
- debugLog(" Announcement ignored as it has been already made", announcement.name);
183
- debugLog("exiting announcedOnMulticastSubnet-2", false);
184
- return false; // nothing changed
185
- }
186
- }
187
- (0, node_opcua_assert_1.assert)(!this._multicastDNS, "already called ?");
188
- this._multicastDNS = acquireBonjour();
189
- this.pendingAnnouncement = true;
190
- this.serviceConfig = serviceConfig;
191
- this._service = yield _announceServerOnMulticastSubnet(this._multicastDNS, serviceConfig);
192
- this.pendingAnnouncement = false;
193
- debugLog(chalk.yellow("exiting announcedOnMulticastSubnet-3", true));
194
- return true;
195
- });
196
- }
197
- isStarted() {
198
- return !!this._multicastDNS;
199
- }
200
- /**
201
- *
202
- * @param announcement
203
- * @param callback
204
- * @private
205
- */
206
- announcedOnMulticastSubnetWithCallback(announcement, callback) {
207
- callback(new Error("Internal Error"));
208
- }
209
- /**
210
- * @private
211
- */
212
- stopAnnnouncedOnMulticastSubnet() {
213
- return __awaiter(this, void 0, void 0, function* () {
214
- if (this.pendingAnnouncement) {
215
- debugLog(chalk.bgWhite.redBright("stopAnnnouncedOnMulticastSubnet is pending : let's wait a little bit and try again"));
216
- // wait until announcement is done
217
- yield new Promise((resolve) => setTimeout(resolve, 500));
218
- return this.stopAnnnouncedOnMulticastSubnet();
219
- }
220
- debugLog(chalk.green("\n\nentering stop_announcedOnMulticastSubnet = ", this.serviceConfig ? (0, exports.serviceToString)(this.serviceConfig) : "<null>"));
221
- if (!this._service) {
222
- debugLog(chalk.green("leaving stop_announcedOnMulticastSubnet = no service"));
223
- return;
224
- }
225
- // due to a wrong declaration of Service.stop in the d.ts file we
226
- // need to use a workaround here
227
- const that_service = this._service;
228
- const that_multicastDNS = this._multicastDNS;
229
- this._service = undefined;
230
- this._multicastDNS = undefined;
231
- this.serviceConfig = undefined;
232
- const proxy = (callback) => {
233
- if (that_multicastDNS && that_service.stop) {
234
- // waitServiceDown(that_service, () => {
235
- // debugLog(chalk.green("stop_announcedOnMulticastSubnet, ", serviceToString(that_service)));
236
- // });
237
- that_service.stop((err) => {
238
- debugLog(chalk.green("service stopped err=", err));
239
- that_multicastDNS.unpublishAll(() => {
240
- releaseBonjour(that_multicastDNS, () => {
241
- callback();
242
- });
243
- });
244
- });
245
- return;
246
- }
247
- else {
248
- callback();
249
- }
250
- };
251
- const stop = (0, util_1.promisify)(proxy);
252
- yield stop.call(this);
253
- debugLog(chalk.green("leaving stop_announcedOnMulticastSubnet = done"));
254
- debugLog(chalk.green("leaving stop_announcedOnMulticastSubnet stop announcement completed"));
255
- });
256
- }
257
- stopAnnouncedOnMulticastSubnetWithCallback(callback) {
258
- callback(new Error("Internal Error"));
259
- }
260
- }
261
- exports.BonjourHolder = BonjourHolder;
262
- BonjourHolder.prototype.announcedOnMulticastSubnetWithCallback = (0, util_1.callbackify)(BonjourHolder.prototype.announcedOnMulticastSubnet);
263
- BonjourHolder.prototype.stopAnnouncedOnMulticastSubnetWithCallback = (0, util_1.callbackify)(BonjourHolder.prototype.stopAnnnouncedOnMulticastSubnet);
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.BonjourHolder = exports._announceServerOnMulticastSubnet = exports.serviceToString = exports.isSameService = exports.announcementToServiceConfig = exports.releaseBonjour2 = exports.acquireBonjour2 = exports.releaseBonjour = exports.acquireBonjour = void 0;
13
+ /**
14
+ * @module node-opcua-service-discovery
15
+ */
16
+ // tslint:disable:no-console
17
+ const util_1 = require("util");
18
+ const chalk = require("chalk");
19
+ const node_opcua_assert_1 = require("node-opcua-assert");
20
+ const node_opcua_debug_1 = require("node-opcua-debug");
21
+ const node_opcua_object_registry_1 = require("node-opcua-object-registry");
22
+ const sterfive_bonjour_service_1 = require("sterfive-bonjour-service");
23
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
24
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename);
25
+ let gBonjour;
26
+ let gBonjourRefCount = 0;
27
+ const registry = new node_opcua_object_registry_1.ObjectRegistry();
28
+ function errorCallback(err) {
29
+ console.log(" ERROR received from Bonjour", err.message);
30
+ }
31
+ function acquireBonjour() {
32
+ const bonjour = new sterfive_bonjour_service_1.Bonjour();
33
+ registry.unregister(bonjour);
34
+ return bonjour;
35
+ }
36
+ exports.acquireBonjour = acquireBonjour;
37
+ function releaseBonjour(bonjour, callback) {
38
+ bonjour.unpublishAll(() => {
39
+ bonjour.destroy(callback);
40
+ registry.unregister(bonjour);
41
+ });
42
+ }
43
+ exports.releaseBonjour = releaseBonjour;
44
+ function acquireBonjour2() {
45
+ if (gBonjourRefCount === 0) {
46
+ // will start the Bonjour service
47
+ debugLog("Starting Bonjour");
48
+ gBonjour = new sterfive_bonjour_service_1.Bonjour(undefined, errorCallback);
49
+ registry.register(gBonjour);
50
+ }
51
+ gBonjourRefCount++;
52
+ return gBonjour;
53
+ }
54
+ exports.acquireBonjour2 = acquireBonjour2;
55
+ function releaseBonjour2(bonjour) {
56
+ gBonjourRefCount--;
57
+ (0, node_opcua_assert_1.assert)(gBonjourRefCount >= 0);
58
+ if (gBonjourRefCount === 0) {
59
+ if (!gBonjour) {
60
+ throw new Error("internal error");
61
+ }
62
+ const tmp = gBonjour;
63
+ gBonjour = undefined;
64
+ // will stop the Bonjour service
65
+ tmp.unpublishAll(() => {
66
+ tmp.destroy();
67
+ registry.unregister(tmp);
68
+ debugLog("Releasing Bonjour");
69
+ });
70
+ }
71
+ }
72
+ exports.releaseBonjour2 = releaseBonjour2;
73
+ function announcementToServiceConfig(announcement) {
74
+ const serviceConfig = {
75
+ name: announcement.name,
76
+ port: announcement.port,
77
+ protocol: "tcp",
78
+ txt: {
79
+ caps: announcement.capabilities.sort().join(","),
80
+ path: announcement.path
81
+ },
82
+ type: "opcua-tcp"
83
+ };
84
+ return serviceConfig;
85
+ }
86
+ exports.announcementToServiceConfig = announcementToServiceConfig;
87
+ function isSameService(a, b) {
88
+ var _a, _b, _c, _d;
89
+ if (!a && !b) {
90
+ return true;
91
+ }
92
+ if (!a || !b) {
93
+ return false;
94
+ }
95
+ return a.port === b.port && ((_a = a.txt) === null || _a === void 0 ? void 0 : _a.path) === ((_b = b.txt) === null || _b === void 0 ? void 0 : _b.path) && a.name === b.name && ((_c = a.txt) === null || _c === void 0 ? void 0 : _c.caps) === ((_d = b.txt) === null || _d === void 0 ? void 0 : _d.caps);
96
+ }
97
+ exports.isSameService = isSameService;
98
+ const serviceToString = (service) => {
99
+ return "type=" + service.type + service.name + " on port " + service.port + " txt " + JSON.stringify(service.txt);
100
+ };
101
+ exports.serviceToString = serviceToString;
102
+ // function waitServiceUp(serviceConfig: ServiceConfig, callback: () => void) {
103
+ // const multicastDNS = new Bonjour();
104
+ // const browser = multicastDNS.find({
105
+ // protocol: "tcp",
106
+ // type: "opcua-tcp"
107
+ // });
108
+ // const onUp = (service: Service) => {
109
+ // if (doDebug) {
110
+ // debugLog(chalk.cyan(" waitServiceUp is up with ", serviceToString(service)));
111
+ // }
112
+ // if (isSameService(service, serviceConfig)) {
113
+ // browser.removeAllListeners("up");
114
+ // multicastDNS.destroy();
115
+ // callback();
116
+ // }
117
+ // };
118
+ // browser.on("up", onUp);
119
+ // }
120
+ // function waitServiceDown(serviceConfig: ServiceConfig, callback: () => void) {
121
+ // const multicastDNS = new Bonjour();
122
+ // const browser = multicastDNS.find({
123
+ // protocol: "tcp",
124
+ // type: "opcua-tcp"
125
+ // });
126
+ // const onDown = (service: Service) => {
127
+ // if (doDebug) {
128
+ // debugLog(chalk.cyan(" waitServiceDown down with ", serviceToString(service)));
129
+ // }
130
+ // if (isSameService(service, serviceConfig)) {
131
+ // browser.removeAllListeners("down");
132
+ // multicastDNS.destroy();
133
+ // callback();
134
+ // }
135
+ // };
136
+ // browser.on("down", onDown);
137
+ // }
138
+ function _announceServerOnMulticastSubnet(multicastDNS, serviceConfig) {
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ return new Promise((resolve, reject) => {
141
+ const port = serviceConfig.port;
142
+ (0, node_opcua_assert_1.assert)(typeof port === "number");
143
+ (0, node_opcua_assert_1.assert)(multicastDNS, "bonjour must have been initialized?");
144
+ debugLog(chalk.cyan(" announceServerOnMulticastSubnet", (0, exports.serviceToString)(serviceConfig)));
145
+ // waitServiceUp(serviceConfig, () => {
146
+ // // istanbul ignore next
147
+ // if (doDebug) {
148
+ // debugLog(chalk.cyan(" announcedOnMulticastSubnet done ", serviceToString(serviceConfig)));
149
+ // }
150
+ // // resolve(service);
151
+ // });
152
+ const service = multicastDNS.publish(Object.assign(Object.assign({}, serviceConfig), { probe: false }));
153
+ service.on("error", (err) => {
154
+ debugLog("bonjour ERROR received ! ", err.message);
155
+ debugLog("params = ", serviceConfig);
156
+ });
157
+ service.on("up", () => {
158
+ debugLog("_announceServerOnMulticastSubnet: bonjour UP received ! ", (0, exports.serviceToString)(serviceConfig));
159
+ resolve(service);
160
+ });
161
+ service.start();
162
+ });
163
+ });
164
+ }
165
+ exports._announceServerOnMulticastSubnet = _announceServerOnMulticastSubnet;
166
+ class BonjourHolder {
167
+ constructor() {
168
+ this.pendingAnnouncement = false;
169
+ }
170
+ /**
171
+ *
172
+ * @param announcement
173
+ * @returns
174
+ */
175
+ announcedOnMulticastSubnet(announcement) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ debugLog(chalk.yellow("\n\nentering announcedOnMulticastSubnet"));
178
+ const serviceConfig = announcementToServiceConfig(announcement);
179
+ if (this._service && this.serviceConfig) {
180
+ // verify that Announcement has changed
181
+ if (isSameService(serviceConfig, this.serviceConfig)) {
182
+ debugLog(" Announcement ignored as it has been already made", announcement.name);
183
+ debugLog("exiting announcedOnMulticastSubnet-2", false);
184
+ return false; // nothing changed
185
+ }
186
+ }
187
+ (0, node_opcua_assert_1.assert)(!this._multicastDNS, "already called ?");
188
+ this._multicastDNS = acquireBonjour();
189
+ this.pendingAnnouncement = true;
190
+ this.serviceConfig = serviceConfig;
191
+ this._service = yield _announceServerOnMulticastSubnet(this._multicastDNS, serviceConfig);
192
+ this.pendingAnnouncement = false;
193
+ debugLog(chalk.yellow("exiting announcedOnMulticastSubnet-3", true));
194
+ return true;
195
+ });
196
+ }
197
+ isStarted() {
198
+ return !!this._multicastDNS;
199
+ }
200
+ /**
201
+ *
202
+ * @param announcement
203
+ * @param callback
204
+ * @private
205
+ */
206
+ announcedOnMulticastSubnetWithCallback(announcement, callback) {
207
+ callback(new Error("Internal Error"));
208
+ }
209
+ /**
210
+ * @private
211
+ */
212
+ stopAnnnouncedOnMulticastSubnet() {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ if (this.pendingAnnouncement) {
215
+ debugLog(chalk.bgWhite.redBright("stopAnnnouncedOnMulticastSubnet is pending : let's wait a little bit and try again"));
216
+ // wait until announcement is done
217
+ yield new Promise((resolve) => setTimeout(resolve, 500));
218
+ return this.stopAnnnouncedOnMulticastSubnet();
219
+ }
220
+ debugLog(chalk.green("\n\nentering stop_announcedOnMulticastSubnet = ", this.serviceConfig ? (0, exports.serviceToString)(this.serviceConfig) : "<null>"));
221
+ if (!this._service) {
222
+ debugLog(chalk.green("leaving stop_announcedOnMulticastSubnet = no service"));
223
+ return;
224
+ }
225
+ // due to a wrong declaration of Service.stop in the d.ts file we
226
+ // need to use a workaround here
227
+ const that_service = this._service;
228
+ const that_multicastDNS = this._multicastDNS;
229
+ this._service = undefined;
230
+ this._multicastDNS = undefined;
231
+ this.serviceConfig = undefined;
232
+ const proxy = (callback) => {
233
+ if (that_multicastDNS && that_service.stop) {
234
+ // waitServiceDown(that_service, () => {
235
+ // debugLog(chalk.green("stop_announcedOnMulticastSubnet, ", serviceToString(that_service)));
236
+ // });
237
+ that_service.stop((err) => {
238
+ debugLog(chalk.green("service stopped err=", err));
239
+ that_multicastDNS.unpublishAll(() => {
240
+ releaseBonjour(that_multicastDNS, () => {
241
+ callback();
242
+ });
243
+ });
244
+ });
245
+ return;
246
+ }
247
+ else {
248
+ callback();
249
+ }
250
+ };
251
+ const stop = (0, util_1.promisify)(proxy);
252
+ yield stop.call(this);
253
+ debugLog(chalk.green("leaving stop_announcedOnMulticastSubnet = done"));
254
+ debugLog(chalk.green("leaving stop_announcedOnMulticastSubnet stop announcement completed"));
255
+ });
256
+ }
257
+ stopAnnouncedOnMulticastSubnetWithCallback(callback) {
258
+ callback(new Error("Internal Error"));
259
+ }
260
+ }
261
+ exports.BonjourHolder = BonjourHolder;
262
+ BonjourHolder.prototype.announcedOnMulticastSubnetWithCallback = (0, util_1.callbackify)(BonjourHolder.prototype.announcedOnMulticastSubnet);
263
+ BonjourHolder.prototype.stopAnnouncedOnMulticastSubnetWithCallback = (0, util_1.callbackify)(BonjourHolder.prototype.stopAnnnouncedOnMulticastSubnet);
264
264
  //# sourceMappingURL=bonjour.js.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- /**
2
- * @module node-opcua-service-discovery
3
- */
4
- export { RegisteredServer, RegisterServerRequest, RegisterServerResponse, MdnsDiscoveryConfiguration, RegisterServer2Request, RegisterServer2Response, RegisterServerRequestOptions, RegisterServer2RequestOptions, FindServersRequest, FindServersRequestOptions, FindServersResponse, FindServersOnNetworkRequest, FindServersOnNetworkRequestOptions, FindServersOnNetworkResponse, ServerOnNetwork } from "node-opcua-types";
5
- export { serverCapabilities } from "./server_capabilities";
6
- export { Announcement, BonjourHolder, isSameService as sameService, _announceServerOnMulticastSubnet, announcementToServiceConfig, serviceToString, } from "./bonjour";
1
+ /**
2
+ * @module node-opcua-service-discovery
3
+ */
4
+ export { RegisteredServer, RegisterServerRequest, RegisterServerResponse, MdnsDiscoveryConfiguration, RegisterServer2Request, RegisterServer2Response, RegisterServerRequestOptions, RegisterServer2RequestOptions, FindServersRequest, FindServersRequestOptions, FindServersResponse, FindServersOnNetworkRequest, FindServersOnNetworkRequestOptions, FindServersOnNetworkResponse, ServerOnNetwork } from "node-opcua-types";
5
+ export { serverCapabilities } from "./server_capabilities";
6
+ export { Announcement, BonjourHolder, isSameService as sameService, _announceServerOnMulticastSubnet, announcementToServiceConfig, serviceToString, } from "./bonjour";
package/dist/index.js CHANGED
@@ -1,27 +1,27 @@
1
- "use strict";
2
- /**
3
- * @module node-opcua-service-discovery
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.serviceToString = exports.announcementToServiceConfig = exports._announceServerOnMulticastSubnet = exports.sameService = exports.BonjourHolder = exports.serverCapabilities = exports.ServerOnNetwork = exports.FindServersOnNetworkResponse = exports.FindServersOnNetworkRequest = exports.FindServersResponse = exports.FindServersRequest = exports.RegisterServer2Response = exports.RegisterServer2Request = exports.MdnsDiscoveryConfiguration = exports.RegisterServerResponse = exports.RegisterServerRequest = exports.RegisteredServer = void 0;
7
- var node_opcua_types_1 = require("node-opcua-types");
8
- Object.defineProperty(exports, "RegisteredServer", { enumerable: true, get: function () { return node_opcua_types_1.RegisteredServer; } });
9
- Object.defineProperty(exports, "RegisterServerRequest", { enumerable: true, get: function () { return node_opcua_types_1.RegisterServerRequest; } });
10
- Object.defineProperty(exports, "RegisterServerResponse", { enumerable: true, get: function () { return node_opcua_types_1.RegisterServerResponse; } });
11
- Object.defineProperty(exports, "MdnsDiscoveryConfiguration", { enumerable: true, get: function () { return node_opcua_types_1.MdnsDiscoveryConfiguration; } });
12
- Object.defineProperty(exports, "RegisterServer2Request", { enumerable: true, get: function () { return node_opcua_types_1.RegisterServer2Request; } });
13
- Object.defineProperty(exports, "RegisterServer2Response", { enumerable: true, get: function () { return node_opcua_types_1.RegisterServer2Response; } });
14
- Object.defineProperty(exports, "FindServersRequest", { enumerable: true, get: function () { return node_opcua_types_1.FindServersRequest; } });
15
- Object.defineProperty(exports, "FindServersResponse", { enumerable: true, get: function () { return node_opcua_types_1.FindServersResponse; } });
16
- Object.defineProperty(exports, "FindServersOnNetworkRequest", { enumerable: true, get: function () { return node_opcua_types_1.FindServersOnNetworkRequest; } });
17
- Object.defineProperty(exports, "FindServersOnNetworkResponse", { enumerable: true, get: function () { return node_opcua_types_1.FindServersOnNetworkResponse; } });
18
- Object.defineProperty(exports, "ServerOnNetwork", { enumerable: true, get: function () { return node_opcua_types_1.ServerOnNetwork; } });
19
- var server_capabilities_1 = require("./server_capabilities");
20
- Object.defineProperty(exports, "serverCapabilities", { enumerable: true, get: function () { return server_capabilities_1.serverCapabilities; } });
21
- var bonjour_1 = require("./bonjour");
22
- Object.defineProperty(exports, "BonjourHolder", { enumerable: true, get: function () { return bonjour_1.BonjourHolder; } });
23
- Object.defineProperty(exports, "sameService", { enumerable: true, get: function () { return bonjour_1.isSameService; } });
24
- Object.defineProperty(exports, "_announceServerOnMulticastSubnet", { enumerable: true, get: function () { return bonjour_1._announceServerOnMulticastSubnet; } });
25
- Object.defineProperty(exports, "announcementToServiceConfig", { enumerable: true, get: function () { return bonjour_1.announcementToServiceConfig; } });
26
- Object.defineProperty(exports, "serviceToString", { enumerable: true, get: function () { return bonjour_1.serviceToString; } });
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-service-discovery
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.serviceToString = exports.announcementToServiceConfig = exports._announceServerOnMulticastSubnet = exports.sameService = exports.BonjourHolder = exports.serverCapabilities = exports.ServerOnNetwork = exports.FindServersOnNetworkResponse = exports.FindServersOnNetworkRequest = exports.FindServersResponse = exports.FindServersRequest = exports.RegisterServer2Response = exports.RegisterServer2Request = exports.MdnsDiscoveryConfiguration = exports.RegisterServerResponse = exports.RegisterServerRequest = exports.RegisteredServer = void 0;
7
+ var node_opcua_types_1 = require("node-opcua-types");
8
+ Object.defineProperty(exports, "RegisteredServer", { enumerable: true, get: function () { return node_opcua_types_1.RegisteredServer; } });
9
+ Object.defineProperty(exports, "RegisterServerRequest", { enumerable: true, get: function () { return node_opcua_types_1.RegisterServerRequest; } });
10
+ Object.defineProperty(exports, "RegisterServerResponse", { enumerable: true, get: function () { return node_opcua_types_1.RegisterServerResponse; } });
11
+ Object.defineProperty(exports, "MdnsDiscoveryConfiguration", { enumerable: true, get: function () { return node_opcua_types_1.MdnsDiscoveryConfiguration; } });
12
+ Object.defineProperty(exports, "RegisterServer2Request", { enumerable: true, get: function () { return node_opcua_types_1.RegisterServer2Request; } });
13
+ Object.defineProperty(exports, "RegisterServer2Response", { enumerable: true, get: function () { return node_opcua_types_1.RegisterServer2Response; } });
14
+ Object.defineProperty(exports, "FindServersRequest", { enumerable: true, get: function () { return node_opcua_types_1.FindServersRequest; } });
15
+ Object.defineProperty(exports, "FindServersResponse", { enumerable: true, get: function () { return node_opcua_types_1.FindServersResponse; } });
16
+ Object.defineProperty(exports, "FindServersOnNetworkRequest", { enumerable: true, get: function () { return node_opcua_types_1.FindServersOnNetworkRequest; } });
17
+ Object.defineProperty(exports, "FindServersOnNetworkResponse", { enumerable: true, get: function () { return node_opcua_types_1.FindServersOnNetworkResponse; } });
18
+ Object.defineProperty(exports, "ServerOnNetwork", { enumerable: true, get: function () { return node_opcua_types_1.ServerOnNetwork; } });
19
+ var server_capabilities_1 = require("./server_capabilities");
20
+ Object.defineProperty(exports, "serverCapabilities", { enumerable: true, get: function () { return server_capabilities_1.serverCapabilities; } });
21
+ var bonjour_1 = require("./bonjour");
22
+ Object.defineProperty(exports, "BonjourHolder", { enumerable: true, get: function () { return bonjour_1.BonjourHolder; } });
23
+ Object.defineProperty(exports, "sameService", { enumerable: true, get: function () { return bonjour_1.isSameService; } });
24
+ Object.defineProperty(exports, "_announceServerOnMulticastSubnet", { enumerable: true, get: function () { return bonjour_1._announceServerOnMulticastSubnet; } });
25
+ Object.defineProperty(exports, "announcementToServiceConfig", { enumerable: true, get: function () { return bonjour_1.announcementToServiceConfig; } });
26
+ Object.defineProperty(exports, "serviceToString", { enumerable: true, get: function () { return bonjour_1.serviceToString; } });
27
27
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- /**
2
- * @module node-opcua-service-discovery
3
- */
4
- export declare const serverCapabilities: string[];
1
+ /**
2
+ * @module node-opcua-service-discovery
3
+ */
4
+ export declare const serverCapabilities: string[];
@@ -1,27 +1,27 @@
1
- "use strict";
2
- /**
3
- * @module node-opcua-service-discovery
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.serverCapabilities = void 0;
7
- // see most up to date version at http://www.opcfoundation.org/UA/schemas/1.04/ServerCapabilities.csv
8
- exports.serverCapabilities = [
9
- "NA",
10
- "DA",
11
- "HD",
12
- "AC",
13
- "HE",
14
- "GDS",
15
- "LDS",
16
- "DI",
17
- "ADI",
18
- "FDI",
19
- "FDIC",
20
- "PLC",
21
- "S95",
22
- // new in 1.04
23
- "RCP",
24
- "PUB",
25
- "SUB", // Supports the Publisher capabilities defined in Part 14.
26
- ];
1
+ "use strict";
2
+ /**
3
+ * @module node-opcua-service-discovery
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.serverCapabilities = void 0;
7
+ // see most up to date version at http://www.opcfoundation.org/UA/schemas/1.04/ServerCapabilities.csv
8
+ exports.serverCapabilities = [
9
+ "NA",
10
+ "DA",
11
+ "HD",
12
+ "AC",
13
+ "HE",
14
+ "GDS",
15
+ "LDS",
16
+ "DI",
17
+ "ADI",
18
+ "FDI",
19
+ "FDIC",
20
+ "PLC",
21
+ "S95",
22
+ // new in 1.04
23
+ "RCP",
24
+ "PUB",
25
+ "SUB", // Supports the Publisher capabilities defined in Part 14.
26
+ ];
27
27
  //# sourceMappingURL=server_capabilities.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-opcua-service-discovery",
3
- "version": "2.76.0",
3
+ "version": "2.76.2",
4
4
  "description": "pure nodejs OPCUA SDK - module -service-discovery",
5
5
  "scripts": {
6
6
  "build": "tsc -b",
@@ -13,9 +13,9 @@
13
13
  "dependencies": {
14
14
  "chalk": "4.1.2",
15
15
  "node-opcua-assert": "2.76.0",
16
- "node-opcua-debug": "2.76.0",
17
- "node-opcua-object-registry": "2.76.0",
18
- "node-opcua-types": "2.76.0",
16
+ "node-opcua-debug": "2.76.2",
17
+ "node-opcua-object-registry": "2.76.2",
18
+ "node-opcua-types": "2.76.2",
19
19
  "sterfive-bonjour-service": "1.1.4"
20
20
  },
21
21
  "author": "Etienne Rossignon",
@@ -33,5 +33,5 @@
33
33
  "internet of things"
34
34
  ],
35
35
  "homepage": "http://node-opcua.github.io/",
36
- "gitHead": "75d9b8cf894c8fbadf77d2c4a48a730d055465e7"
36
+ "gitHead": "acb5ecaf1e1c71af3b63e80909d58447f3f298e7"
37
37
  }