Skip to content

Commit

Permalink
Merge pull request #911 from reporty/feature/REP-44855
Browse files Browse the repository at this point in the history
Add `onAck` delegation for Session
  • Loading branch information
James Criscuolo authored Mar 16, 2021
2 parents 709bed2 + dd958af commit fd54a59
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/api/ack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IncomingRequestMessage, IncomingAckRequest } from "../core";

/**
* A request to confirm 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;
}
}
1 change: 1 addition & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @packageDocumentation
*/
export * from "./exceptions";
export * from "./ack";
export * from "./bye";
export * from "./emitter";
export * from "./info";
Expand Down
7 changes: 7 additions & 0 deletions src/api/session-delegate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IncomingRequestMessage } from "../core";
import { Ack } from "./ack";
import { Bye } from "./bye";
import { Info } from "./info";
import { Message } from "./message";
Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/api/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -793,6 +794,11 @@ 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;

Expand Down

0 comments on commit fd54a59

Please sign in to comment.