@expo/serve-sim 0.14.1 → 0.14.2
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/dist/middleware.js +113 -113
- package/dist/native/serve-sim-native.node +0 -0
- package/dist/serve-sim.js +124 -124
- package/package.json +1 -1
- package/src/middleware.ts +4 -2
- package/src/native.ts +18 -0
package/package.json
CHANGED
package/src/middleware.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ScreenshotImageOptions } from "./screenshot-options";
|
|
2
2
|
import { convertScreenshot } from "./native";
|
|
3
|
+
import { SCREENSHOT_METADATA_HEADER, screenshotMetadataHeaders } from "./screenshot-metadata";
|
|
3
4
|
import { startDeviceInProcess, stopDeviceInProcess } from "./device-lifecycle";
|
|
4
5
|
export { startDeviceInProcess } from "./device-lifecycle";
|
|
5
6
|
export { gridDeviceState } from "./state";
|
|
@@ -2884,7 +2885,7 @@ export function simMiddleware(options?: SimMiddlewareOptions): SimMiddleware {
|
|
|
2884
2885
|
udid = udid.toUpperCase();
|
|
2885
2886
|
try {
|
|
2886
2887
|
const captureStarted = performance.now();
|
|
2887
|
-
const { png, nativeMs } = await captureScreenshotPngAsync({
|
|
2888
|
+
const { png, nativeMs, metadata } = await captureScreenshotPngAsync({
|
|
2888
2889
|
udid,
|
|
2889
2890
|
display: display?.data,
|
|
2890
2891
|
maxWidth,
|
|
@@ -2909,9 +2910,10 @@ export function simMiddleware(options?: SimMiddlewareOptions): SimMiddleware {
|
|
|
2909
2910
|
"Content-Type": format === "jpeg" ? "image/jpeg" : "image/png",
|
|
2910
2911
|
"Content-Length": String(image.byteLength),
|
|
2911
2912
|
// The route allows configured cross-origin callers, and they can only read custom headers listed here.
|
|
2912
|
-
"Access-Control-Expose-Headers": `${SCREENSHOT_ARTIFACT_HEADER}, ${SCREENSHOT_ARTIFACT_ERROR_HEADER}, Server-Timing`,
|
|
2913
|
+
"Access-Control-Expose-Headers": `${SCREENSHOT_ARTIFACT_HEADER}, ${SCREENSHOT_ARTIFACT_ERROR_HEADER}, ${SCREENSHOT_METADATA_HEADER}, Server-Timing`,
|
|
2913
2914
|
"Server-Timing": serverTiming,
|
|
2914
2915
|
...screenshotArtifactHeaders(artifact),
|
|
2916
|
+
...screenshotMetadataHeaders(metadata),
|
|
2915
2917
|
});
|
|
2916
2918
|
res.end(image);
|
|
2917
2919
|
} catch (err) {
|
package/src/native.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { createRequire } from "module";
|
|
|
11
11
|
import { dirname, join } from "path";
|
|
12
12
|
import { existsSync } from "fs";
|
|
13
13
|
import { fileURLToPath } from "url";
|
|
14
|
+
import { screenshotMetadata, type ScreenshotMetadata } from "./screenshot-metadata";
|
|
14
15
|
import { DEFAULT_STREAM_ENCODER_SETTINGS, type StreamEncoderSettings } from "./stream-settings";
|
|
15
16
|
import { readSenderStats, type SenderStats } from "./webrtc-sender-stats";
|
|
16
17
|
import type { HingePhysicalOrientation } from "./hinge-control";
|
|
@@ -62,6 +63,10 @@ interface SimHIDHandle {
|
|
|
62
63
|
|
|
63
64
|
interface SimCaptureHandle {
|
|
64
65
|
screenshot(screenID: number, maxWidth: number): Promise<Uint8Array>;
|
|
66
|
+
screenshotWithMetadata?(
|
|
67
|
+
screenID: number,
|
|
68
|
+
maxWidth: number,
|
|
69
|
+
): Promise<{ data: Uint8Array; metadata: string }>;
|
|
65
70
|
start(): Promise<void>;
|
|
66
71
|
suspendForReboot(): Promise<void>;
|
|
67
72
|
resumeAfterReboot(): Promise<void>;
|
|
@@ -148,6 +153,8 @@ export type NativeDeviceStateSnapshot = {
|
|
|
148
153
|
state: NativeHingeState;
|
|
149
154
|
};
|
|
150
155
|
|
|
156
|
+
export type NativeScreenshot = { data: Uint8Array; metadata: ScreenshotMetadata };
|
|
157
|
+
|
|
151
158
|
export type NativeScreenInfo = {
|
|
152
159
|
width: number;
|
|
153
160
|
height: number;
|
|
@@ -400,6 +407,17 @@ export class NativeCapture {
|
|
|
400
407
|
return this.handle.screenshot(screenID, maxWidth);
|
|
401
408
|
}
|
|
402
409
|
|
|
410
|
+
async screenshotWithMetadata(screenID: number, maxWidth = 0): Promise<NativeScreenshot> {
|
|
411
|
+
if (!this.handle.screenshotWithMetadata) {
|
|
412
|
+
return {
|
|
413
|
+
data: await this.handle.screenshot(screenID, maxWidth),
|
|
414
|
+
metadata: screenshotMetadata(),
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
const result = await this.handle.screenshotWithMetadata(screenID, maxWidth);
|
|
418
|
+
return { data: result.data, metadata: JSON.parse(result.metadata) as ScreenshotMetadata };
|
|
419
|
+
}
|
|
420
|
+
|
|
403
421
|
private readonly handle: SimCaptureHandle;
|
|
404
422
|
|
|
405
423
|
/** A fixed screen ID captures that panel independently of active-display/input routing. */
|