Skip to content

Commit

Permalink
feat: set codec preferences on answer
Browse files Browse the repository at this point in the history
  • Loading branch information
farhat-ha committed Jun 10, 2024
1 parent 946649f commit fe4258b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/js/src/Modules/Verto/webrtc/BaseCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ export default abstract class BaseCall implements IWebRTCCall {
customHeaders: params.customHeaders,
};
}
if (params.preferred_codecs?.length > 0) {
this.options.preferred_codecs = params.preferred_codecs;
}

this.peer = new Peer(PeerType.Answer, this.options, this.session);
await this.peer.iceGatheringComplete.promise;
Expand Down
4 changes: 2 additions & 2 deletions packages/js/src/Modules/Verto/webrtc/Peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ export default class Peer {
}

private _setAudioCodec = (transceiver: RTCRtpTransceiver) => {
if (!this.options.codecs || this.options.codecs.length === 0) {
if (!this.options.preferred_codecs || this.options.preferred_codecs.length === 0) {
return;
}
if (transceiver.setCodecPreferences) {
return transceiver.setCodecPreferences(this.options.codecs);
return transceiver.setCodecPreferences(this.options.preferred_codecs);
}
};
/** Workaround for ReactNative: first time SDP has no candidates */
Expand Down
3 changes: 2 additions & 1 deletion packages/js/src/Modules/Verto/webrtc/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface IVertoCallOptions {
customHeaders?: Array<{ name: string; value: string }>;
debug?: boolean;
debugOutput?: 'socket' | 'file';
codecs?: RTCRtpCodecCapability[];
preferred_codecs?: RTCRtpCodecCapability[];
}

export interface IStatsBinding {
Expand All @@ -57,6 +57,7 @@ export interface IStatsBinding {

export interface AnswerParams {
customHeaders?: Array<{ name: string; value: string }>;
preferred_codecs?: Array<RTCRtpCodecCapability>;
}

export interface IWebRTCCall {
Expand Down
15 changes: 15 additions & 0 deletions packages/js/src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ export interface ICallOptions {
* Add custom headers to the INVITE and ANSWER request.
*/
customHeaders?: { name: string; value: string }[];

/**
* Enable debug mode for this call.
*/
debug?: boolean;

/**
* Output debug logs to a file.
*/
debugOutput?: 'socket' | 'file';

/**
* Preferred codecs for the call.
*/
preferred_codecs?: RTCRtpCodecCapability[];
}

/**
Expand Down

0 comments on commit fe4258b

Please sign in to comment.