Skip to content

Commit

Permalink
feat: add option to allow ice candidate prefetching (#396)
Browse files Browse the repository at this point in the history
* feat: add option to allow ice candidate prefetching

* chore: add docs for prefetchIceCandidates option
  • Loading branch information
farhat-ha authored Nov 14, 2024
1 parent 9cc84ac commit 5a6165a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/js/src/Modules/Verto/util/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IVertoOptions {

debug?: boolean;
debugOutput?: 'socket' | 'file';
prefetchIceCandidates?: boolean;
}
export interface SubscribeParams {
channels?: string[];
Expand Down
3 changes: 2 additions & 1 deletion packages/js/src/Modules/Verto/webrtc/Peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,11 @@ export default class Peer {
}

private _config(): RTCConfiguration {
const { iceServers = [] } = this.options;
const { iceServers = [], prefetchIceCandidates } = this.options;

const config: RTCConfiguration = {
bundlePolicy: 'max-compat',
iceCandidatePoolSize: prefetchIceCandidates ? 10 : 0,
iceServers,
};

Expand Down
1 change: 1 addition & 0 deletions packages/js/src/Modules/Verto/webrtc/VertoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class VertoHandler {
mediaSettings: params.mediaSettings,
debug: session.options.debug ?? false,
debugOutput: session.options.debugOutput ?? 'socket',
prefetchIceCandidates: session.options.prefetchIceCandidates ?? false,
};

if (params.telnyx_call_control_id) {
Expand Down
1 change: 1 addition & 0 deletions packages/js/src/Modules/Verto/webrtc/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface IVertoCallOptions {
debug?: boolean;
debugOutput?: 'socket' | 'file';
preferred_codecs?: RTCRtpCodecCapability[];
prefetchIceCandidates?: boolean;
}

export interface IStatsBinding {
Expand Down
12 changes: 12 additions & 0 deletions packages/js/src/TelnyxRTC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ export class TelnyxRTC extends TelnyxRTCClient {
* preferred_codecs: [PCMACodec],
* });
* ```
*
* ### ICE Candidate Prefetching
*
* ICE candidate prefetching can be enabled by passing `prefetchIceCandidates` to the `newCall` method.
* example:
* ```js
* client.newCall({
* destinationNumber: 'xxx',
* prefetchIceCandidates: true,
* });
* ```
*
*/
newCall(options: ICallOptions) {
return super.newCall(options);
Expand Down
21 changes: 21 additions & 0 deletions packages/js/src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ export interface IClientOptions {
* "Generate Ringback Tone" in your SIP Connection.
*/
ringbackFile?: string;

/**
* Enable debug mode for this client.
* This will gather WebRTC debugging information.
*/
debug?: boolean;

/**
* Debug output option
*/
debugOutput?: 'socket' | 'file';

/**
* Enable or disable prefetching ICE candidates.
*/
prefetchIceCandidates?: boolean;
}

export interface ISIPCallOptions {
Expand Down Expand Up @@ -201,6 +217,11 @@ export interface ICallOptions {
* Preferred codecs for the call.
*/
preferred_codecs?: RTCRtpCodecCapability[];

/**
* Enable or disable ICE Candidate Prefetching.
*/
prefetchIceCandidates?: boolean;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/react-client/src/useTelnyxRTC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { TelnyxRTC, IClientOptions } from '@telnyx/webrtc';

type TokenCredential = {
login_token: string;
debug?: boolean
debug?: boolean;
};

type UsernameCredential = {
login: string;
password: string;
debug?: boolean
debug?: boolean;
};

export type CredentialOptions = TokenCredential | UsernameCredential;
Expand Down

0 comments on commit 5a6165a

Please sign in to comment.