@@ -8,6 +8,7 @@ import NativeApiVideoLiveStreamView, {
8
8
OnConnectionFailedEvent,
9
9
OnPermissionsDeniedEvent,
10
10
OnStartStreamingEvent,
11
+ PredefinedResolution,
11
12
} from './NativeApiVideoLiveStreamView';
12
13
13
14
type ApiVideoLiveStreamProps = {
@@ -16,7 +17,7 @@ type ApiVideoLiveStreamProps = {
16
17
video?: {
17
18
bitrate?: number;
18
19
fps?: number;
19
- resolution?: Resolution;
20
+ resolution?: Resolution | PredefinedResolution ;
20
21
gopDuration?: number;
21
22
};
22
23
isMuted?: boolean;
@@ -76,20 +77,42 @@ const getDefaultBitrate = (resolution: Resolution): number => {
76
77
}
77
78
};
78
79
80
+
81
+ function resolveResolution(resolution: Resolution | PredefinedResolution): Resolution {
82
+ const predefinedResolutions: Record<PredefinedResolution, Resolution> = {
83
+ "1080p": { width: 1920, height: 1080 },
84
+ "720p": { width: 1280, height: 720 },
85
+ "480p": { width: 858, height: 480 },
86
+ "360p": { width: 640, height: 360 },
87
+ "240p": { width: 352, height: 240 },
88
+ };
89
+
90
+ if (typeof resolution === "string") {
91
+ const predefined = predefinedResolutions[resolution];
92
+ if (!predefined) {
93
+ throw new Error("Unknown resolution");
94
+ }
95
+ return predefined;
96
+ }
97
+ return {
98
+ width: Math.max(resolution.height, resolution.width),
99
+ height: Math.min(resolution.height, resolution.width),
100
+ };
101
+ }
102
+
79
103
const ApiVideoLiveStreamView = forwardRef<
80
104
ApiVideoLiveStreamMethods,
81
105
ApiVideoLiveStreamProps
82
106
>((props, forwardedRef) => {
107
+ const resolution = resolveResolution(props.video?.resolution || "720p")
83
108
const nativeLiveStreamProps: NativeLiveStreamProps = {
84
109
...LIVE_STREAM_PROPS_DEFAULTS,
85
110
...props,
86
111
video: {
87
112
...LIVE_STREAM_PROPS_DEFAULTS.video,
88
- bitrate: getDefaultBitrate(
89
- props.video?.resolution || { width: 1280, height: 720 }
90
- ),
91
- resolution: { width: 1280, height: 720 },
113
+ bitrate: getDefaultBitrate(resolution),
92
114
...props.video,
115
+ resolution,
93
116
},
94
117
audio: {
95
118
...LIVE_STREAM_PROPS_DEFAULTS.audio,
@@ -193,5 +216,5 @@ const ApiVideoLiveStreamView = forwardRef<
193
216
);
194
217
});
195
218
196
- export * from './types';
197
219
export { ApiVideoLiveStreamView };
220
+ export type { Resolution, PredefinedResolution} from './NativeApiVideoLiveStreamView';
0 commit comments