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");
subscription.$session._unexposeSubscriptionDiagnostics(subscription);
ServerSidePublishEngine.transferSubscription(subscription, session.publishEngine, sendInitialValues);
subscription.$session = session;
session._exposeSubscriptionDiagnostics(subscription);
assert(subscription.publishEngine === session.publishEngine);
assert(session.publishEngine.subscriptionCount === nbSubscriptionBefore + 1);
// TODO: If the Server transfers the Subscription to the new Session, the Server shall issue a
// StatusChangeNotification notificationMessage with the status code Good_SubscriptionTransferred
// to the old Session.
const result = new TransferResult({
availableSequenceNumbers: subscription.getAvailableSequenceNumbers(),
statusCode: StatusCodes.Good
});
// istanbul ignore next
if (doDebug) {
debugLog("TransferResult", result.toString());
}
return result;
}
const nbSubscriptionBefore = session.publishEngine.subscriptionCount;
subscription.$session._unexposeSubscriptionDiagnostics(subscription);
ServerSidePublishEngine.transferSubscription(subscription, session.publishEngine, sendInitialValues);
subscription.$session = session;
session._exposeSubscriptionDiagnostics(subscription);
assert(subscription.publishEngine === session.publishEngine);
assert(session.publishEngine.subscriptionCount === nbSubscriptionBefore + 1);
// TODO: If the Server transfers the Subscription to the new Session, the Server shall issue a
// StatusChangeNotification notificationMessage with the status code Good_SubscriptionTransferred
// to the old Session.
const result = new TransferResult({
statusCode: StatusCodes.Good,
availableSequenceNumbers: subscription.getAvailableSequenceNumbers()
});
// istanbul ignore next
if (doDebug) {
debugLog("TransferResult", result.toString());
}
return result;
};