Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onAck delegation for Session #911

Merged
merged 3 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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