@expo/serve-sim 0.1.35-canary.0
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/LICENSE +202 -0
- package/README.md +279 -0
- package/Sources/SimAXSettings/build.sh +21 -0
- package/Sources/SimAXSettings/sim-ax-settings.m +273 -0
- package/Sources/SimCameraHelper/build.sh +33 -0
- package/Sources/SimCameraHelper/main.m +955 -0
- package/Sources/SimCameraInjector/SimCamFakes.h +88 -0
- package/Sources/SimCameraInjector/SimCamFakes.m +704 -0
- package/Sources/SimCameraInjector/SimCamFrameSource.h +26 -0
- package/Sources/SimCameraInjector/SimCamFrameSource.m +577 -0
- package/Sources/SimCameraInjector/SimCamLog.h +5 -0
- package/Sources/SimCameraInjector/SimCamLog.m +9 -0
- package/Sources/SimCameraInjector/SimCamSwizzles.h +3 -0
- package/Sources/SimCameraInjector/SimCamSwizzles.m +1338 -0
- package/Sources/SimCameraInjector/SimCameraInjector.m +19 -0
- package/Sources/SimCameraInjector/build.sh +39 -0
- package/Sources/SimCameraInjector/include/SimCamShared.h +79 -0
- package/dist/bin/LiveKitWebRTC.framework/LiveKitWebRTC +0 -0
- package/dist/bin/LiveKitWebRTC.framework/Resources/Info.plist +36 -0
- package/dist/bin/LiveKitWebRTC.framework/Resources/LICENSE.webrtc +29 -0
- package/dist/bin/LiveKitWebRTC.framework/Resources/PrivacyInfo.xcprivacy +32 -0
- package/dist/bin/LiveKitWebRTC.framework/_CodeSignature/CodeResources +150 -0
- package/dist/middleware.cjs +2 -0
- package/dist/middleware.js +123 -0
- package/dist/native/serve-sim-native.node +0 -0
- package/dist/serve-sim.js +218 -0
- 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/dist/state.js +1 -0
- package/package.json +99 -0
- package/src/ax-shared.ts +25 -0
- package/src/ax.ts +258 -0
- package/src/camera-helper.ts +150 -0
- package/src/connect-to-fetch.ts +239 -0
- package/src/middleware.ts +2208 -0
- package/src/native.ts +294 -0
- package/src/state.ts +86 -0
- package/src/stream-settings.ts +202 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Evan Bacon
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# serve-sim
|
|
2
|
+
|
|
3
|
+
The `npx serve` of Apple Simulators.
|
|
4
|
+
|
|
5
|
+
Host your simulator for use with Agent tools like Codex, Cursor, or Claude Desktop — locally, over your LAN, or host on a remote mac and tunnel anywhere.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx @expo/serve-sim
|
|
9
|
+
# → Preview at http://localhost:3200
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
https://github.com/user-attachments/assets/fbf890f4-c8c7-4684-82be-d677b8a188f8
|
|
13
|
+
|
|
14
|
+
`serve-sim` captures the simulator's IOSurface through an in-process Swift addon, exposes it over HTTP or WebRTC, and serves a React preview UI with simulator input. It works with any booted iOS Simulator — no Xcode plugin and no instrumentation in your app.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Up to 60 FPS over HTTP, or low-latency 30 FPS over WebRTC.
|
|
19
|
+
- Swipe from the bottom to go home.
|
|
20
|
+
- gestures like pinch to zoom by holding the option key.
|
|
21
|
+
- Simulator logs are forwarded to the browser for browser-use MCP tools to read from.
|
|
22
|
+
- Recent simulator actions are available in the browser tools panel and `serve-sim event-log`.
|
|
23
|
+
- Drag and drop videos and images to add them to the simulator device.
|
|
24
|
+
- Keyboard commands and hot keys are forwarded to the simulator, including CMD+SHIFT+H to go home.
|
|
25
|
+
- Apple Watch, iPad, and iOS support.
|
|
26
|
+
|
|
27
|
+
## Why?
|
|
28
|
+
|
|
29
|
+
Hosted simulators can be hard to test, `serve-sim` enables you to test the hosted infra locally first for faster iteration. When you're ready to host a simulator remotely, simply tunnel the served URL and users can interact with the simulator as if it were running locally on their device.
|
|
30
|
+
|
|
31
|
+
I develop the Expo framework, but this tool is completely agnostic to React Native and can be used for any iOS interaction you need.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
Requires an Apple silicon (`arm64`) Mac 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+.
|
|
36
|
+
|
|
37
|
+
The bundled native addon, simulator tools, and host helpers are arm64-only.
|
|
38
|
+
|
|
39
|
+
## CLI
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
serve-sim [device...] Start preview server (default: localhost:3200)
|
|
43
|
+
serve-sim --no-preview [device...] Stream in foreground without a preview server
|
|
44
|
+
serve-sim gesture '<json>' [-d udid] Send a touch gesture
|
|
45
|
+
serve-sim button [name] [-d udid] Send a button press (default: home)
|
|
46
|
+
serve-sim type <text> [-d udid] Type text via the simulator keyboard
|
|
47
|
+
(US keyboard only; also --stdin / --file <path>)
|
|
48
|
+
serve-sim rotate <orientation> [-d udid]
|
|
49
|
+
portrait | portrait_upside_down |
|
|
50
|
+
landscape_left | landscape_right
|
|
51
|
+
serve-sim ca-debug <option> <on|off> [-d udid]
|
|
52
|
+
Toggle a CoreAnimation debug flag
|
|
53
|
+
(blended|copies|misaligned|offscreen|slow-animations)
|
|
54
|
+
serve-sim memory-warning [-d udid] Simulate a memory warning
|
|
55
|
+
serve-sim event-log [-d udid] Show recent simulator events
|
|
56
|
+
|
|
57
|
+
serve-sim camera <bundle-id> [-d udid] [source-options]
|
|
58
|
+
Inject a synthetic camera feed and (re)launch the app
|
|
59
|
+
serve-sim camera switch <placeholder|webcam|file> [arg] [-d udid]
|
|
60
|
+
Hot-swap the running helper's source (no relaunch)
|
|
61
|
+
serve-sim camera mirror <auto|on|off> [-d udid]
|
|
62
|
+
Hot-swap preview-layer mirror mode
|
|
63
|
+
serve-sim camera status [-d udid] Print helper state as JSON ({alive, source, ...})
|
|
64
|
+
serve-sim camera --list-webcams List host camera devices
|
|
65
|
+
serve-sim camera --stop-webcam [-d udid]
|
|
66
|
+
Stop the camera helper for a device
|
|
67
|
+
|
|
68
|
+
Options:
|
|
69
|
+
-p, --port <port> Starting port (preview default: 3200; helper default: 3100)
|
|
70
|
+
--detach Spawn server and exit (daemon mode)
|
|
71
|
+
-q, --quiet JSON-only output
|
|
72
|
+
--no-preview Skip the web UI; stream in foreground only
|
|
73
|
+
--codec <codec> HTTP stream codec: 'auto', 'h264', or 'mjpeg'
|
|
74
|
+
--transport <http|webrtc>
|
|
75
|
+
Stream transport (default: http)
|
|
76
|
+
--webrtc-codec <vp8|vp9|h264>
|
|
77
|
+
WebRTC video codec (default: h264)
|
|
78
|
+
--stun-url <url[,url...]>
|
|
79
|
+
STUN URL(s) for WebRTC ICE
|
|
80
|
+
--turn-url <url[,url...]>
|
|
81
|
+
TURN URL(s) for WebRTC ICE
|
|
82
|
+
--turn-username <username>
|
|
83
|
+
TURN username
|
|
84
|
+
--turn-credential <credential>
|
|
85
|
+
TURN credential
|
|
86
|
+
--list [device] List running streams
|
|
87
|
+
--kill [device] Kill running stream(s)
|
|
88
|
+
|
|
89
|
+
Camera options (used with `serve-sim camera <bundle-id>`):
|
|
90
|
+
-f, --file <path> Image or video file (kind auto-detected from
|
|
91
|
+
extension/magic bytes; videos loop at native FPS)
|
|
92
|
+
--webcam [name] Live host webcam (defaults to the built-in
|
|
93
|
+
front camera when [name] is omitted)
|
|
94
|
+
--mirror [on|off|auto] Override preview-layer mirroring (default: auto =
|
|
95
|
+
front mirrored, back not). Data-output buffers
|
|
96
|
+
are never auto-mirrored, matching AVF defaults.
|
|
97
|
+
--no-mirror Shortcut for --mirror off
|
|
98
|
+
--build Rebuild the dylib + helper from source
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
WebRTC uses HTTP for SDP signaling and RTP for video. Simulator input and screen
|
|
102
|
+
metadata continue over the existing helper WebSocket. ICE prefers a direct UDP
|
|
103
|
+
path when one is reachable, even if the page was loaded through a tunnel URL;
|
|
104
|
+
TURN is used as a fallback when direct/STUN candidates fail.
|
|
105
|
+
Multiple WebRTC viewers can use the same simulator simultaneously. They share
|
|
106
|
+
one SimulatorKit capture source, while each viewer has an independent peer
|
|
107
|
+
connection, encoder, congestion controller, and helper WebSocket. HTTP streams
|
|
108
|
+
continue to support multiple viewers as well.
|
|
109
|
+
|
|
110
|
+
See [WebRTC architecture](docs/webrtc-architecture.md) for the current design,
|
|
111
|
+
control-channel decision, known constraints, and planned direction.
|
|
112
|
+
|
|
113
|
+
### Examples
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
serve-sim # auto-detect booted sim, open preview
|
|
117
|
+
serve-sim "iPhone 16 Pro" # target a specific device
|
|
118
|
+
serve-sim --detach # start a background helper, return JSON
|
|
119
|
+
serve-sim --list # show running streams
|
|
120
|
+
serve-sim --kill # stop all helpers
|
|
121
|
+
|
|
122
|
+
# Type text into the focused field
|
|
123
|
+
serve-sim type "Hello, world!"
|
|
124
|
+
echo "from stdin" | serve-sim type --stdin
|
|
125
|
+
serve-sim type --file ./snippet.txt
|
|
126
|
+
|
|
127
|
+
# Camera injection
|
|
128
|
+
serve-sim camera com.acme.MyApp # animated placeholder
|
|
129
|
+
serve-sim camera com.acme.MyApp --webcam # default webcam
|
|
130
|
+
serve-sim camera com.acme.MyApp --webcam "MacBook Pro Camera"
|
|
131
|
+
serve-sim camera com.acme.MyApp --file ~/Pictures/face.png # static image
|
|
132
|
+
serve-sim camera com.acme.MyApp --file ~/Movies/loop.mp4 # looping video
|
|
133
|
+
|
|
134
|
+
# Hot-swap source on a running helper (no app relaunch)
|
|
135
|
+
serve-sim camera switch placeholder
|
|
136
|
+
serve-sim camera switch webcam
|
|
137
|
+
serve-sim camera switch ~/Movies/loop.mp4 # auto-detects file kind
|
|
138
|
+
|
|
139
|
+
# Other helpers
|
|
140
|
+
serve-sim camera mirror on
|
|
141
|
+
serve-sim camera status # JSON: alive, source, mirror
|
|
142
|
+
serve-sim camera --list-webcams
|
|
143
|
+
serve-sim camera --stop-webcam
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Multiple booted simulators are supported by passing several device names. With no device argument, serve-sim selects an existing stream, a booted simulator, or a default simulator to boot.
|
|
147
|
+
|
|
148
|
+
### Camera
|
|
149
|
+
|
|
150
|
+
`serve-sim camera <bundle-id>` replaces the simulator's camera feed for a single app. A small host-side helper writes BGRA frames into a POSIX shared-memory region; an injected dylib (`DYLD_INSERT_LIBRARIES`) swizzles AVFoundation inside the simulator process so the app reads from that region instead of the simulator's stub camera.
|
|
151
|
+
|
|
152
|
+
The helper is one-per-device and outlives any single app launch, so multiple apps on the same simulator can share the feed — just run `serve-sim camera <other-bundle-id>` again to relaunch the next app with the dylib attached. Source changes (`camera switch`) and mirror changes (`camera mirror`) flow through the helper's control socket and don't relaunch the app.
|
|
153
|
+
|
|
154
|
+
Sources:
|
|
155
|
+
|
|
156
|
+
- **placeholder** — animated programmatic frames (default).
|
|
157
|
+
- **file** — image (PNG/JPEG/HEIC/…) or video (mp4/mov/m4v/webm/…). The CLI sniffs the kind from the extension and falls back to magic bytes for files without an extension.
|
|
158
|
+
- **webcam** — live `AVCaptureDevice` (built-in, Continuity, external).
|
|
159
|
+
|
|
160
|
+
## Connectors
|
|
161
|
+
|
|
162
|
+
`serve-sim` can be used with dev servers, browser, and AI editors for more seamless integration.
|
|
163
|
+
|
|
164
|
+
### Agent Skill
|
|
165
|
+
|
|
166
|
+
An [Agent Skill](https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview) ships in [`skills/serve-sim`](skills/serve-sim) — it teaches AI coding agents (Claude Code, Cursor, Codex CLI, Gemini CLI, and any host implementing the open Agent Skills standard) how to drive a simulator through the CLI: taps, gestures, hardware buttons, rotation, camera injection, and handing the stream off to the host's preview pane.
|
|
167
|
+
|
|
168
|
+
```sh
|
|
169
|
+
bunx add-skill expo/serve-sim
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
See [`skills/serve-sim/README.md`](skills/serve-sim/README.md) for the full capability list.
|
|
173
|
+
|
|
174
|
+
### Claude Code Desktop
|
|
175
|
+
|
|
176
|
+
Create a `.claude/launch.json` and define a server:
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"version": "0.0.1",
|
|
181
|
+
"configurations": [
|
|
182
|
+
{
|
|
183
|
+
"name": "Apple",
|
|
184
|
+
"runtimeExecutable": "npx",
|
|
185
|
+
"runtimeArgs": ["serve-sim"],
|
|
186
|
+
"port": 3200
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Expo
|
|
193
|
+
|
|
194
|
+
Expo apps don't need to touch `metro.config.js` — the [`expo-device-hub`](https://github.com/expo/expo-device-hub) plugin uses `serve-sim` and sets up the device streaming for you.
|
|
195
|
+
|
|
196
|
+
```sh
|
|
197
|
+
npx expo install expo-device-hub
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Then run `npx expo start` and open the simulator preview at:
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
http://localhost:8081/_expo/plugins/expo-device-hub
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
No other configuration needed.
|
|
207
|
+
|
|
208
|
+
## Embed in your dev server
|
|
209
|
+
|
|
210
|
+
`@expo/serve-sim/middleware` is a **fetch-style** middleware. `simMiddleware(options)` returns a Web-standard request handler with a `.handleWebSocket` hook, so it mounts in any server that speaks `Request`/`Response` (Bun, Deno, Hono, a Node adapter, …). Run `serve-sim --detach` once to start the streaming helper, then wire the two entry points:
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
import { simMiddleware } from "@expo/serve-sim/middleware";
|
|
214
|
+
|
|
215
|
+
const middleware = simMiddleware({ basePath: "/.sim" });
|
|
216
|
+
|
|
217
|
+
// `server` is a stand-in for your runtime (Bun.serve, node:http + ws, Deno, …).
|
|
218
|
+
|
|
219
|
+
// HTTP — run every request through the middleware. It returns a Response for
|
|
220
|
+
// serve-sim's own routes (preview at /.sim, state at /.sim/api, SSE logs at
|
|
221
|
+
// /.sim/logs), or `undefined` — meaning "not mine", so fall through.
|
|
222
|
+
server.onRequest(async (request) => {
|
|
223
|
+
return (await middleware(request)) ?? new Response("Not found", { status: 404 });
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// WebSocket — the preview client runs execs, simulator settings, and the SSE
|
|
227
|
+
// side-channels over one socket at `<basePath>/exec-ws`, with no HTTP fallback.
|
|
228
|
+
// On upgrade, hand the request + accepted socket to handleWebSocket; it returns
|
|
229
|
+
// true once it owns the socket. `socket` is a `ws`-style WebSocket (Node's `ws`
|
|
230
|
+
// works as-is; other runtimes need a small adapter).
|
|
231
|
+
server.onUpgrade((request, socket) => {
|
|
232
|
+
if (!middleware.handleWebSocket?.(request, socket)) socket.close();
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
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.
|
|
237
|
+
|
|
238
|
+
### Single-port / remote proxying
|
|
239
|
+
|
|
240
|
+
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`:
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
const middleware = simMiddleware({ basePath: "/.sim", proxyHelpers: true });
|
|
244
|
+
|
|
245
|
+
// Route HTTP requests through `middleware(request)` as above, and also forward
|
|
246
|
+
// raw upgrade events for helper and DevTools proxy sockets.
|
|
247
|
+
const server = listen();
|
|
248
|
+
server.on("upgrade", (req, socket, head) => middleware.handleUpgrade(req, socket, head));
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
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.
|
|
252
|
+
|
|
253
|
+
## How it works
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
┌──────────────┐ IOSurface ┌──────────────────────┐ HTTP / WebRTC ┌─────────┐
|
|
257
|
+
│ iOS Simulator│ ────────────► │ serve-sim process │ ──────────────► │ Browser │
|
|
258
|
+
└──────────────┘ │ Swift N-API capture │ └─────────┘
|
|
259
|
+
│ + Node middleware │
|
|
260
|
+
└──────────────────────┘
|
|
261
|
+
▲
|
|
262
|
+
state files in
|
|
263
|
+
$TMPDIR/serve-sim/
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
The npm package ships the native capture addon and LiveKit WebRTC framework alongside the Node CLI. `bun` is needed to build the package, but not to run the published CLI.
|
|
267
|
+
|
|
268
|
+
## Development
|
|
269
|
+
|
|
270
|
+
```sh
|
|
271
|
+
bun install
|
|
272
|
+
bun run packages/serve-sim/build.ts # full production build
|
|
273
|
+
packages/serve-sim/Sources/SimNative/build.sh # native addon only
|
|
274
|
+
bun run --filter serve-sim dev # watch mode
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## License
|
|
278
|
+
|
|
279
|
+
Apache-2.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
5
|
+
OUT_DIR="${1:-$HERE/../../dist/simax}"
|
|
6
|
+
mkdir -p "$OUT_DIR"
|
|
7
|
+
|
|
8
|
+
SDK="$(xcrun --sdk iphonesimulator --show-sdk-path)"
|
|
9
|
+
BIN="$OUT_DIR/serve-sim-ax-settings"
|
|
10
|
+
|
|
11
|
+
# Build an arm64 simulator executable; it runs inside the sim via `simctl spawn`.
|
|
12
|
+
xcrun --sdk iphonesimulator clang \
|
|
13
|
+
-arch arm64 \
|
|
14
|
+
-mios-simulator-version-min=15.0 \
|
|
15
|
+
-isysroot "$SDK" \
|
|
16
|
+
-framework CoreFoundation \
|
|
17
|
+
-o "$BIN" \
|
|
18
|
+
"$HERE/sim-ax-settings.m"
|
|
19
|
+
|
|
20
|
+
echo "Built: $BIN"
|
|
21
|
+
file "$BIN"
|