Skip to content

Commit

Permalink
chore: restore overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlaz committed Nov 14, 2024
1 parent fd81f09 commit 4f8121e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
30 changes: 18 additions & 12 deletions packages/client/src/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ export class Call {
clientDetails,
fastReconnect: performingFastReconnect,
reconnectDetails,
preferredPublishOptions: this.getPreferredCodec(
preferredPublishOptions: this.getPreferredCodecs(
publishingCapabilitiesSdp,
),
});
Expand Down Expand Up @@ -908,23 +908,29 @@ export class Call {
* This is an experimental client feature and subject to change.
* @internal
*/
private getPreferredCodec = (sdp: string): PublishOption[] => {
const { preferredCodec } = this.clientPublishOptions || {};
if (!preferredCodec) return [];
private getPreferredCodecs = (sdp: string): PublishOption[] => {
const { preferredCodec, preferredBitrate, maxSimulcastLayers } =
this.clientPublishOptions || {};
if (!preferredCodec || !preferredBitrate || !maxSimulcastLayers) return [];

let sfuCodec: Codec | undefined;
const codec = findCodec(`video/${preferredCodec}`);
if (!codec) return [];
if (codec) {
const { clockRate, mimeType, sdpFmtpLine } = codec;
sfuCodec = Codec.create({
name: preferredCodec, // e.g. 'vp9'
fmtp: sdpFmtpLine || '',
clockRate: clockRate,
payloadType: getPayloadTypeForCodec(sdp, mimeType, sdpFmtpLine),
});
}

const { clockRate, mimeType, sdpFmtpLine } = codec;
return [
PublishOption.create({
trackType: TrackType.VIDEO,
codec: Codec.create({
name: preferredCodec, // e.g. 'vp9'
fmtp: sdpFmtpLine || '',
clockRate: clockRate,
payloadType: getPayloadTypeForCodec(sdp, mimeType, sdpFmtpLine),
}),
codec: sfuCodec,
bitrate: preferredBitrate,
maxSpatialLayers: maxSimulcastLayers,
}),
];
};
Expand Down
8 changes: 8 additions & 0 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ export type ClientPublishOptions = {
* The preferred codec to use when publishing the video stream.
*/
preferredCodec?: PreferredCodec;
/**
* The preferred bitrate to use when publishing the video stream.
*/
preferredBitrate?: number;
/**
* The maximum number of simulcast layers to use when publishing the video stream.
*/
maxSimulcastLayers?: number;
/**
* Screen share settings.
*/
Expand Down
3 changes: 3 additions & 0 deletions sample-apps/react-native/dogfood/src/components/MeetingUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export const MeetingUI = ({ callId, navigation, route }: Props) => {
const onJoinCallHandler = useCallback(async () => {
try {
setShow('loading');
call?.updatePublishOptions({
preferredCodec: 'vp9',
});
await call?.join({ create: true });
appStoreSetState({ chatLabelNoted: false });
setShow('active-call');
Expand Down
13 changes: 12 additions & 1 deletion sample-apps/react/react-dogfood/components/MeetingUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,25 @@ export const MeetingUI = ({ chatClient, mode }: MeetingUIProps) => {
const videoCodecOverride = router.query['video_codec'] as
| PreferredCodec
| undefined;
const bitrateOverride = router.query['bitrate'] as string | undefined;
const maxSimulcastLayers = router.query['max_simulcast_layers'] as
| string
| undefined;

const onJoin = useCallback(
async ({ fastJoin = false } = {}) => {
if (!fastJoin) setShow('loading');
if (!call) throw new Error('No active call found');
try {
const preferredBitrate = bitrateOverride
? parseInt(bitrateOverride, 10)
: undefined;
call.updatePublishOptions({
preferredCodec: videoCodecOverride || 'vp9',
preferredBitrate,
maxSimulcastLayers: maxSimulcastLayers
? parseInt(maxSimulcastLayers, 10)
: 3, // default to 3
});
await call.join({ create: true });
setShow('active-call');
Expand All @@ -66,7 +77,7 @@ export const MeetingUI = ({ chatClient, mode }: MeetingUIProps) => {
setShow('error-join');
}
},
[call, videoCodecOverride],
[bitrateOverride, call, maxSimulcastLayers, videoCodecOverride],
);

const onLeave = useCallback(
Expand Down

0 comments on commit 4f8121e

Please sign in to comment.