@expo/serve-sim 0.1.40 → 0.1.42

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expo/serve-sim",
3
- "version": "0.1.40",
3
+ "version": "0.1.42",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Evan Bacon",
@@ -32,6 +32,7 @@
32
32
  ],
33
33
  "files": [
34
34
  "LICENSE",
35
+ "NOTICE",
35
36
  "dist/serve-sim.js",
36
37
  "dist/middleware.js",
37
38
  "dist/middleware.cjs",
package/src/middleware.ts CHANGED
@@ -17,7 +17,13 @@ import { readCameraStatus } from "./camera-helper";
17
17
  import { createMetricsSamplerCache, MetricsSampler, type MetricsSamplerCache } from "./metrics-sampler";
18
18
  import { foregroundTracker, type ForegroundApp, type ForegroundTrackerCache } from "./foreground-tracker";
19
19
  import { corsAllowOriginHeaders } from "./middleware-utils";
20
- import { closeDeviceSession, getDeviceSession, sendCorsPreflight, type HidSocket } from "./device-session";
20
+ import {
21
+ closeDeviceSession,
22
+ getDeviceSession,
23
+ peekDeviceSession,
24
+ sendCorsPreflight,
25
+ type HidSocket,
26
+ } from "./device-session";
21
27
  import {
22
28
  eventLogEventForCommand,
23
29
  readEventLog,
@@ -779,12 +785,21 @@ function serveHelperInProcess(
779
785
  return true;
780
786
  }
781
787
  if (
782
- (endpoint === "/webrtc/offer" || endpoint === "/webrtc/close" || endpoint === "/stream-settings")
788
+ (endpoint === "/webrtc/offer" || endpoint === "/webrtc/close" || endpoint === "/webrtc/stats"
789
+ || endpoint === "/stream-settings")
783
790
  && req.method === "OPTIONS"
784
791
  ) {
785
792
  sendCorsPreflight(res);
786
793
  return true;
787
794
  }
795
+ // Polled once a second by the panel and the recorder, so creating a session here would start a
796
+ // capture nothing asked for, and re-create one every tick after the simulator is shut down.
797
+ if (endpoint === "/webrtc/stats") {
798
+ const live = peekDeviceSession(device);
799
+ if (!live) return false;
800
+ void live.handleWebRTCStats(req, res);
801
+ return true;
802
+ }
788
803
  let session;
789
804
  try {
790
805
  session = getDeviceSession(device, initialStreamSettings);
package/src/native.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  DEFAULT_STREAM_ENCODER_SETTINGS,
16
16
  type StreamEncoderSettings,
17
17
  } from "./stream-settings";
18
+ import { readSenderStats, type SenderStats } from "./webrtc-sender-stats";
18
19
 
19
20
  const require = createRequire(import.meta.url);
20
21
 
@@ -47,6 +48,7 @@ interface SimCaptureHandle {
47
48
  ): Promise<void>;
48
49
  handleWebRTCOffer(offerJson: string): Promise<string>;
49
50
  closeWebRTCSession(sessionId: string): Promise<void>;
51
+ webRTCSenderStats(sessionId: string): Promise<string>;
50
52
  screenSize(): Promise<{ width: number; height: number }>;
51
53
  stop(): Promise<void>;
52
54
  subscribe(codec: number, onFrame: RawFrameCallback): Promise<NativeUnsubscribe>;
@@ -269,6 +271,15 @@ export class NativeCapture {
269
271
  return this.handle.closeWebRTCSession(sessionId);
270
272
  }
271
273
 
274
+ /**
275
+ * Sender-side statistics for live WebRTC sessions. Pass a session id to gather that viewer only;
276
+ * omit it for every session (`--debug-stream`). `qualityLimitationReason` lives here only: a
277
+ * receive-only browser cannot tell a CPU-bound encoder from a starved network.
278
+ */
279
+ async webRTCSenderStats(sessionId?: string): Promise<SenderStats> {
280
+ return readSenderStats(JSON.parse(await this.handle.webRTCSenderStats(sessionId ?? "")));
281
+ }
282
+
272
283
  screenSize(): Promise<{ width: number; height: number }> {
273
284
  return this.handle.screenSize();
274
285
  }