Repository navigation
fix(mobile): add native Android streaming client for SSE and relay streams - #104
Open
Satya-Siba-Nayak wants to merge 1 commit into
Open
Satya-Siba-Nayak wants to merge 1 commit into
Satya-Siba-Nayak wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Fixes #103 (follow-up to #93 / #94, and addresses Android companion SSE streaming in #57).
#94 (
ee66db7069) addednetwork_security_config.xmlandACCESS_LOCAL_NETWORKso Android can pair and load chats over LAN viaCapacitorHttp, while intentionally deferring the native streaming layer. Without native streaming onwindow.CapacitorWebFetch, Android connects initially and then drops toReconnecting/Not connected:/api/events): Android WebView serves the app fromhttps://localhostwithallowMixedContent: false, blocking raw WebViewfetch(CapacitorWebFetch) to plain-HTTP companion SSE streams before the request leaves the device./v1/channels/<id>/to-app?wait=25&stream=1): Raw WebViewfetchsends a CORS preflight (Origin: https://localhost,Access-Control-Request-Headers: authorization), whichlink-servicedoes not currently answer (404with noAccess-Control-Allow-*headers)..localhosts to an activeTRANSPORT_WIFINetworkkeeps LAN streams on Wi-Fi without affecting Tailscale (100.x.y.z/.ts.net) or public relay hosts.Changes
apps/mobile/android/app/src/main/java/bot/dusk/mobile/SseStreamPlugin.java: Adds theDuskStreamnative Android plugin backed byHttpURLConnection(sends noOrigin, respectsnetwork_security_config.xml, usesTextUtils.joinforminSdkVersion 24compatibility). Streams SSE (text/event-stream,/api/events,/stream) and relay NDJSON (application/x-ndjson,stream=1) incrementally via Capacitorchunk/endevents, enforceshttp/httpsschemes only, and binds RFC 1918 /.localhosts toTRANSPORT_WIFI.apps/mobile/android/app/src/main/java/bot/dusk/mobile/MainActivity.java: RegistersSseStreamPlugin.class.apps/mobile/src/native-platform.ts: ExportscreateNativeStreamFetchand wiresDuskStreamonly ontowindow.CapacitorWebFetchon Android (idempotent). Leaveswindow.fetch(CapacitorHttp,installNativeAbort,nativeBodybinary uploads, long timeouts), same-origin URLs (including/_capacitor_http_interceptor_), non-HTTP URLs (blob:,data:), and iOS completely untouched. PreservesAbortError/TimeoutErrorandredirect: "error"3xx rejection.src/mobile/native-stream.test.ts: Unit tests for SSE streaming, relaystream=1NDJSON streaming +x-link-beatheader passthrough, same-origin/_capacitor_http_interceptor_/data:passthrough,AbortSignalcancellation + nativeclose(),redirect: "error"3xx rejection, inline responses, and reader cancel cleanup.Kept strictly scoped to Android native streaming (server-side CORS preflight support in
apps/link-service/src/app.mjsis left out of this PR per one-concern-per-PR guidelines).How it was checked
pnpm lint(oxlint --deny-warnings .): 0 warnings, 0 errors.pnpm --filter @duskbot/mobile typecheckandtsc -b: passed cleanly.pnpm --filter @duskbot/mobile buildandnode apps/mobile/scripts/release-gate.mjs: built cleanly and passed release gate.vitest run src/mobile/: 62/62 test files passed (567/567 tests), plusscripts/testing/file-size-ratchet.test.tsandscripts/testing/comment-history.test.tspassed.Local Gradle APK build was not run from this Windows machine; verifiable via
android-smoke.yml.pnpm lint, mobile typecheck,tsc -b, mobile build + release gate, and fullsrc/mobile/+ guard tests pass (server/tsconfig.jsonhas unrelated pre-existing errors ondevinserver/mac-control/*)New behaviour has a test (
src/mobile/native-stream.test.ts)No secrets, personal data or local paths in the diff or screenshots