@expo/serve-sim 0.1.43 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/middleware.js +46 -46
- package/dist/native/serve-sim-native.node +0 -0
- package/dist/serve-sim.js +78 -78
- package/package.json +1 -1
- package/src/stream-settings.ts +53 -1
package/package.json
CHANGED
package/src/stream-settings.ts
CHANGED
|
@@ -97,16 +97,26 @@ const STREAM_ENCODER_SETTING_KEYS = new Set<keyof StreamEncoderSettings>([
|
|
|
97
97
|
"h264Fps",
|
|
98
98
|
]);
|
|
99
99
|
|
|
100
|
+
const WEBRTC_ENCODER_SETTING_KEYS = new Set<keyof StreamEncoderSettings>([
|
|
101
|
+
"maxDimension",
|
|
102
|
+
"h264Bitrate",
|
|
103
|
+
"h264Fps",
|
|
104
|
+
]);
|
|
105
|
+
|
|
100
106
|
/** Validate an untrusted PATCH body without silently accepting typos or wrong types. */
|
|
101
107
|
export function parseStreamEncoderSettingsPatch(
|
|
102
108
|
input: unknown,
|
|
109
|
+
transport?: StreamPlaybackSettings["transport"],
|
|
103
110
|
): Partial<StreamEncoderSettings> | null {
|
|
104
111
|
if (!input || typeof input !== "object" || Array.isArray(input)) return null;
|
|
105
112
|
const patch = input as Record<string, unknown>;
|
|
106
113
|
const keys = Object.keys(patch);
|
|
114
|
+
const allowedKeys = transport === "webrtc"
|
|
115
|
+
? WEBRTC_ENCODER_SETTING_KEYS
|
|
116
|
+
: STREAM_ENCODER_SETTING_KEYS;
|
|
107
117
|
if (
|
|
108
118
|
keys.length === 0
|
|
109
|
-
|| keys.some((key) => !
|
|
119
|
+
|| keys.some((key) => !allowedKeys.has(key as keyof StreamEncoderSettings))
|
|
110
120
|
) {
|
|
111
121
|
return null;
|
|
112
122
|
}
|
|
@@ -165,6 +175,30 @@ export function streamEncoderSettingsFrom(
|
|
|
165
175
|
};
|
|
166
176
|
}
|
|
167
177
|
|
|
178
|
+
export function streamEncoderSettingsForTransport(
|
|
179
|
+
settings: StreamEncoderSettings,
|
|
180
|
+
transport: StreamPlaybackSettings["transport"],
|
|
181
|
+
): Partial<StreamEncoderSettings> {
|
|
182
|
+
if (transport === "webrtc") {
|
|
183
|
+
return {
|
|
184
|
+
maxDimension: settings.maxDimension,
|
|
185
|
+
h264Bitrate: settings.h264Bitrate,
|
|
186
|
+
h264Fps: settings.h264Fps,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
mjpegFps: settings.mjpegFps,
|
|
191
|
+
mjpegQuality: settings.mjpegQuality,
|
|
192
|
+
maxDimension: settings.maxDimension,
|
|
193
|
+
h264Bitrate: settings.h264Bitrate,
|
|
194
|
+
h264Fps: settings.h264Fps,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function isWebRtcTransportLocked(settings: StreamSettings | undefined): boolean {
|
|
199
|
+
return settings?.transport === "webrtc";
|
|
200
|
+
}
|
|
201
|
+
|
|
168
202
|
export function streamControlSettingsFrom(
|
|
169
203
|
settings: StreamSettings | undefined,
|
|
170
204
|
): StreamControlSettings {
|
|
@@ -199,6 +233,24 @@ export function mergeStreamControlSettings(
|
|
|
199
233
|
return normalizeStreamControlSettings({ ...current, ...patch }, current);
|
|
200
234
|
}
|
|
201
235
|
|
|
236
|
+
export function mergeStreamPlaybackSettings(
|
|
237
|
+
current: StreamControlSettings,
|
|
238
|
+
patch: Partial<StreamPlaybackSettings>,
|
|
239
|
+
transportLocked = false,
|
|
240
|
+
): StreamControlSettings {
|
|
241
|
+
if (!transportLocked) return mergeStreamControlSettings(current, patch);
|
|
242
|
+
|
|
243
|
+
const lockedPatch: Partial<StreamPlaybackSettings> = {};
|
|
244
|
+
if (patch.webRtcCodec !== undefined) lockedPatch.webRtcCodec = patch.webRtcCodec;
|
|
245
|
+
if (patch.iceServers !== undefined) lockedPatch.iceServers = patch.iceServers;
|
|
246
|
+
if (Object.keys(lockedPatch).length === 0) return current;
|
|
247
|
+
|
|
248
|
+
return mergeStreamControlSettings(current, {
|
|
249
|
+
...lockedPatch,
|
|
250
|
+
transport: "webrtc",
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
202
254
|
/** Apply shared encoder controls without replacing viewer-local playback values. */
|
|
203
255
|
export function mergeStreamEncoderSettings(
|
|
204
256
|
current: StreamControlSettings,
|