node-opcua-server-discovery 2.156.0 → 2.158.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.
@@ -1,13 +1,11 @@
1
1
  import { ServerOnNetwork } from "node-opcua-service-discovery";
2
2
  export declare class MDNSResponder {
3
+ #private;
3
4
  /**
4
5
  * the list of servers that have been activated as mDNS service
5
6
  */
6
7
  registeredServers: ServerOnNetwork[];
7
- private multicastDNS;
8
- private browser;
9
- private recordId;
10
8
  lastUpdateDate: Date;
11
9
  constructor();
12
- dispose(): void;
10
+ dispose(): Promise<void>;
13
11
  }
@@ -8,17 +8,24 @@ const sterfive_bonjour_service_1 = require("sterfive-bonjour-service");
8
8
  const node_opcua_debug_1 = require("node-opcua-debug");
9
9
  const node_opcua_object_registry_1 = require("node-opcua-object-registry");
10
10
  const node_opcua_service_discovery_1 = require("node-opcua-service-discovery");
11
- const debugLog = (0, node_opcua_debug_1.make_debugLog)(__filename);
12
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)(__filename) || true;
11
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)("LDSSERVER");
12
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("LDSSERVER") || true;
13
13
  const registry = new node_opcua_object_registry_1.ObjectRegistry();
14
14
  class MDNSResponder {
15
+ /**
16
+ * the list of servers that have been activated as mDNS service
17
+ */
18
+ registeredServers;
19
+ #bonjour;
20
+ #mDNSBrowser;
21
+ #recordId;
22
+ lastUpdateDate = new Date();
15
23
  constructor() {
16
- this.lastUpdateDate = new Date();
17
24
  registry.register(this);
18
25
  this.registeredServers = [];
19
- this.multicastDNS = new sterfive_bonjour_service_1.Bonjour();
20
- this.recordId = 0;
21
- this.browser = this.multicastDNS.find({
26
+ this.#bonjour = new sterfive_bonjour_service_1.Bonjour();
27
+ this.#recordId = 0;
28
+ this.#mDNSBrowser = this.#bonjour.find({
22
29
  protocol: "tcp",
23
30
  type: "opcua-tcp"
24
31
  });
@@ -54,8 +61,8 @@ class MDNSResponder {
54
61
  debugLog("Ignoring existing server ", service.name);
55
62
  return;
56
63
  }
57
- this.recordId++;
58
- const recordId = this.recordId;
64
+ this.#recordId++;
65
+ const recordId = this.#recordId;
59
66
  const serverName = service.name;
60
67
  service.txt = service.txt || {};
61
68
  const service_txt = service.txt;
@@ -86,21 +93,32 @@ class MDNSResponder {
86
93
  this.registeredServers.splice(index, 1); // remove element at index
87
94
  this.lastUpdateDate = new Date();
88
95
  };
89
- this.browser.on("up", (service) => {
96
+ this.#mDNSBrowser.on("up", (service) => {
90
97
  // istanbul ignore next
91
98
  doDebug && debugLog("MDNSResponder : service is up with ", (0, node_opcua_service_discovery_1.serviceToString)(service));
92
99
  addService(service);
100
+ // console.log("records " , JSON.stringify(service.records()));
93
101
  });
94
- this.browser.on("down", (service) => {
102
+ this.#mDNSBrowser.on("down", (service) => {
95
103
  // istanbul ignore next
96
104
  doDebug && debugLog("MDNSResponder : service is down with ", (0, node_opcua_service_discovery_1.serviceToString)(service));
97
105
  removeService(service);
98
106
  });
99
107
  }
100
- dispose() {
101
- // yy delete (this as any).multicastDNS;
102
- this.multicastDNS.destroy();
108
+ async dispose() {
109
+ if (this.#mDNSBrowser) {
110
+ this.#mDNSBrowser.stop();
111
+ this.#mDNSBrowser = undefined;
112
+ }
113
+ await new Promise((resolve) => {
114
+ this.#bonjour.unpublishAll(() => {
115
+ this.#bonjour.destroy(() => {
116
+ resolve();
117
+ });
118
+ });
119
+ });
103
120
  registry.unregister(this);
121
+ await new Promise((resolve) => setTimeout(resolve, 100));
104
122
  }
105
123
  }
106
124
  exports.MDNSResponder = MDNSResponder;
@@ -1 +1 @@
1
- {"version":3,"file":"mdns_responder.js","sourceRoot":"","sources":["../source/mdns_responder.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,uEAAqE;AACrE,uDAAiE;AACjE,2EAA4D;AAC5D,+EAAgF;AAEhF,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,UAAU,C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E,CAAC;YACzB,IAAI,CAAC,YAAY,GAAG,SAAU,CAAC;QACnC,CAAC;QACD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAChC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,GAAG,EAAE;gBAC5B,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE;oBACvB,OAAO,EAAE,CAAC;gBACd,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC1B,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IACnE,CAAC;CACJ;AAlID,sCAkIC"}
@@ -1,12 +1,11 @@
1
1
  /**
2
2
  * @module node-opcua-server-discovery
3
3
  */
4
- import { Message, MessageSecurityMode, Response, SecurityPolicy, ServerSecureChannelLayer } from "node-opcua-secure-channel";
4
+ import { Message, MessageSecurityMode, SecurityPolicy, ServerSecureChannelLayer } from "node-opcua-secure-channel";
5
5
  import { OPCUABaseServer, OPCUABaseServerOptions } from "node-opcua-server";
6
6
  import { BonjourHolder, MdnsDiscoveryConfiguration, RegisteredServer } from "node-opcua-service-discovery";
7
7
  import { ApplicationDescription } from "node-opcua-service-endpoints";
8
8
  import { ApplicationDescriptionOptions } from "node-opcua-service-endpoints";
9
- import { ErrorCallback } from "node-opcua-status-code";
10
9
  import { MDNSResponder } from "./mdns_responder";
11
10
  export interface OPCUADiscoveryServerOptions extends OPCUABaseServerOptions {
12
11
  certificateFile?: string;
@@ -21,19 +20,22 @@ interface RegisteredServerExtended extends RegisteredServer {
21
20
  serverInfo: ApplicationDescriptionOptions;
22
21
  discoveryConfiguration?: MdnsDiscoveryConfiguration[];
23
22
  }
24
- interface RegisterServerMap {
25
- [key: string]: RegisteredServerExtended;
23
+ type RegisterServerMap = Map<string, RegisteredServerExtended>;
24
+ export interface OPCUADiscoveryServer {
25
+ on(eventName: "onUnregisterServer", eventHandler: (server: RegisteredServer, forced: boolean) => void): this;
26
+ on(eventName: "onRegisterServer", eventHandler: (server: RegisteredServer, firstTime: boolean) => void): this;
27
+ once(eventName: "onUnregisterServer", eventHandler: (server: RegisteredServer, forced: boolean) => void): this;
28
+ once(eventName: "onRegisterServer", eventHandler: (server: RegisteredServer, firstTime: boolean) => void): this;
26
29
  }
27
30
  export declare class OPCUADiscoveryServer extends OPCUABaseServer {
31
+ #private;
32
+ private mDnsLDSAnnouncer?;
28
33
  mDnsResponder?: MDNSResponder;
29
34
  readonly registeredServers: RegisterServerMap;
30
- private bonjourHolder;
31
35
  private _delayInit?;
32
36
  constructor(options: OPCUADiscoveryServerOptions);
33
37
  start(): Promise<void>;
34
- start(callback: ErrorCallback): void;
35
38
  shutdown(): Promise<void>;
36
- shutdown(callback: ErrorCallback): void;
37
39
  /**
38
40
  * returns the number of registered servers
39
41
  */
@@ -42,7 +44,5 @@ export declare class OPCUADiscoveryServer extends OPCUABaseServer {
42
44
  protected _on_RegisterServer2Request(message: Message, channel: ServerSecureChannelLayer): void;
43
45
  protected _on_RegisterServerRequest(message: Message, channel: ServerSecureChannelLayer): void;
44
46
  protected _on_FindServersOnNetworkRequest(message: Message, channel: ServerSecureChannelLayer): void;
45
- protected __internalRegisterServerWithCallback(RegisterServerXResponse: any, rawServer: RegisteredServer, discoveryConfigurations: MdnsDiscoveryConfiguration[] | undefined, callback: (err: Error | null, response?: Response) => void): Promise<void>;
46
- protected __internalRegisterServer(RegisterServerXResponse: any, rawServer: RegisteredServer, discoveryConfigurations?: MdnsDiscoveryConfiguration[]): Promise<Response>;
47
47
  }
48
48
  export {};