How to use node-opcua-service-discovery - 10 common examples

To help you get started, we’ve selected a few node-opcua-service-discovery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-server-discovery / src / opcua_discovery_server.js View on Github external
// },
            debugLog("a new OPCUA server has been registered");

            const recordId = ++this.recordId;
            const serverName = service.name;

            service.txt.caps = service.txt.caps || "";
            let serverCapabilities = service.txt.caps.split(",").map(x => x.toUpperCase()).sort();

            assert(serverCapabilities instanceof Array);

            const path = service.txt.path || "";
            const discoveryUrl = "opc.tcp://" + service.host + ":" + service.port + path;

            this.registeredServers.push(
                new discovery_service.ServerOnNetwork({
                    recordId: recordId,
                    serverName: serverName,
                    discoveryUrl: discoveryUrl,
                    serverCapabilities: serverCapabilities
                }));
            this.lastUpdateDate = new Date(Date.now());
        };
github node-opcua / node-opcua / packages / node-opcua-server-discovery / source / opcua_discovery_server.ts View on Github external
): Promise {

            let b = ((conf as any).bonjourHolder) as BonjourHolder;
            if (b) {
                if (sameAnnouncement(b.announcement!, announcement)) {
                    debugLog("Configuration ", conf.mdnsServerName, " has not changed !");
                    // nothing to do
                    return;
                } else {
                    debugLog("Configuration ", conf.mdnsServerName, " HAS changed !");
                    debugLog(" Was ", b.announcement!);
                    debugLog(" is  ", announcement);
                }
                await _stop_announcedOnMulticastSubnet(conf);
            }
            b = new BonjourHolder();
            ((conf as any).bonjourHolder) = b;
            await b._announcedOnMulticastSubnet(announcement);
        }
github node-opcua / node-opcua / packages / node-opcua-server-discovery / source / opcua_discovery_server.ts View on Github external
const defaultApplicationUri = makeApplicationUrn("%FQDN%", "NodeOPCUA-DiscoveryServer");

        options.serverInfo = options.serverInfo || {};
        const serverInfo = options.serverInfo;
        serverInfo.applicationType = ApplicationType.DiscoveryServer;
        serverInfo.applicationUri = serverInfo.applicationUri || defaultApplicationUri;
        serverInfo.productUri = serverInfo.productUri || "NodeOPCUA-DiscoveryServer";
        serverInfo.applicationName = serverInfo.applicationName || { text: "NodeOPCUA-DiscoveryServer", locale: null };
        serverInfo.gatewayServerUri = serverInfo.gatewayServerUri || "";
        serverInfo.discoveryProfileUri = serverInfo.discoveryProfileUri || "";
        serverInfo.discoveryUrls = serverInfo.discoveryUrls || [];

        super(options);

        this.bonjourHolder = new BonjourHolder();

        const port = options.port || 4840;

        this.capabilitiesForMDNS = ["LDS"];
        this.registeredServers = {};

        this.mDnsResponder = undefined;

        // see OPC UA Spec 1.2 part 6 : 7.4 Well Known Addresses
        // opc.tcp://localhost:4840/UADiscovery

        this._delayInit = () => {
            const endPoint = new OPCUAServerEndPoint({
                port,

                certificateChain: this.getCertificateChain(),
github node-opcua / node-opcua / packages / node-opcua-server / src / register_server_manager.js View on Github external
// the applicationUri from the ApplicationDescription defined in 7.1.
            serverUri: server.serverInfo.applicationUri,

            // The globally unique identifier for the Server product.
            productUri: server.serverInfo.productUri,
            serverNames: [
                {locale: "en", text: server.serverInfo.productName}
            ],
            serverType: server.serverType,
            gatewayServerUri: null,
            discoveryUrls: discoveryUrls,
            semaphoreFilePath: null,
            isOnline: isOnline
        },
        discoveryConfiguration: [
            new discovery_service.MdnsDiscoveryConfiguration({
                mdnsServerName: server.serverInfo.applicationUri,
                serverCapabilities: server.capabilitiesForMDNS
            })
        ]
    });

    return request;
}
github node-opcua / node-opcua / packages / node-opcua-server-discovery / source / opcua_discovery_server.ts View on Github external
private async __internalRegisterServer(
      RegisterServerXResponse: any /* RegisterServer2Response | RegisterServerResponse */,
      rawServer: RegisteredServer,
      discoveryConfigurations?: MdnsDiscoveryConfiguration[]
    ): Promise {

        const server = rawServer as any as RegisteredServerExtended;

        if (!discoveryConfigurations) {
            discoveryConfigurations = [new MdnsDiscoveryConfiguration({
                mdnsServerName: undefined,
                serverCapabilities: ["NA"]
            })];
        }

        function sendError(statusCode: StatusCode): Response {
            debugLog(chalk.red("_on_RegisterServer(2)Request error"), statusCode.toString());
            const response1 = new RegisterServerXResponse({
                responseHeader: { serviceResult: statusCode }
            });
            return response1;
        }

        async function _stop_announcedOnMulticastSubnet(conf: MdnsDiscoveryConfiguration): Promise {
            const b = ((conf as any).bonjourHolder) as BonjourHolder;
            await b._stop_announcedOnMulticastSubnet();
github node-opcua / node-opcua / packages / node-opcua-server / source / register_server_manager.ts View on Github external
function constructRegisterServer2Request(
  server: any,
  isOnline: boolean
): RegisterServer2Request {

    const discoveryUrls = server.getDiscoveryUrls();
    assert(!isOnline || discoveryUrls.length >= 1, "expecting some discoveryUrls if we go online ....");

    return new RegisterServer2Request({

        server: {
            // The globally unique identifier for the Server instance. The serverUri matches
            // the applicationUri from the ApplicationDescription defined in 7.1.
            serverUri: server.serverInfo.applicationUri,

            // The globally unique identifier for the Server product.
            productUri: server.serverInfo.productUri,
            serverNames: [
                { locale: "en", text: server.serverInfo.productName }
            ],
            serverType: server.serverType,

            discoveryUrls,
            gatewayServerUri: null,
            isOnline,
github node-opcua / node-opcua / packages / node-opcua-server-discovery / src / opcua_discovery_server.js View on Github external
server.discoveryConfiguration = discoveryConfiguration;


        if (discoveryConfiguration) {

            const endpointUrl = serverInfo.discoveryUrls[0];
            const parsedUrl = url.parse(endpointUrl);

            const options ={
                applicationUri: serverInfo.applicationUri,
                port: parseInt(parsedUrl.port,10),
                path: parsedUrl.pathname || "/",
                capabilities: server.discoveryConfiguration.serverCapabilities || [ "DA" ]
            };
            // let's announce the server on the  mutlicast DNS
            server.bonjourEntry = _announceServerOnMulticastSubnet(discoveryServer.bonjour, options);
        }
        discoveryServer.registered_servers[key].serverInfo = serverInfo;

    } else {
        if (key in  discoveryServer.registered_servers) {
            const server  = discoveryServer.registered_servers[key];
            debugLog(chalk.cyan("unregistering server : "), server.serverUri.yellow);
            if (server.bonjourEntry) {
                server.bonjourEntry.stop();
                server.bonjourEntry = null;
            }
            delete  discoveryServer.registered_servers[key];
        }

    }
github node-opcua / node-opcua / packages / node-opcua-server-discovery / source / opcua_discovery_server.ts View on Github external
async function _announcedOnMulticastSubnet(
          conf: MdnsDiscoveryConfiguration,
          announcement: Announcement
        ): Promise {

            let b = ((conf as any).bonjourHolder) as BonjourHolder;
            if (b) {
                if (sameAnnouncement(b.announcement!, announcement)) {
                    debugLog("Configuration ", conf.mdnsServerName, " has not changed !");
                    // nothing to do
                    return;
                } else {
                    debugLog("Configuration ", conf.mdnsServerName, " HAS changed !");
                    debugLog(" Was ", b.announcement!);
                    debugLog(" is  ", announcement);
                }
                await _stop_announcedOnMulticastSubnet(conf);
            }
            b = new BonjourHolder();
            ((conf as any).bonjourHolder) = b;
            await b._announcedOnMulticastSubnet(announcement);
        }
github node-opcua / node-opcua / packages / node-opcua-server-discovery / source / opcua_discovery_server.ts View on Github external
if (this.mDnsResponder) {
            for (const server of this.mDnsResponder.registeredServers) {
                if (server.recordId <= request.startingRecordId) {
                    continue;
                }
                if (!hasCapabilities(server.serverCapabilities, serverCapabilityFilter)) {
                    continue;
                }
                servers.push(server);
                if (servers.length === request.maxRecordsToReturn) {
                    break;
                }
            }
        }
        const response = new FindServersOnNetworkResponse({
            lastCounterResetTime, //  UtcTime The last time the counters were reset
            servers
        });
        channel.send_response("MSG", response, message);

    }
github node-opcua / node-opcua / packages / node-opcua-server / src / base_server.js View on Github external
return filename;
}

const debugLog = require("node-opcua-debug").make_debugLog(__filename);

const StatusCodes = require("node-opcua-status-code").StatusCodes;

const endpoints_service = require("node-opcua-service-endpoints");
const GetEndpointsResponse = endpoints_service.GetEndpointsResponse;
const ApplicationType = endpoints_service.ApplicationType;

const OPCUASecureObject = require("node-opcua-common").OPCUASecureObject;


const discovery_service = require("node-opcua-service-discovery");
const FindServersRequest = discovery_service.FindServersRequest;
const FindServersResponse = discovery_service.FindServersResponse;
const LocalizedText = require("node-opcua-data-model").LocalizedText;

const default_server_info = {

    // The globally unique identifier for the application instance. This URI is used as
    // ServerUri in Services if the application is a Server.
    applicationUri: "urn:NodeOPCUA-Server-default",

    // The globally unique identifier for the product.
    productUri: "NodeOPCUA-Server",

    // A localized descriptive name for the application.
    applicationName: {text: "NodeOPCUA", locale: null},
    applicationType: ApplicationType.Server,
    gatewayServerUri: "",