@expo/serve-sim 0.1.36 → 0.1.37
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 +14 -0
- package/dist/middleware.js +24 -24
- package/dist/native/serve-sim-native.node +0 -0
- package/dist/serve-sim.js +66 -66
- package/package.json +1 -1
- package/src/middleware.ts +37 -0
- package/src/stream-settings.ts +16 -2
package/package.json
CHANGED
package/src/middleware.ts
CHANGED
|
@@ -1768,6 +1768,43 @@ export function simMiddleware(options?: SimMiddlewareOptions): SimMiddleware {
|
|
|
1768
1768
|
return;
|
|
1769
1769
|
}
|
|
1770
1770
|
|
|
1771
|
+
if (url === base + "/healthz") {
|
|
1772
|
+
res.writeHead(200, {
|
|
1773
|
+
"Content-Type": "application/json",
|
|
1774
|
+
"Cache-Control": "no-store",
|
|
1775
|
+
});
|
|
1776
|
+
res.end(JSON.stringify({ status: "ok" }));
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
if (url === base + "/readyz") {
|
|
1781
|
+
const states = await readServeSimStates();
|
|
1782
|
+
const state = selectServeSimState(states, selectedDevice);
|
|
1783
|
+
if (!state) {
|
|
1784
|
+
res.writeHead(503, {
|
|
1785
|
+
"Content-Type": "application/json",
|
|
1786
|
+
"Cache-Control": "no-store",
|
|
1787
|
+
});
|
|
1788
|
+
res.end(JSON.stringify({ status: "starting" }));
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1791
|
+
try {
|
|
1792
|
+
await getDeviceSession(state.device, streamSettings).start();
|
|
1793
|
+
res.writeHead(200, {
|
|
1794
|
+
"Content-Type": "application/json",
|
|
1795
|
+
"Cache-Control": "no-store",
|
|
1796
|
+
});
|
|
1797
|
+
res.end(JSON.stringify({ status: "ready", device: state.device }));
|
|
1798
|
+
} catch {
|
|
1799
|
+
res.writeHead(503, {
|
|
1800
|
+
"Content-Type": "application/json",
|
|
1801
|
+
"Cache-Control": "no-store",
|
|
1802
|
+
});
|
|
1803
|
+
res.end(JSON.stringify({ status: "starting" }));
|
|
1804
|
+
}
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1771
1808
|
// JSON API: serve-sim state
|
|
1772
1809
|
if (url === base + "/api") {
|
|
1773
1810
|
const states = await readServeSimStates();
|
package/src/stream-settings.ts
CHANGED
|
@@ -2,9 +2,10 @@ export type HttpStreamCodec = "auto" | "mjpeg" | "h264";
|
|
|
2
2
|
export type WebRtcStreamCodec = "vp8" | "vp9" | "h264";
|
|
3
3
|
export type WebRtcIceServer = { urls: string[]; username?: string; credential?: string };
|
|
4
4
|
|
|
5
|
-
export type StreamSettings =
|
|
5
|
+
export type StreamSettings = (
|
|
6
6
|
| { transport: "http"; codec?: HttpStreamCodec }
|
|
7
|
-
| { transport: "webrtc"; codec: WebRtcStreamCodec; iceServers?: WebRtcIceServer[] }
|
|
7
|
+
| { transport: "webrtc"; codec: WebRtcStreamCodec; iceServers?: WebRtcIceServer[] }
|
|
8
|
+
) & Partial<StreamEncoderSettings>;
|
|
8
9
|
|
|
9
10
|
export interface StreamPlaybackSettings {
|
|
10
11
|
transport: "http" | "webrtc";
|
|
@@ -17,7 +18,9 @@ export interface StreamEncoderSettings {
|
|
|
17
18
|
mjpegFps: number;
|
|
18
19
|
mjpegQuality: number;
|
|
19
20
|
maxDimension: number;
|
|
21
|
+
/** Shared target bitrate for H.264/AVCC and WebRTC video. */
|
|
20
22
|
h264Bitrate: number;
|
|
23
|
+
/** Shared target frame rate for H.264/AVCC and WebRTC video. */
|
|
21
24
|
h264Fps: number;
|
|
22
25
|
}
|
|
23
26
|
|
|
@@ -162,16 +165,27 @@ export function streamEncoderSettingsFrom(
|
|
|
162
165
|
export function streamControlSettingsFrom(
|
|
163
166
|
settings: StreamSettings | undefined,
|
|
164
167
|
): StreamControlSettings {
|
|
168
|
+
const encoderSettings = settings
|
|
169
|
+
? {
|
|
170
|
+
mjpegFps: settings.mjpegFps,
|
|
171
|
+
mjpegQuality: settings.mjpegQuality,
|
|
172
|
+
maxDimension: settings.maxDimension,
|
|
173
|
+
h264Bitrate: settings.h264Bitrate,
|
|
174
|
+
h264Fps: settings.h264Fps,
|
|
175
|
+
}
|
|
176
|
+
: {};
|
|
165
177
|
if (settings?.transport === "webrtc") {
|
|
166
178
|
return normalizeStreamControlSettings({
|
|
167
179
|
transport: "webrtc",
|
|
168
180
|
webRtcCodec: settings.codec,
|
|
169
181
|
iceServers: settings.iceServers,
|
|
182
|
+
...encoderSettings,
|
|
170
183
|
});
|
|
171
184
|
}
|
|
172
185
|
return normalizeStreamControlSettings({
|
|
173
186
|
transport: "http",
|
|
174
187
|
httpCodec: settings?.codec ?? "auto",
|
|
188
|
+
...encoderSettings,
|
|
175
189
|
});
|
|
176
190
|
}
|
|
177
191
|
|