portholejs 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/LICENSE +186 -0
  2. package/README.md +201 -0
  3. package/package.json +1 -1
package/LICENSE ADDED
@@ -0,0 +1,186 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty percent
20
+ (50%) or more of the outstanding shares, or (iii) beneficial ownership of
21
+ such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source, and
28
+ configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation or
31
+ translation of a Source form, including but not limited to compiled object
32
+ code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that is
36
+ included in or attached to the work (an example is provided in the Appendix
37
+ below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object form,
40
+ that is based on (or derived from) the Work and for which the editorial
41
+ revisions, annotations, elaborations, or other modifications represent, as a
42
+ whole, an original work of authorship. For the purposes of this License,
43
+ Derivative Works shall not include works that remain separable from, or
44
+ merely link (or bind by name) to the interfaces of, the Work and Derivative
45
+ Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the original
48
+ version of the Work and any modifications or additions to that Work or
49
+ Derivative Works thereof, that is intentionally submitted to Licensor for
50
+ inclusion in the Work by the copyright owner or by an individual or Legal
51
+ Entity authorized to submit on behalf of the copyright owner. For the purposes
52
+ of this definition, "submitted" means any form of electronic, verbal, or
53
+ written communication sent to the Licensor or its representatives, including
54
+ but not limited to communication on electronic mailing lists, source code
55
+ control systems, and issue tracking systems that are managed by, or on behalf
56
+ of, the Licensor for the purpose of discussing and improving the Work, but
57
+ excluding communication that is conspicuously marked or otherwise designated
58
+ in writing by the copyright owner as "Not a Contribution."
59
+
60
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
61
+ behalf of whom a Contribution has been received by Licensor and subsequently
62
+ incorporated within the Work.
63
+
64
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
65
+ License, each Contributor hereby grants to You a perpetual, worldwide,
66
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
67
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
68
+ sublicense, and distribute the Work and such Derivative Works in Source or
69
+ Object form.
70
+
71
+ 3. Grant of Patent License. Subject to the terms and conditions of this
72
+ License, each Contributor hereby grants to You a perpetual, worldwide,
73
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
74
+ section) patent license to make, have made, use, offer to sell, sell, import,
75
+ and otherwise transfer the Work, where such license applies only to those
76
+ patent claims licensable by such Contributor that are necessarily infringed
77
+ by their Contribution(s) alone or by combination of their Contribution(s) with
78
+ the Work to which such Contribution(s) was submitted. If You institute patent
79
+ litigation against any entity (including a cross-claim or counterclaim in a
80
+ lawsuit) alleging that the Work or a Contribution incorporated within the Work
81
+ constitutes direct or contributory patent infringement, then any patent
82
+ licenses granted to You under this License for that Work shall terminate as of
83
+ the date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
86
+ Derivative Works thereof in any medium, with or without modifications, and in
87
+ Source or Object form, provided that You meet the following conditions:
88
+
89
+ (a) You must give any other recipients of the Work or Derivative Works a copy
90
+ of this License; and
91
+
92
+ (b) You must cause any modified files to carry prominent notices stating that
93
+ You changed the files; and
94
+
95
+ (c) You must retain, in the Source form of any Derivative Works that You
96
+ distribute, all copyright, patent, trademark, and attribution notices from the
97
+ Source form of the Work, excluding those notices that do not pertain to any
98
+ part of the Derivative Works; and
99
+
100
+ (d) If the Work includes a "NOTICE" text file as part of its distribution,
101
+ then any Derivative Works that You distribute must include a readable copy of
102
+ the attribution notices contained within such NOTICE file, excluding those
103
+ notices that do not pertain to any part of the Derivative Works, in at least
104
+ one of the following places: within a NOTICE text file distributed as part of
105
+ the Derivative Works; within the Source form or documentation, if provided
106
+ along with the Derivative Works; or, within a display generated by the
107
+ Derivative Works, if and wherever such third-party notices normally appear.
108
+ The contents of the NOTICE file are for informational purposes only and do not
109
+ modify the License. You may add Your own attribution notices within
110
+ Derivative Works that You distribute, alongside or as an addendum to the
111
+ NOTICE text from the Work, provided that such additional attribution notices
112
+ cannot be construed as modifying the License.
113
+
114
+ You may add Your own copyright statement to Your modifications and may
115
+ provide additional or different license terms and conditions for use,
116
+ reproduction, or distribution of Your modifications, or for any such
117
+ Derivative Works as a whole, provided Your use, reproduction, and distribution
118
+ of the Work otherwise complies with the conditions stated in this License.
119
+
120
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
121
+ Contribution intentionally submitted for inclusion in the Work by You to the
122
+ Licensor shall be under the terms and conditions of this License, without any
123
+ additional terms or conditions. Notwithstanding the above, nothing herein
124
+ shall supersede or modify the terms of any separate license agreement you may
125
+ have executed with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade names,
128
+ trademarks, service marks, or product names of the Licensor, except as
129
+ required for reasonable and customary use in describing the origin of the Work
130
+ and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
133
+ writing, Licensor provides the Work (and each Contributor provides its
134
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
135
+ KIND, either express or implied, including, without limitation, any warranties
136
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
137
+ PARTICULAR PURPOSE. You are solely responsible for determining the
138
+ appropriateness of using or redistributing the Work and assume any risks
139
+ associated with Your exercise of permissions under this License.
140
+
141
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
142
+ tort (including negligence), contract, or otherwise, unless required by
143
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
144
+ writing, shall any Contributor be liable to You for damages, including any
145
+ direct, indirect, special, incidental, or consequential damages of any
146
+ character arising as a result of this License or out of the use or inability
147
+ to use the Work (including but not limited to damages for loss of goodwill,
148
+ work stoppage, computer failure or malfunction, or any and all other
149
+ commercial damages or losses), even if such Contributor has been advised of
150
+ the possibility of such damages.
151
+
152
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work
153
+ or Derivative Works thereof, You may choose to offer, and charge a fee for,
154
+ acceptance of support, warranty, indemnity, or other liability obligations
155
+ and/or rights consistent with this License. However, in accepting such
156
+ obligations, You may act only on Your own behalf and on Your sole
157
+ responsibility, not on behalf of any other Contributor, and only if You agree
158
+ to indemnify, defend, and hold each Contributor harmless for any liability
159
+ incurred by, or claims asserted against, such Contributor by reason of your
160
+ accepting any such warranty or additional liability.
161
+
162
+ END OF TERMS AND CONDITIONS
163
+
164
+ APPENDIX: How to apply the Apache License to your work.
165
+
166
+ To apply the Apache License to your work, attach the following boilerplate
167
+ notice, with the fields enclosed by brackets "[]" replaced with your own
168
+ identifying information. (Don't include the brackets!) The text should be
169
+ enclosed in the appropriate comment syntax for the file format. We also
170
+ recommend that a file or class name and description of purpose be included on
171
+ the same "printed page" as the copyright notice for easier identification
172
+ within third-party archives.
173
+
174
+ Copyright [yyyy] [name of copyright owner]
175
+
176
+ Licensed under the Apache License, Version 2.0 (the "License");
177
+ you may not use this file except in compliance with the License.
178
+ You may obtain a copy of the License at
179
+
180
+ http://www.apache.org/licenses/LICENSE-2.0
181
+
182
+ Unless required by applicable law or agreed to in writing, software
183
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
184
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
185
+ See the License for the specific language governing permissions and
186
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,201 @@
1
+ # Porthole
2
+
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/giolaq/porthole/main/assets/porthole-logo.png" alt="Porthole logo" width="220">
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://www.npmjs.com/package/portholejs"><img src="https://img.shields.io/npm/v/portholejs" alt="npm version"></a>
9
+ <a href="https://github.com/giolaq/porthole/actions/workflows/ci.yml"><img src="https://github.com/giolaq/porthole/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
10
+ <a href="https://github.com/giolaq/porthole/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/portholejs" alt="license"></a>
11
+ <a href="https://www.npmjs.com/package/portholejs"><img src="https://img.shields.io/node/v/portholejs" alt="node"></a>
12
+ </p>
13
+
14
+ A window into your Android emulator — `npx portholejs`.
15
+
16
+ Porthole boots or attaches to Android phone and TV AVDs, streams them to a browser,
17
+ and forwards touch, keyboard, D-pad remote, screenshots, logcat, and file drops
18
+ through one local tool. It is the Android sibling of
19
+ [serve-sim](https://github.com/EvanBacon/serve-sim).
20
+
21
+ ## Quick Start
22
+
23
+ Prerequisites:
24
+
25
+ - Node.js 20 or newer
26
+ - Android Studio or Android SDK command line tools
27
+ - `emulator` and `adb` installed under the SDK
28
+ - Chrome, Edge, or another browser with WebCodecs for H.264 playback
29
+
30
+ Porthole finds the SDK from `ANDROID_HOME`, then `ANDROID_SDK_ROOT`, then the
31
+ platform defaults:
32
+
33
+ - macOS: `~/Library/Android/sdk`
34
+ - Linux: `~/Android/Sdk`
35
+ - Windows: `%LOCALAPPDATA%\Android\Sdk`
36
+
37
+ ```sh
38
+ npx portholejs
39
+ ```
40
+
41
+ With no running emulator, Porthole prompts for an AVD. To boot a specific AVD:
42
+
43
+ ### The scrcpy-server component
44
+
45
+ Porthole mirrors and controls the emulator by speaking the
46
+ [scrcpy](https://github.com/Genymobile/scrcpy) protocol. At runtime it pushes a
47
+ small server jar (`scrcpy-server`, Apache-2.0, by Genymobile) to the emulator
48
+ over adb and connects to its video and control sockets — no scrcpy CLI or
49
+ native binary is involved.
50
+
51
+ The jar is **not** bundled in this repository or in the npm package. It is
52
+ downloaded automatically during `npm install` (a `postinstall` step) from the
53
+ official Genymobile/scrcpy GitHub release, pinned to **v3.1** and verified
54
+ against a SHA-256 checksum. If the download was skipped (for example, an
55
+ offline install), fetch it later with:
56
+
57
+ ```sh
58
+ node node_modules/portholejs/scripts/download-scrcpy-server.mjs
59
+ ```
60
+
61
+ `porthole doctor` reports whether the jar is present. To bump the pinned
62
+ version, update `SCRCPY_VERSION` and `SCRCPY_SHA256` in
63
+ `scripts/download-scrcpy-server.mjs` and keep the engine's scrcpy options class
64
+ in sync (see `src/engine/scrcpy-engine.ts`).
65
+
66
+ ```sh
67
+ npx portholejs start Pixel_8_Pro_API_34
68
+ ```
69
+
70
+ For a headless agent workflow:
71
+
72
+ ```sh
73
+ npx portholejs start Android_TV_1080p --detach -q
74
+ npx portholejs remote dpad_down
75
+ npx portholejs screenshot -q
76
+ npx portholejs kill -q
77
+ ```
78
+
79
+ ## CLI Reference
80
+
81
+ | Command | Purpose |
82
+ | ----------------------------------- | --------------------------------------------------- |
83
+ | `porthole start [avd]` | Boot or attach and serve the browser preview |
84
+ | `porthole list` | List AVDs, running emulators, and known sessions |
85
+ | `porthole kill [avd]` | Stop emulators Porthole booted and detached servers |
86
+ | `porthole tap <x> <y>` | Touch normalized phone coordinates from `0..1` |
87
+ | `porthole key <keycode>` | Send an Android keycode down/up pair |
88
+ | `porthole remote <button>` | Press a TV D-pad/media button |
89
+ | `porthole text "<string>"` | Type text into the active session |
90
+ | `porthole screenshot [-o file.png]` | Save a PNG screenshot |
91
+ | `porthole focused` | Print the currently focused UI node |
92
+ | `porthole dump-ui [--filter text]` | Dump the Android UI hierarchy |
93
+ | `porthole wait-for <text>` | Wait until UI text appears |
94
+ | `porthole open-url <url>` | Open a URL or Android deep link |
95
+ | `porthole stop-app <package>` | Force-stop an app |
96
+ | `porthole clear-app <package>` | Clear app data |
97
+ | `porthole rotate <orientation>` | Rotate a phone emulator |
98
+ | `porthole emu <args...>` | Pass through to `adb emu` |
99
+ | `porthole doctor` | Diagnose Node/SDK/adb/AVD/session problems |
100
+ | `porthole mcp` | Run the MCP server over stdio |
101
+
102
+ Common options:
103
+
104
+ | Option | Meaning |
105
+ | ----------------------- | ------------------------------------------------ |
106
+ | `-p, --port <port>` | Preview/control port, default `3200` |
107
+ | `-d, --device <serial>` | Attach to a running emulator serial |
108
+ | `--host <host>` | Bind address, default `127.0.0.1` |
109
+ | `--no-preview` | Do not open the browser automatically |
110
+ | `--detach` | Start the preview server in the background |
111
+ | `--mjpeg` | Force MJPEG screenshot polling |
112
+ | `-q, --quiet` | Emit one JSON object/array on stdout |
113
+ | `--max-size <px>` | Maximum scrcpy stream dimension |
114
+ | `--max-fps <fps>` | Maximum scrcpy FPS |
115
+ | `--bitrate <bps>` | Scrcpy video bitrate |
116
+ | `--wipe-data` | Wipe emulator data before boot |
117
+ | `--no-snapshot` | Disable loading/saving emulator snapshots |
118
+ | `--cold-boot` | Alias for `--no-snapshot` |
119
+ | `--gpu <mode>` | Pass emulator GPU mode |
120
+ | `--keep-alive` | Leave a Porthole-booted emulator running on exit |
121
+
122
+ Quiet schemas are intentionally simple: `list -q` returns
123
+ `{ "devices": [...], "sessions": [...] }`; `start --detach -q` returns the
124
+ session record with `url`, `pid`, `serial`, `avdName`, `port`, and `profile`;
125
+ input commands return `{ "ok": true, "session": ... }`; `screenshot -q` returns
126
+ `{ "ok": true, "path": "...", "session": ... }`.
127
+
128
+ ## MCP Setup
129
+
130
+ `.mcp.json`:
131
+
132
+ ```json
133
+ {
134
+ "mcpServers": {
135
+ "porthole": {
136
+ "command": "npx",
137
+ "args": ["portholejs", "mcp"]
138
+ }
139
+ }
140
+ }
141
+ ```
142
+
143
+ Claude Code:
144
+
145
+ ```sh
146
+ claude mcp add porthole -- npx portholejs mcp
147
+ ```
148
+
149
+ Useful MCP tools: `list_devices`, `boot_device`, `wait_for_boot`,
150
+ `attach_device`, `tap`, `key`, `remote`, `type_text`, `screenshot`,
151
+ `dump_ui`, `get_focused`, `find_element`, `wait_for`, `open_url`, `stop_app`,
152
+ `clear_app`, `get_crashes`, `read_logcat`, and `install_apk`.
153
+
154
+ ## Browser UI
155
+
156
+ The preview shows the active device, stream status, screenshots, copy-to-clipboard,
157
+ stream stats, logcat, drag-and-drop APK install/file push, phone hardware keys,
158
+ and a TV D-pad remote. TV sessions reject touch input server-side.
159
+
160
+ Video uses WebCodecs by default. Browsers without `VideoDecoder` automatically
161
+ fall back to `/stream.mjpeg`, and `--mjpeg` or `?video=mjpeg` forces that mode.
162
+ MJPEG is implemented with shared `adb screencap` polling at roughly 3 fps,
163
+ re-encoded server-side to downscaled JPEG (pure JS, max 800 px) to keep
164
+ per-frame payloads small; it is a compatibility fallback, not a
165
+ high-frame-rate stream.
166
+
167
+ When serving on a LAN with `--host 0.0.0.0`, Porthole prints a tokenized URL.
168
+ Non-local requests must present that token.
169
+
170
+ Two capability notes:
171
+
172
+ - `porthole emu` / `POST /api/emu` is a raw passthrough to the emulator
173
+ console (`adb emu`) — including commands like `kill`. Treat it as
174
+ operator-level access; anyone who can reach the (token-protected) API can
175
+ use it.
176
+ - `porthole focused` / `get_focused` reads D-pad focus, which is a TV/leanback
177
+ concept. On phone profiles it usually returns `null` unless a view holds
178
+ keyboard focus — that is expected, not an error.
179
+
180
+ ## Troubleshooting
181
+
182
+ | Problem | Fix |
183
+ | ----------------------------- | --------------------------------------------------------------------------- |
184
+ | SDK not found | Set `ANDROID_HOME` or `ANDROID_SDK_ROOT` to your Android SDK |
185
+ | `adb devices` shows `offline` | Porthole runs `adb reconnect offline`; if it persists, restart the emulator |
186
+ | Port `3200` is taken | Pass `-p 3201` or another free port |
187
+ | Blank video | Use a WebCodecs-capable browser and check DevTools for decoder errors |
188
+ | TV taps do nothing | Use `porthole remote <button>`; TV profiles reject touch |
189
+
190
+ ## Development
191
+
192
+ ```sh
193
+ npm install
194
+ npm run build
195
+ npm run test
196
+ npm run lint
197
+ npm run typecheck
198
+ ```
199
+
200
+ Integration tests that require a booted emulator are gated behind
201
+ `PORTHOLE_EMU=1`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "portholejs",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A window into your Android emulator — stream and control AVDs from the browser",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",