serve-sim 0.1.43 → 0.1.44-beta.106.1
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.swift +57 -0
- package/README.md +20 -3
- package/Sources/SimNative/AccessibilityBridge.swift +635 -0
- package/Sources/SimNative/FrameCapture.swift +310 -0
- package/Sources/SimNative/H264Encoder.swift +261 -0
- package/Sources/SimNative/HIDInjector.swift +649 -0
- package/Sources/SimNative/SimFrameworks.swift +25 -0
- package/Sources/SimNative/StreamFormat.swift +46 -0
- package/Sources/SimNative/VideoEncoder.swift +53 -0
- package/Sources/SimNative/Xcode.swift +25 -0
- package/Sources/SimNative/build.sh +45 -0
- package/Sources/SimNative/sim-capture.swift +224 -0
- package/Sources/SimNative/sim-module.swift +195 -0
- package/dist/middleware.js +51 -29
- package/dist/native/serve-sim-native.node +0 -0
- package/dist/serve-sim.js +95 -70
- package/dist/simax/serve-sim-ax-settings +0 -0
- package/dist/simcam/libSimCameraInjector.dylib +0 -0
- package/dist/simcam/serve-sim-camera-helper +0 -0
- package/package.json +10 -6
- package/src/ax.ts +27 -63
- package/src/middleware.ts +635 -174
- package/src/native.ts +240 -0
- package/src/state.ts +49 -1
- package/bin/serve-sim-bin +0 -0
package/Package.swift
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// swift-tools-version:6.0
|
|
2
|
+
//
|
|
3
|
+
// Builds serve-sim-native — the in-process N-API addon that replaces the
|
|
4
|
+
// spawned serve-sim-bin helper. The JS bindings are written directly in Swift
|
|
5
|
+
// with node-swift (NodeAPI), so there is no Objective-C++ glue: SimHID /
|
|
6
|
+
// SimCapture are NodeClasses and the accessibility dumps are async NodeFunctions
|
|
7
|
+
// (see Sources/SimNative/sim-module.swift). The reverse-engineered streaming
|
|
8
|
+
// logic in SimStreamHelper is reused verbatim.
|
|
9
|
+
//
|
|
10
|
+
// The actual .node is produced by Sources/SimNative/build.sh, which drives
|
|
11
|
+
// `swift build --arch arm64 --arch x86_64` for a universal binary and links
|
|
12
|
+
// napi_* with `-undefined dynamic_lookup` (resolved against the host Node/Bun
|
|
13
|
+
// at dlopen). `node-swift rebuild` is intentionally not used: it builds a single
|
|
14
|
+
// arch only, and cross-compiling per-arch with `--triple` breaks the
|
|
15
|
+
// `#NodeModule` macro.
|
|
16
|
+
|
|
17
|
+
import PackageDescription
|
|
18
|
+
|
|
19
|
+
let package = Package(
|
|
20
|
+
name: "serve-sim-native",
|
|
21
|
+
platforms: [.macOS(.v14)],
|
|
22
|
+
products: [
|
|
23
|
+
.library(
|
|
24
|
+
name: "serve-sim-native",
|
|
25
|
+
type: .dynamic,
|
|
26
|
+
targets: ["SimNative"]
|
|
27
|
+
),
|
|
28
|
+
],
|
|
29
|
+
dependencies: [
|
|
30
|
+
.package(path: "node_modules/node-swift"),
|
|
31
|
+
],
|
|
32
|
+
targets: [
|
|
33
|
+
.target(
|
|
34
|
+
name: "SimNative",
|
|
35
|
+
dependencies: [
|
|
36
|
+
.product(name: "NodeAPI", package: "node-swift"),
|
|
37
|
+
.product(name: "NodeModuleSupport", package: "node-swift"),
|
|
38
|
+
],
|
|
39
|
+
exclude: [
|
|
40
|
+
"build.sh",
|
|
41
|
+
],
|
|
42
|
+
linkerSettings: [
|
|
43
|
+
.unsafeFlags([
|
|
44
|
+
"-Xlinker", "-undefined",
|
|
45
|
+
"-Xlinker", "dynamic_lookup",
|
|
46
|
+
])
|
|
47
|
+
]
|
|
48
|
+
),
|
|
49
|
+
],
|
|
50
|
+
// The reused SimStreamHelper logic was written against the standalone helper
|
|
51
|
+
// (plain swiftc, which defaults to Swift 5 mode). Build in Swift 5 mode so its
|
|
52
|
+
// benign cross-queue captures stay warnings rather than Swift 6 errors;
|
|
53
|
+
// node-swift's API works in v5. Declared at package level so the target's
|
|
54
|
+
// language mode is valid under stricter toolchains — CI rejects a target
|
|
55
|
+
// language mode that isn't among the package's declared modes.
|
|
56
|
+
swiftLanguageModes: [.v5]
|
|
57
|
+
)
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ I develop the Expo framework, but this tool is completely agnostic to React Nati
|
|
|
31
31
|
|
|
32
32
|
## Install
|
|
33
33
|
|
|
34
|
-
Requires macOS with Xcode command line tools (`xcrun simctl`) and Node.js
|
|
34
|
+
Requires macOS with Xcode command line tools (`xcrun simctl`) and a [maintained Node.js LTS release](https://nodejs.org/en/about/previous-releases) (currently Node 20+). Older or end-of-life Node versions are not supported. `bun` is **not** required to run the CLI. Camera injection uses a host-side helper built for macOS 14+.
|
|
35
35
|
|
|
36
36
|
> **Note:** Apple Silicon (arm64) only. The bundled `serve-sim-bin` helper ships as an arm64 binary and does not run on Intel (x86_64) Macs.
|
|
37
37
|
|
|
@@ -64,10 +64,13 @@ serve-sim camera --stop-webcam [-d udid]
|
|
|
64
64
|
Stop the camera helper for a device
|
|
65
65
|
|
|
66
66
|
Options:
|
|
67
|
-
-p, --port <port> Starting port (preview default: 3200
|
|
67
|
+
-p, --port <port> Starting port (preview default: 3200; helper default: 3100)
|
|
68
68
|
-d, --detach Spawn helper and exit (daemon mode)
|
|
69
69
|
-q, --quiet JSON-only output
|
|
70
70
|
--no-preview Skip the web UI; stream in foreground only
|
|
71
|
+
--codec <codec> Stream codec for the preview UI: 'auto' (H.264 when the
|
|
72
|
+
browser can decode it) or 'mjpeg' (force software JPEG —
|
|
73
|
+
e.g. on VMs without H.264 encode)
|
|
71
74
|
--list [device] List running streams
|
|
72
75
|
--kill [device] Kill running stream(s)
|
|
73
76
|
|
|
@@ -206,7 +209,21 @@ app.use(simMiddleware({ basePath: "/.sim" }));
|
|
|
206
209
|
// → state JSON at /.sim/api
|
|
207
210
|
```
|
|
208
211
|
|
|
209
|
-
The middleware reads the helper's state from `$TMPDIR/serve-sim/` and
|
|
212
|
+
The middleware reads the helper's state from `$TMPDIR/serve-sim/` and points the browser at the helper's stream, interaction WebSocket, and WebKit DevTools endpoints. By default those URLs target the helper's own port directly (CORS is wide-open on the helper), so a plain `app.use(...)` mount works without touching your server's WebSocket handling.
|
|
213
|
+
|
|
214
|
+
### Single-port / remote proxying
|
|
215
|
+
|
|
216
|
+
To expose the preview to remote viewers behind a single port (the way standalone `serve-sim` does), pass `proxyHelpers: true`. The browser then reaches the stream, control socket, and DevTools through same-origin `/.sim/helper/<device>` and `/.sim/devtools` URLs, so the per-device helper port and inspect-webkit bridge can stay local to the host. This routes WebSockets through the middleware, so you must forward your server's `upgrade` events to `handleUpgrade`:
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
const middleware = simMiddleware({ basePath: "/.sim", proxyHelpers: true });
|
|
220
|
+
app.use(middleware);
|
|
221
|
+
|
|
222
|
+
const server = app.listen(3000);
|
|
223
|
+
server.on("upgrade", (req, socket, head) => middleware.handleUpgrade(req, socket, head));
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
If you enable `proxyHelpers` but don't wire `upgrade`, the page still loads video over HTTP but loses simulator input and DevTools (their sockets never reach the proxy). When terminating TLS at a reverse proxy, forward `X-Forwarded-Proto` so the helper URLs use `https`/`wss` and avoid mixed-content blocks.
|
|
210
227
|
|
|
211
228
|
## How it works
|
|
212
229
|
|