Simplify ws-scrcpy for clean iframe embedding in the Hive platform, connecting directly to redroid Android containers with a single clean URL.
The codebase has been massively simplified and modernized:
- Decoder Lock: Locked video decoder exclusively to H264 Converter (MSE). Removed Broadway.js, TinyH264, and WebCodecs implementations.
- Code Cleanup: Removed ADB Shell (node-pty), File Listing, DevTools tracking, and all iOS support (appl-device).
- Auto-Connect Mode: Removed device selection UI. Client auto-connects to root URL (
ws://hostname:port/). - Environment-Based Configuration: Device UDID read from runtime environment variables instead of build-time webpack injection.
- Clean URLs: No query parameters needed. Simple iframe embedding:
<iframe src="http://ws-scrcpy:8000">
Configuration
# Required: Device to connect to
export SCRCPY_DEVICE_HOST=emulator-5554 # Local testing
export SCRCPY_DEVICE_HOST=redroid:5555 # Docker/Production
# Optional: scrcpy server port (default: 8886)
export SCRCPY_DEVICE_PORT=8886
# Optional: ws-scrcpy server port (default: 8000)
export WS_SCRCPY_SERVER_PORT=8000# 1. Start Android emulator
~/Library/Android/sdk/emulator/emulator -avd Pixel_7 -no-window -no-audio
# 2. Set device and build
export SCRCPY_DEVICE_HOST=emulator-5554
npm run dist
# 3. Start server
cd dist && npm start
# 4. Open browser
open http://localhost:8000version: '3.8'
services:
redroid:
image: redroid/redroid:latest
privileged: true
networks:
- android-net
ws-scrcpy:
build: .
environment:
- SCRCPY_DEVICE_HOST=redroid:5555
ports:
- "8000:8000"
networks:
- android-net
command: >
sh -c "adb connect redroid:5555 && node /app/dist/index.js"- Client: Browser loads from
http://hostname:8000 - WebSocket: Client connects to
ws://hostname:8000/(clean URL, no query params) - Server: Reads
SCRCPY_DEVICE_HOSTfrom environment - Auto-start: Pushes scrcpy-server.jar and starts it on device (if needed)
- Port Forward: Sets up
adb forwardfrom local port to device tcp:8886 - Proxy: Establishes WebSocket proxy to scrcpy server
- Stream: H264 video streams via MSE decoder to browser
src/app/index.ts- Client auto-connect logicsrc/server/goog-device/mw/WebsocketProxyOverAdb.ts- Server-side proxy with env configsrc/server/services/WebSocketServer.ts- Default route handlersrc/common/Constants.ts- scrcpy server configuration (port 8886)tion logic that used to pushvendor/scrcpy/scrcpy-server.jarto the Android device and execute it viaadb shell.
We threw this out because the redroid container in the Hive stack generally runs the scrcpy daemon out of the box natively. However, you are currently testing this on a raw, local Android Studio Pixel 7 emulator, which does not have the server injected or running.
Because the client is now optimized to be a "dumb client" that blindly assumes the server is actively listening on the target device, it crashes on your local emulator when it tries to proxy to a nonexistent socket.
To test this successfully on your local machine before deploying to Hive, we have two options:
- Manual Server Push: Manually push the
scrcpy-server.jarto your emulator and run it viaadb shell app_process ...from a separate terminal window to mimic theredroidenvironment. - Restore Auto-Push: Temporarily restore the auto-push code we deleted so
ws-scrcpyhandles injecting the jar for your local testing phase.