Skip to content

Commit

Permalink
feat(*): test removal of _ prefix in resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierapivideo committed Jan 5, 2024
1 parent 15b4742 commit c3c50b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/NativeApiVideoLiveStreamView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import type {
} from 'react-native/Libraries/Types/CodegenTypes';
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';

// Type can't start with a digit so we prefix it with an underscore.
export type NativeResolution = '_240p' | '_360p' | '_480p' | '_720p' | '_1080p';
export type NativeResolution = '240p' | '360p' | '480p' | '720p' | '1080p';
export type Camera = 'front' | 'back';

export type OnConnectionFailedEvent = Readonly<{
Expand All @@ -21,7 +20,7 @@ export interface NativeLiveStreamProps extends ViewProps {
video: {
bitrate: Int32;
fps: Int32;
resolution?: WithDefault<NativeResolution, '_720p'>;
resolution?: WithDefault<NativeResolution, '720p'>;
gopDuration: Float;
};
isMuted: boolean;
Expand Down
21 changes: 6 additions & 15 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const LIVE_STREAM_PROPS_DEFAULTS: NativeLiveStreamProps = {
video: {
bitrate: 2000000,
fps: 30,
resolution: '_720p',
resolution: '720p',
gopDuration: 1,
},
isMuted: false,
Expand All @@ -57,7 +57,7 @@ export type ApiVideoLiveStreamMethods = {
setZoomRatio: (zoomRatio: number) => void;
};

const getDefaultBitrate = (resolution: Resolution): number => {
const getDefaultBitrate = (resolution: NativeResolution): number => {
switch (resolution) {
case '240p':
return 800000;
Expand All @@ -72,29 +72,20 @@ const getDefaultBitrate = (resolution: Resolution): number => {
}
};

const convertNativeResolutionToResolution = (
resolution: NativeResolution
): Resolution => {
return resolution.replace('_', '') as Resolution;
};

const ApiVideoLiveStreamView = forwardRef<
ApiVideoLiveStreamMethods,
ApiVideoLiveStreamProps
>((props, forwardedRef) => {
const nativeResolution =
props.video?.resolution || LIVE_STREAM_PROPS_DEFAULTS.video.resolution!;
const nativeLiveStreamProps: NativeLiveStreamProps = {
...LIVE_STREAM_PROPS_DEFAULTS,
...props,
video: {
...LIVE_STREAM_PROPS_DEFAULTS.video,
bitrate: getDefaultBitrate(
props.video?.resolution ||
convertNativeResolutionToResolution(
LIVE_STREAM_PROPS_DEFAULTS.video?.resolution || '_720p'
)
),
resolution: '_720p', // TODO convert resolution to native
bitrate: getDefaultBitrate(nativeResolution),
...props.video,
resolution: props.video?.resolution!,
},
audio: {
...LIVE_STREAM_PROPS_DEFAULTS.audio,
Expand Down

0 comments on commit c3c50b3

Please sign in to comment.