Skip to content

PC Control API Specification (v1) ​

This document specifies the local HTTP REST + WebSocket Control API exposed by connekt-hub. Any desktop application or tool (Electron, Node.js, TypeScript, Python, Go, Swift, Flutter Desktop, CLI harnesses) can spawn connekt-hub as a managed Sidecar and control every connected device through this interface.


1. Running connekt-hub & Default Endpoints ​

bash
# Default: listens on 0.0.0.0:9527 (Control API, LAN /ws device ingress, and Web Debugger)
connekt-hub --listen 0.0.0.0:9527 --adb-reverse-port 19527

# Sidecar mode: ephemeral port + single JSON ready line on stdout
connekt-hub-headless --listen 127.0.0.1:0 --ready-json
  • HTTP REST Base URL: http://127.0.0.1:9527/api/v1
  • Real-time Control WebSocket: ws://127.0.0.1:9527/api/v1/control
  • Embedded Web Debugger (full build): http://127.0.0.1:9527/
  • Zero-install Mobile H5 Companion (full build): http://127.0.0.1:9527/m
  • Browser Peer SDK Module (full & headless): http://127.0.0.1:9527/sdk/connekt-peer.js

Payload encoding: Because wire payloads are arbitrary bytes, JSON endpoints accept payload_encoding:

  • "utf8" (default) — UTF-8 text or JSON strings.
  • "base64" — Arbitrary binary data (images, Protobuf, archives).

2. HTTP REST API ​

2.1 Health & Transport Status ​

GET /api/v1/health

json
{
  "status": "ok",
  "version": "0.1.0",
  "web_ui": true,
  "uptime_ms": 48210,
  "transports": {
    "adb": { "enabled": true, "connected_devices": 2, "reverse_port": 19527 },
    "lan_ws": { "enabled": true, "listen": "0.0.0.0:9527" }
  },
  "online_peers": 3
}

2.2 List Online Peers ​

GET /api/v1/peers

json
{
  "peers": [
    {
      "peer_id": "a1b2c3d4/com.demo.shop",
      "device_id": "dev-9f8e7d6c",
      "serial": "DEVICE_SERIAL",
      "package_name": "com.demo.shop",
      "app_name": "Demo Shop",
      "process_name": "com.demo.shop",
      "pid": 14820,
      "platform": "android",
      "model": "Pixel 9",
      "manufacturer": "Google",
      "os_version": "15",
      "transports": ["adb", "lan"],
      "active_transport": "adb",
      "connected_at_ms": 1764759600000
    }
  ]
}

2.3 Send Unidirectional Message (send) ​

POST /api/v1/send

json
{
  "dst": "a1b2c3d4/com.demo.shop",
  "ch": "cmd",
  "payload_encoding": "utf8",
  "payload": "{\"action\":\"refresh\"}"
}

dst accepts:

  • A single peer_id (unicast)
  • "*" (broadcast to all online peers)
  • A string array ["peerA", "peerB"] (zero-copy subset multicast)

Response (200 OK):

json
{
  "ok": true,
  "delivered_count": 1
}

2.4 Request / Response (request) ​

POST /api/v1/request

json
{
  "dst": "a1b2c3d4/com.demo.shop",
  "ch": "layout",
  "payload_encoding": "utf8",
  "payload": "{\"cmd\":\"dump_tree\"}",
  "timeout_ms": 5000
}

Success (200 OK):

json
{
  "ok": true,
  "src": "a1b2c3d4/com.demo.shop",
  "ch": "layout",
  "payload_encoding": "utf8",
  "payload": "{\"root\":\"DecorView\",\"children\":[]}"
}

Error (PEER_OFFLINE, TIMEOUT, NO_HANDLER, etc.):

json
{
  "ok": false,
  "err_code": "TIMEOUT",
  "err_msg": "Request timed out after 5000ms"
}

3. Real-Time Control WebSocket (WS /api/v1/control) ​

Use /api/v1/control for high-frequency inbound telemetry, peer online/offline events, responding to peer-initiated REQ calls, and zero-Base64 binary streaming (control commands use JSON text frames; stream chunks use raw WebSocket Binary frames).

3.1 Hub → Control Client (Events) ​

1) Peer Topology Events ​

json
{ "event": "peer_list", "peers": [ ... ] }
{ "event": "peer_online", "peer": { ... } }
{ "event": "peer_offline", "peer_id": "a1b2c3d4/com.demo.shop" }

2) Inbound Message (DATA) ​

json
{
  "event": "message",
  "src": "a1b2c3d4/com.demo.shop",
  "dst": "pc",
  "ch": "network",
  "payload_encoding": "utf8",
  "payload": "{\"url\":\"https://api.example.com/user\",\"status\":200}",
  "ts_ms": 1764759612345
}

3) Inbound Request (REQ) ​

json
{
  "event": "request",
  "req_id": 42,
  "src": "a1b2c3d4/com.demo.shop",
  "ch": "mock",
  "payload_encoding": "utf8",
  "payload": "{\"path\":\"/api/config\"}"
}

4) Routing Traffic Telemetry (opt-in via include_traffic: true) ​

json
{
  "event": "traffic",
  "kind": "data",
  "src": "pc",
  "dst": "",
  "dsts": ["d1/appA", "d2/appB"],
  "ch": "notice",
  "bytes": 21,
  "ok": true,
  "transport": "adb",
  "ts_ms": 1764759612400
}

kind is "data", "req", "resp", or "stream".

5) Binary Stream Lifecycle (stream_open / Binary Chunks / stream_close) ​

  • Inbound stream open (after calling register_stream for ch):
    json
    {
      "event": "stream_open",
      "stream_id": 7,
      "src": "a1b2c3d4/com.demo.shop",
      "ch": "files",
      "meta": { "name": "dump.hprof", "mime": "application/octet-stream" }
    }
  • Inbound chunk (WebSocket Binary Frame — zero Base64 / zero JSON):
    text
    [ 4-byte Big-Endian stream_id (u32) ][ raw chunk payload bytes ]
  • Stream close / reject / cancel:
    json
    {
      "event": "stream_close",
      "stream_id": 7,
      "ok": false,
      "err_code": "STREAM_REJECTED",
      "err_msg": "video/mp4 rejected by policy"
    }

3.2 Control Client → Hub (Actions) ​

1) Subscribe & Filter ​

json
{
  "action": "subscribe",
  "channels": ["network", "log"],
  "peers": [],
  "include_traffic": true
}

2) Send Message (send — unicast, array, or "*") ​

json
{
  "action": "send",
  "dst": ["d1/appA", "d2/appB"],
  "ch": "cmd",
  "payload_encoding": "utf8",
  "payload": "hello"
}

3) Initiate Request (request) ​

json
{
  "action": "request",
  "call_id": "c-1001",
  "dst": "a1b2c3d4/com.demo.shop",
  "ch": "layout",
  "payload_encoding": "utf8",
  "payload": "{\"depth\":3}",
  "timeout_ms": 5000
}

The Hub replies with:

json
{
  "event": "request_result",
  "call_id": "c-1001",
  "ok": true,
  "payload_encoding": "utf8",
  "payload": "{...}"
}

4) Respond to Peer Request (respond) ​

json
{
  "action": "respond",
  "req_id": 42,
  "dst": "a1b2c3d4/com.demo.shop",
  "ch": "mock",
  "ok": true,
  "payload_encoding": "utf8",
  "payload": "{\"mocked\":true}"
}

5) Binary Streams (register_stream / stream_open / Binary / stream_close) ​

  • Register inbound stream channel: {"action":"register_stream","ch":"files"} (unregister_stream to remove).
  • Open 0-RTT outbound stream (dst supports single peer_id, array, or "*"):
    json
    {
      "action": "stream_open",
      "stream_id": 10,
      "dst": ["d1/appA", "d2/appB"],
      "ch": "files",
      "meta": { "mime": "image/png" }
    }
  • Write chunks via WebSocket Binary Frame: [4-byte BE stream_id][raw bytes] (recommended ≤ 64 KiB per frame).
  • Close cleanly or abort/reject:
    json
    { "action": "stream_close", "stream_id": 10, "ok": true }
    { "action": "stream_close", "stream_id": 7, "ok": false, "err_code": "STREAM_REJECTED", "err_msg": "unsupported mime" }

4. Minimal Raw Examples ​

Prefer the Official SDKs

For production integrations, use @connekt/client or connekt (Python) instead of writing raw HTTP/WS code by hand.

Raw Browser / Node WebSocket ​

ts
const ws = new WebSocket("ws://127.0.0.1:9527/api/v1/control");
ws.onmessage = (e) => {
  const msg = JSON.parse(e.data);
  if (msg.event === "message" && msg.ch === "network") {
    console.log("Packet:", msg.src, msg.payload);
  }
};

Raw Python HTTP ​

python
import json, urllib.request

with urllib.request.urlopen("http://127.0.0.1:9527/api/v1/peers") as r:
    peers = json.loads(r.read())["peers"]
print("Online peers:", [p["peer_id"] for p in peers])

Released under the MIT License.