Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 });
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;
}
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);
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);
}
const results = subscriptionAcknowledgements.map(function (subscriptionAcknowledgement) {
const subscription = self.getSubscriptionById(subscriptionAcknowledgement.subscriptionId);
if (!subscription) {
return StatusCodes.BadSubscriptionIdInvalid;
}
return subscription.acknowledgeNotification(subscriptionAcknowledgement.sequenceNumber);
});
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;
};
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);
});
};
(subscriptionAcknowledgement: SubscriptionAcknowledgement) => {
const subscription = this.getSubscriptionById(subscriptionAcknowledgement.subscriptionId);
if (!subscription) {
return StatusCodes.BadSubscriptionIdInvalid;
}
return subscription.acknowledgeNotification(subscriptionAcknowledgement.sequenceNumber);
});