Skip to content

Commit

Permalink
feat: support target resolution overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlaz committed Dec 4, 2024
1 parent daf2071 commit 77b2fce
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion sample-apps/react/react-dogfood/helpers/axiosApiTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
AxiosResponseTransformer,
default as axios,
} from 'axios';
import { JoinCallRequest, JoinCallResponse } from '@stream-io/video-react-sdk';
import {
GetOrCreateCallResponse,
JoinCallRequest,
JoinCallResponse,
} from '@stream-io/video-react-sdk';

const cascadingTransformer: AxiosRequestTransformer =
/**
Expand Down Expand Up @@ -115,6 +119,32 @@ const sfuOverrideTransformer: AxiosResponseTransformer =
return data;
};

const targetResolutionOverrideTransformer: AxiosResponseTransformer =
/**
* This transformer is used to override the target resolution returned by the
* backend with the one provided in the URL query params.
*
* Useful for testing with a specific target resolution.
*
* Note: it needs to be declared as a `function` instead of an arrow function
* as it executes in the context of the current axios instance.
*/
function targetResolutionOverrideTransformer(data: GetOrCreateCallResponse) {
if (typeof window !== 'undefined') {
const params = new URLSearchParams(window.location.search);
const width = params.get('width') || params.get('w');
const height = params.get('height') || params.get('h');
if (width && height && data?.call?.settings?.video?.target_resolution) {
data.call.settings.video.target_resolution = {
...data.call.settings.video.target_resolution,
width: parseInt(width, 10),
height: parseInt(height, 10),
};
}
}
return data;
};

/**
* Default request transformers.
*/
Expand All @@ -130,4 +160,5 @@ export const defaultRequestTransformers: AxiosRequestTransformer[] = [
export const defaultResponseTransformers: AxiosResponseTransformer[] = [
...(axios.defaults.transformResponse as AxiosResponseTransformer[]),
sfuOverrideTransformer,
targetResolutionOverrideTransformer,
];

0 comments on commit 77b2fce

Please sign in to comment.