How to use the node-opcua-status-code.StatusCodes.BadSubscriptionIdInvalid function in node-opcua-status-code

To help you get started, we’ve selected a few node-opcua-status-code 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 / server_engine.ts View on Github external
public transferSubscription(
    session: ServerSession,
    subscriptionId: number,
    sendInitialValues: boolean): TransferResult {

    assert(session instanceof ServerSession);
    assert(_.isNumber(subscriptionId));
    assert(_.isBoolean(sendInitialValues));

    if (subscriptionId <= 0) {
      return new TransferResult({ statusCode: StatusCodes.BadSubscriptionIdInvalid });
    }

    const subscription = this.findSubscription(subscriptionId);
    if (!subscription) {
      return new TransferResult({ statusCode: StatusCodes.BadSubscriptionIdInvalid });
    }
    if (!subscription.$session) {
      return new TransferResult({ statusCode: StatusCodes.BadInternalError });
    }

    // update diagnostics 
    subscription.subscriptionDiagnostics.transferRequestCount++;

    // now check that new session has sufficient right
    // if (session.authenticationToken.toString() !== subscription.authenticationToken.toString()) {
    //     console.log("ServerEngine#transferSubscription => BadUserAccessDenied");
    //     return new TransferResult({ statusCode: StatusCodes.BadUserAccessDenied });
    // }
    if (session.publishEngine === subscription.publishEngine) {
      // subscription is already in this session !!
      return new TransferResult({ statusCode: StatusCodes.BadNothingToDo });
github node-opcua / node-opcua / packages / node-opcua-server / source / server_session.ts View on Github external
public deleteSubscription(subscriptionId: number): StatusCode {

        const session = this;
        const subscription = session.getSubscription(subscriptionId);
        if (!subscription) {
            return StatusCodes.BadSubscriptionIdInvalid;
        }

        // xx this.publishEngine.remove_subscription(subscription);
        subscription.terminate();

        if (session.currentSubscriptionCount === 0) {

            const local_publishEngine = session.publishEngine;
            local_publishEngine.cancelPendingPublishRequest();
        }
        return StatusCodes.Good;
    }
github node-opcua / node-opcua / packages / node-opcua-client / source / reconnection.ts View on Github external
const results = transferSubscriptionsResponse.results || [];

                    // istanbul ignore next
                    if (doDebug) {
                        debugLog(chalk.cyan("    =>  transfer subscriptions  done"),
                            results.map((x: any) => x.statusCode.toString()).join(" "));
                    }

                    const subscriptionsToRecreate = [];

                    // some subscriptions may be marked as invalid on the server side ...
                    // those one need to be recreated and repaired ....
                    for (let i = 0; i < results.length; i++) {

                        const statusCode = results[i].statusCode;
                        if (statusCode === StatusCodes.BadSubscriptionIdInvalid) {

                            // repair subscription
                            debugLog(chalk.red("         WARNING SUBSCRIPTION  "),
                                subscriptionsIds[i], chalk.red(" SHOULD BE RECREATED"));

                            subscriptionsToRecreate.push(subscriptionsIds[i]);
                        } else {
                            const availableSequenceNumbers = results[i].availableSequenceNumbers;

                            debugLog(chalk.green("         SUBSCRIPTION "), subscriptionsIds[i],
                                chalk.green(" CAN BE REPAIRED AND AVAILABLE "), availableSequenceNumbers);
                            // should be Good.
                        }
                    }
                    debugLog("  new session subscriptionCount = ", newSession.getPublishEngine().subscriptionCount);
github node-opcua / node-opcua / packages / node-opcua-server / src / server_engine.js View on Github external
const session = context.session;
    if (!session) {
        return callback(null, {statusCode: StatusCodes.BadInternalError});
    }

    const subscriptionId = inputArguments[0].value;
    const subscription = session.getSubscription(subscriptionId);
    if (!subscription) {
        // subscription may belongs to a different session  that ours
        if (engine.findSubscription(subscriptionId)) {
            // if yes, then access to  Subscription data should be denied
            return callback(null, {statusCode: StatusCodes.BadUserAccessDenied});
        }

        return callback(null, {statusCode: StatusCodes.BadSubscriptionIdInvalid});
    }
    const result = subscription.getMonitoredItems();
    assert(result.statusCode);
    assert(_.isArray(result.serverHandles));
    assert(_.isArray(result.clientHandles));
    assert(result.serverHandles.length === result.clientHandles.length);
    const callMethodResult = new CallMethodResult({
        statusCode: result.statusCode,
        outputArguments: [
            {dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: result.serverHandles},
            {dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: result.clientHandles}
        ]
    });
    callback(null, callMethodResult);

}
github node-opcua / node-opcua / packages / node-opcua-server / src / server_publish_engine.js View on Github external
const results = subscriptionAcknowledgements.map(function (subscriptionAcknowledgement) {

        const subscription = self.getSubscriptionById(subscriptionAcknowledgement.subscriptionId);
        if (!subscription) {
            return StatusCodes.BadSubscriptionIdInvalid;
        }
        return subscription.acknowledgeNotification(subscriptionAcknowledgement.sequenceNumber);
    });
github node-opcua / node-opcua / packages / node-opcua-server / src / server_session.js View on Github external
ServerSession.prototype.deleteSubscription = function (subscriptionId) {

    const session = this;
    const subscription = session.getSubscription(subscriptionId);
    if (!subscription) {
        return StatusCodes.BadSubscriptionIdInvalid;
    }

    //xx this.publishEngine.remove_subscription(subscription);
    subscription.terminate();

    if (session.currentSubscriptionCount === 0) {

        const local_publishEngine = session.publishEngine;
        local_publishEngine.cancelPendingPublishRequest();
    }
    return StatusCodes.Good;
};
github node-opcua / node-opcua / packages / node-opcua-server / src / opcua_server.js View on Github external
this._apply_on_SessionObject(ResponseClass, message, channel, function (session, sendResponse, sendError) {
        const subscription = session.getSubscription(request.subscriptionId);
        if (!subscription) {
            return sendError(StatusCodes.BadSubscriptionIdInvalid);
        }
        subscription.resetLifeTimeAndKeepAliveCounters();
        action_to_perform(session, subscription, sendResponse, sendError);
    });
};
github node-opcua / node-opcua / packages / node-opcua-server / source / server_publish_engine.ts View on Github external
(subscriptionAcknowledgement: SubscriptionAcknowledgement) => {

              const subscription = this.getSubscriptionById(subscriptionAcknowledgement.subscriptionId);
              if (!subscription) {
                  return StatusCodes.BadSubscriptionIdInvalid;
              }
              return subscription.acknowledgeNotification(subscriptionAcknowledgement.sequenceNumber);
          });