Android: replies never stream in over a companion (LAN/Tailscale) pairing, only after restarting the app

Aperta
#57 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, typescript
Ambito
mobile, networking

Direzione di ricerca

Start with apps/companion/src/proxy.ts and src/mobile/transport/transport.ts, then trace how installTransport opens the event stream and how companion requests check Origin. The issue reports a local native Android streaming plugin as a working fix and notes that the WebSocket viewer needs a similar path or origin handling. Done when companion replies stream to Android without restarting and the live computer view works.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
What happened

Paired with the Mac over the companion (both the Wi-Fi and the Tailscale pairing). Sending a message works and the desktop shows it, but the bot's reply never appears on the phone. It only shows after the app is killed and reopened. The live computer view (the display icon) stays blank for what looks like the same reason.

Cause: the companion rejects any request that carries an Origin header before it looks at the token (apps/companion/src/proxy.ts, "A native app sends no Origin"; handle.upgrade does the same for WebSockets). Ordinary requests go through CapacitorHttp (native, no Origin) and work. But installTransport (src/mobile/transport/transport.ts) opens the event stream with the WebView's own fetch (CapacitorWebFetch), and the WebView always sends Origin: https://localhost. So the stream gets 403 {"error":"forbidden: cross-origin request"}. Reproduced with curl:

curl -H "Origin: https://localhost" http://<mac>:8810/api/events   -> 403 forbidden: cross-origin request
curl http://<mac>:8810/api/events                                  -> 401 (reaches the token check)

CapacitorHttp can't carry the stream, because it buffers the whole body. What fixed it locally: a small native Android plugin that does the streaming GET with HttpURLConnection and passes chunks to JS as events, plus a fetch-shaped shim that installTransport uses as streamFetch for http: (companion) origins. Replies now stream in live. Happy to open a PR with it if that approach is welcome. The WebSocket viewer would need a similar native path, or the companion would need to accept the app's own origins (https://localhost, capacitor://localhost) with a valid token.

Setup: desktop 0.2.17 on macOS; phone app built from main at 7791c1f (apps/mobile, Android debug build, Samsung Galaxy S26), paired over the companion (port 8810).

Steps to reproduce
  1. Build apps/mobile for Android (allowing cleartext, see the readiness notes) and pair with a Mac over Wi-Fi or Tailscale.
  2. Send a bot a message from the phone.
  3. The reply appears on the desktop but not on the phone until the app is restarted.
Version

0.2.17 (desktop, macOS); phone app from main @ 7791c1f

Platform

Android

Engine

No response

Logs or screenshots

Lingua principale
TypeScript
Stelle
277
Fork
27
Merge medio
2h 47m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di DuskBotAI/duskbot

Tutte le issue di DuskBotAI/duskbot

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.