From a13d3b6e15d3e44269f14bc0229ddf1f9f7a358f Mon Sep 17 00:00:00 2001 From: slavikbialik Date: Sun, 28 Feb 2021 17:28:34 +0200 Subject: [PATCH 1/2] Add `onAck` delegation for Session --- src/api/ack.ts | 15 +++++++++++++++ src/api/index.ts | 1 + src/api/session-delegate.ts | 7 +++++++ src/api/session.ts | 7 +++++++ 4 files changed, 30 insertions(+) create mode 100644 src/api/ack.ts diff --git a/src/api/ack.ts b/src/api/ack.ts new file mode 100644 index 000000000..3fc3c4285 --- /dev/null +++ b/src/api/ack.ts @@ -0,0 +1,15 @@ +import { IncomingRequestMessage, IncomingAckRequest } from "../core"; + +/** + * A request to end a {@link Session} (incoming ACK). + * @public + */ +export class Ack { + /** @internal */ + public constructor(private incomingAckRequest: IncomingAckRequest) {} + + /** Incoming ACK request message. */ + public get request(): IncomingRequestMessage { + return this.incomingAckRequest.message; + } +} \ No newline at end of file diff --git a/src/api/index.ts b/src/api/index.ts index 88daf1474..7a318eec5 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -3,6 +3,7 @@ * @packageDocumentation */ export * from "./exceptions"; +export * from "./ack"; export * from "./bye"; export * from "./emitter"; export * from "./info"; diff --git a/src/api/session-delegate.ts b/src/api/session-delegate.ts index cde5ab583..0a3f492ce 100644 --- a/src/api/session-delegate.ts +++ b/src/api/session-delegate.ts @@ -1,4 +1,5 @@ import { IncomingRequestMessage } from "../core"; +import { Ack } from "./ack"; import { Bye } from "./bye"; import { Info } from "./info"; import { Message } from "./message"; @@ -11,6 +12,12 @@ import { SessionDescriptionHandler } from "./session-description-handler"; * @public */ export interface SessionDelegate { + /** + * Called upon receiving an incoming in dialog ACK request. + * @param ack - The ack. + */ + onAck?(ack: Ack): void; + /** * Called upon receiving an incoming in dialog BYE request. * @param bye - The bye. diff --git a/src/api/session.ts b/src/api/session.ts index 17cc9f254..91f0183cb 100644 --- a/src/api/session.ts +++ b/src/api/session.ts @@ -29,6 +29,7 @@ import { } from "../core"; import { getReasonPhrase } from "../core/messages/utils"; import { AllowedMethods } from "../core/user-agent-core/allowed-methods"; +import { Ack } from "./ack"; import { Bye } from "./bye"; import { Emitter, EmitterImpl } from "./emitter"; import { ContentTypeUnsupportedError, RequestPendingError } from "./exceptions"; @@ -793,6 +794,12 @@ export abstract class Session { : this._sessionDescriptionHandlerModifiers }; + if (this.delegate && this.delegate.onAck) + { + const ack = new Ack(request); + this.delegate.onAck(ack); + } + // reset pending ACK flag this.pendingReinviteAck = false; From 71fa1a031603e917a627d16d977adbde3ca6ddd4 Mon Sep 17 00:00:00 2001 From: Slavik Bialik Date: Sun, 28 Feb 2021 20:02:00 +0200 Subject: [PATCH 2/2] code lint-fix --- src/api/ack.ts | 2 +- src/api/session.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/api/ack.ts b/src/api/ack.ts index 3fc3c4285..2344448cb 100644 --- a/src/api/ack.ts +++ b/src/api/ack.ts @@ -12,4 +12,4 @@ export class Ack { public get request(): IncomingRequestMessage { return this.incomingAckRequest.message; } -} \ No newline at end of file +} diff --git a/src/api/session.ts b/src/api/session.ts index 91f0183cb..f9090fcdf 100644 --- a/src/api/session.ts +++ b/src/api/session.ts @@ -794,10 +794,9 @@ export abstract class Session { : this._sessionDescriptionHandlerModifiers }; - if (this.delegate && this.delegate.onAck) - { - const ack = new Ack(request); - this.delegate.onAck(ack); + if (this.delegate && this.delegate.onAck) { + const ack = new Ack(request); + this.delegate.onAck(ack); } // reset pending ACK flag