How to use the node-opcua-client.OPCUAClientBase.create function in node-opcua-client

To help you get started, we’ve selected a few node-opcua-client 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 / source / register_server_manager.ts View on Github external
public _establish_initial_connection(outer_callback: EmptyCallback) {

        if (!this.server) {
            throw  new Error("Internal Error");
        }
        debugLog("RegisterServerManager#_establish_initial_connection");

        assert(!this._registration_client);
        assert(typeof this.discoveryServerEndpointUrl === "string");
        assert(this.state === RegisterServerManagerStatus.INACTIVE);
        this._setState(RegisterServerManagerStatus.INITIALIZING);
        this.selectedEndpoint = null;

        // Retry Strategy must be set
        const client = OPCUAClientBase.create({
            certificateFile: this.server.certificateFile,
            clientName: "RegistrationClient-1",
            connectionStrategy: infinite_connectivity_strategy,
            privateKeyFile: this.server.privateKeyFile
        });

        this._registration_client = client;

        client.on("backoff", (nretry: number, delay: number) => {
            debugLog("RegisterServerManager - received backoff");
            console.log(
              chalk.bgWhite.yellow("contacting discovery server backoff "),
              this.discoveryServerEndpointUrl, " attempt #",
              nretry, " retrying in ", delay / 1000.0, " seconds");
            this._emitEvent("serverRegistrationPending");
        });
github node-opcua / node-opcua / packages / node-opcua-server / src / register_server_manager.js View on Github external
RegisterServerManager.prototype._establish_initial_connection = function (outer_callback) {

    debugLog("RegisterServerManager#_establish_initial_connection");

    const self = this;
    assert(!self._registration_client);
    assert(typeof self.discoveryServerEndpointUrl === "string");
    assert(self.state === RegisterServerManagerStatus.INACTIVE);
    self._setState(RegisterServerManagerStatus.INITIALIZING);
    self.selectedEndpoint = null;

    // Retry Strategy must be set
    let client = OPCUAClientBase.create({
        clientName: "RegistrationClient-1",
        certificateFile: self.server.certificateFile,
        privateKeyFile: self.server.privateKeyFile,
        connectionStrategy: infinite_connectivity_strategy,
    });

    self._registration_client = client;

    client.on("backoff", function (number, delay) {
        debugLog("RegisterServerManager - received backoff");
        console.log("contacting discovery server backoff  attempt #".bgWhite.yellow, number, " retrying in ", delay / 1000.0, " seconds");
        self._emitEvent("serverRegistrationPending");
    });

    async.series([
github node-opcua / node-opcua / packages / node-opcua-server / source / register_server_manager.ts View on Github external
return outer_callback(new Error("Cannot registerServer"));
        }

        const options = {
            securityMode: selectedEndpoint.securityMode,
            securityPolicy: coerceSecurityPolicy(selectedEndpoint.securityPolicyUri),
            serverCertificate: selectedEndpoint.serverCertificate,

            certificateFile: server.certificateFile,
            privateKeyFile: server.privateKeyFile,

            clientName: "RegistrationClient-2",
            connectionStrategy: no_reconnect_connectivity_strategy
        };

        const client = OPCUAClientBase.create(options);

        const tmp = this._serverEndpoints;
        (client as any)._serverEndpoints = tmp;
        (server as any)._registration_client = client;

        const theStatus = isOnline
          ? RegisterServerManagerStatus.REGISTERING
          : RegisterServerManagerStatus.UNREGISTERING;
        this._setState(theStatus);

        debugLog("                      lds endpoint uri : ", selectedEndpoint.endpointUrl);

        async.series([
            // establish_connection_with_lds
            (callback: EmptyCallback) => {
github node-opcua / node-opcua / packages / node-opcua-server / src / register_server_manager.js View on Github external
return outer_callback(new Error("Cannot registerServer"));
    }

    const options = {
        securityMode: selectedEndpoint.securityMode,
        securityPolicy: coerceSecurityPolicy(selectedEndpoint.securityPolicyUri),
        serverCertificate: selectedEndpoint.serverCertificate,
        certificateFile: server.certificateFile,
        privateKeyFile: server.privateKeyFile,
        connectionStrategy: no_reconnect_connectivity_strategy,
        clientName: "RegistrationClient-2"
    };

    const tmp = self._serverEndpoints;

    let client = OPCUAClientBase.create(options);
    client._serverEndpoints = tmp;
    server._registration_client = client;

    const theStatus =isOnline ? RegisterServerManagerStatus.REGISTERING :RegisterServerManagerStatus.UNREGISTERING;
    self._setState(theStatus);

    debugLog("                      lds endpoint uri : ",selectedEndpoint.endpointUrl);

    async.series([
        function establish_connection_with_lds(callback) {
            client.connect(selectedEndpoint.endpointUrl, function (err) {
                debugLog("establish_connection_with_lds => errr = ",err);
                if (err) {
                    debugLog("RegisterServerManager#_registerServer connection to client has failed");
                    debugLog("RegisterServerManager#_registerServer  => please check that you server certificate is trusted by the LDS");
                    console.log("RegisterServer to the LDS  has failed during secure connection  => please check that you server certificate is trusted by the LDS. err: "+ err.message);