Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The Expo / React Native player for iOS and Android, with its own `package.json`,
- **iOS uses the UIScene life cycle (`expo-build-properties` `ios.enableSceneSupport`).** Without it an iOS 27-SDK build is killed at launch on iOS 27; drop it with the SDK 58 upgrade, whose template does the same (TESTING.md).
- **OTA cannot reach native code.** The Live Activity card (Lock Screen, Dynamic Island, the Apple Watch Smart Stack) is SwiftUI under `targets/live-activity/` and `modules/live-activity/ios/`, so a change there ships only in a new binary, like a dependency, `patches/`, plugin or native `app.json` change; the JS that drives it (`src/hooks/useLiveActivity.ts`) is OTA-able. The same holds for the App Intents (Siri, Shortcuts): Swift under `targets/live-activity/_shared/` and `modules/app-intents/ios/`, JS under `src/intents/`. `SubwaveLiveAttributes.swift` is compiled into both and must stay byte-identical (`npm test` checks): a mismatch stops the card rendering instead of failing the build.
- **Android Auto's browse session is RNTP's own**, reached through the patch's `MediaBrowserBridge`; `modules/android-auto` only lists stations, and a pick reaches `service.ts` as `remote-play-id`. Play enforced against a TTS-reading app once (#477); TESTING.md has the history and the device check.
- **The CarPlay app is off unless `SUBWAVE_CARPLAY=1` is set at prebuild** (`plugins/withCarPlay.js`), because a device build can't be signed with the CarPlay entitlement until Apple grants it. Unset, the Info.plist and entitlements are unchanged (`npm test` checks). Its Swift is `targets/live-activity/_shared/SubwaveCarPlay.swift` (TESTING.md).
- **The station password is not the station login** (#478). Every check is the fail-closed `POST /station-auth`, and only the controller's own answers count: a 200 with its `{ ok: true }` body is a right password and a 401 with its `{ ok: false }` body a wrong one, while anything else keeps a saved password and saves no typed one (`stationAuthResult`, #2143, #2164); the password rides the stream as `?auth=` so Cast works; `createApi` reads it through a getter because the feed reset and the Live Activity lifecycle key on the `api` object's identity, so rebuilding the client on unlock would reset both. While playback is stuck, `src/lib/stuck-password-check.ts` asks again after every answer but a denial, never within 120 s of the last check or before a 429's `Retry-After` runs out, capped at the route's own window: it allows a household's address 20 attempts per 15 minutes (#2141, #2164). When the gate's stop takes a tuned-in listener off the air, the right typed password tunes them back in with no second press (`src/lib/gate-resume.ts`, the twin of the web's `lib/gateResume.ts`), through `tune`, so it is a listener's own load in `stream-recovery.ts`. `useStationGate` outlives a station switch, so the hold names the `api` it was taken on, and `tune` toggles, so it never runs for a listener already tuned in.
- **Every stream reload goes through `src/lib/stream-recovery.ts` while the player is mounted** (#2114, #2139): one at a time, and never on a state event alone. A listener's own load (a tune-in, a retune, a Play from the lock screen, a headset, CarPlay or Bluetooth) always loads, queued behind one in flight. `service.ts` hands a remote Play to the mounted player (`src/lib/remote-play.ts`) and loads directly only when none is mounted, which Android's headless service allows; an App Intent's tune-in and station switch do the same (`src/intents/tune-flow.ts`), and so does an Android Auto pick. The watchdog, churn guard and error backoff each check the native media clock first, because a reload re-sends Icecast's burst and the listener hears audio twice; a regained link reads it through the pending check it brings forward, and with none pending reloads at once. Every load is checked even when it reports no state (iOS drops a repeated Loading, #2143), and an automatic reload is a failure until its item stays up, so a hung station backs off to 60 s. Playing resets that only provisionally: an item that fails after stopping within 4 s of its first Playing, judged from the moment it stopped, takes the reset back, and the reload after it waits at most 16 s, so a stream cut a moment in can't reload 35-60 times a minute. A stall never counts, however early, and stays on the 6 s watchdog: Icecast closes a stalled socket about 15 s after its source stops, so a longer wait hears that close as a failure, and a flapping source climbs to a minute of silence. A hold counts as the item's Playing, because JS can miss the real one. None of this runs during an iOS audio interruption (a call, Siri), which freezes the clock without a state event.
- **The idle skip changes only the native rate, never seeks or reloads** (#9, the port of web's `idleSkip.ts`, kept in step with it). It runs on an MP3 load in the foreground, reads `/state` only after that load's first Playing, and ends on any stall, pause, interruption or backgrounding, since JS timers can stop while the 8x would not. `loadAndPlay` resets the rate to 1x because RNTP carries it to the next item. What it shed reaches the feed as `leadTrimMs`, so the track clock and the DJ's lines move with the listener.
Expand Down
1 change: 1 addition & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"backgroundColor": "#100e0c"
}
],
"./plugins/withCarPlay",
[
"expo-build-properties",
{
Expand Down
63 changes: 61 additions & 2 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ template still starts React Native from the app delegate, so `expo-build-propert
SDK 58 template does: a scene manifest naming Expo's `ExpoAppSceneDelegate` (it
creates the window, starts React Native and forwards URL and lifecycle events to
the app delegate), and an app delegate that only creates the factory. Drop the
option with the SDK 58 upgrade; it warns and does nothing there.
option with the SDK 58 upgrade; it warns and does nothing there. `plugins/withCarPlay.js`
edits that manifest when CarPlay is on, so after the upgrade check it still finds one
(`scripts/carplay-plugin.test.ts` builds it through expo-build-properties). Check
`SubwavePhoneSceneDelegate` (`targets/live-activity/_shared/SubwaveCarPlay.swift`) too:
it subclasses `ExpoAppSceneDelegate` and, when it adopts a running window instead
of calling `super`, re-sends the connection's URLs, user activities and quick
action through that class's own `scene(_:openURLContexts:)`, `scene(_:continue:)`
and `windowScene(_:performActionFor:)`. If SDK 58's delegate handles more at
connect time, or renames those, the adopt path must follow.

EAS builds SDK 57 with **Xcode 26.6** (the `sdk-57` image) unless `eas.json`
names another, so a default store build has none of the iOS 27-only code
Expand Down Expand Up @@ -251,7 +259,7 @@ head unit) should show the new title without unlocking.

### CarPlay — Now-Playing in the car (iOS only)

Scope is **Tier 1**: control the *already-playing* stream from the dash (metadata,
Every build today is **Tier 1**: control the *already-playing* stream from the dash (metadata,
artwork, play/pause/stop). There is **no launchable in-car app icon** — start the
stream in the phone app first, then connect the car. RNTP feeds the iOS surface
(`MPNowPlayingInfoCenter`), so CarPlay needs **no extra app-side wiring**.
Expand All @@ -262,6 +270,57 @@ stream in the phone app first, then connect the car. RNTP feeds the iOS surface
Play/Pause work; no scrubber (the `isLiveStream` track hides it). On iOS 26+
the Live Activity's `.small` card also appears on the CarPlay Dashboard.

**Tier 2, the CarPlay app, is built but switched off.** It puts SUB/WAVE in the
car's app grid: the saved stations as a list, tap one to tune in, then the system
Now Playing screen with a heart. It needs Apple's `com.apple.developer.carplay-audio`
entitlement, which Apple grants on request (developer.apple.com/carplay), and a
device build cannot be signed with it until the grant is on the App ID. So
`plugins/withCarPlay.js` does nothing unless `SUBWAVE_CARPLAY=1` is set at prebuild:
unset, the Info.plist and entitlements are what they were. Once the grant lands, set
it in `eas.json`'s `env` for the iOS profiles.

- **Swift draws, JS decides.** `targets/live-activity/_shared/SubwaveCarPlay.swift`
reads the stations the app already mirrors for Siri (`SavedStations`, App Group),
and a tap goes through the App Intents bridge as `tuneIn`, so switching and tuning
in are `src/intents/tune.ts` (`tune-flow.ts` decides): handed to the mounted player
when there is one, and cut to the bridge's deadline like any Siri tune-in. The heart is the bridge's `like`, and a failed like
shows the bridge's message in an alert. The list redraws on `SubwaveStationsChanged`
and `SubwaveOnAirChanged` (posted by the module's `setStations` and `setOnAir`); the
on-air flag is read through `OnAirFlag` (`_shared/OnAirFlag.swift`), shared with the
tune control.
- **The car can launch the app with no phone screen.** Under the scene life cycle
React Native starts when the phone's window scene connects, and a car launch
connects only the CarPlay scene. So the CarPlay delegate starts React Native into a
window with no scene (`ReactBoot`), and the plugin swaps the phone role's delegate
for `SubwavePhoneSceneDelegate`, which moves that window onto the phone's scene
(sized to it) when it connects instead of starting a second copy. A process the
car started has played nothing, so `ReactBoot` clears an on-air flag a killed app
left set.
- **Multiple scenes are on with the flag.** Apple's CarPlay manifest sets
`UIApplicationSupportsMultipleScenes` (the app declares a phone scene and a CarPlay
one) and names `CPTemplateApplicationScene` as the CarPlay scene class, so the plugin
does both. On iPad that also lets the system open a second window of the app;
`SubwavePhoneSceneDelegate` asks for that session's destruction, because one React
tree plays one stream. Unset, the manifest stays `false`.
- **Testing it.** Xcode 27 has no Simulator.app, and DeviceHub offers no CarPlay
display for a simulator (FB24785359). The routes are Xcode 26's Simulator.app,
DeviceHub's CarPlay Simulator with a USB iPhone (needs the entitlement in the
profile), or the third-party NeoSimulator (needs Full Disk Access to switch the
display host; the iOS 27.0 runtime has no CarPlay mode, so use iOS 18 or 26).
Build with `SUBWAVE_CARPLAY=1 npx expo prebuild -p ios`, then check: the list shows
each saved station with its host and marks the playing one; a tap spins, then
plays and pushes Now Playing; a failure shows the bridge's message in an alert;
a heart with nothing on air shows the bridge's message too; adding a station on
the phone updates the list. Then cold: play a station, kill the app, connect
CarPlay, open SUB/WAVE from the car (no station is marked playing), tap a station
(it must play), then open the phone app (it must fill the screen and show the same
playback, tuned in, with no second player). On an iPad build with the flag, a
second window (drag the app from the Dock) must close rather than open a player.
- **Verified so far (2026-11):** it builds with Xcode 27, a normal phone launch
goes through `SubwavePhoneSceneDelegate` (2026-10), and the plugin's plist edits
are under `npm test`. The CarPlay screens, the car-first launch and the iPad second
window are not yet run.

### Android Auto — the station list in the car (Android only)

SUB/WAVE lists in Android Auto as a media app: the saved stations, tap one to tune
Expand Down
17 changes: 13 additions & 4 deletions modules/app-intents/ios/SubwaveAppIntentsModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ private let requestName = Notification.Name("SubwaveIntentRequest")
private let ackName = Notification.Name("SubwaveIntentAck")
private let replyName = Notification.Name("SubwaveIntentReply")

// The tune control's state (targets/live-activity/TuneControl.swift), matched
// by STRING like the names above.
// Whether the station is on, read by OnAirFlag in
// targets/live-activity/_shared/OnAirFlag.swift for the tune control
// (targets/live-activity/TuneControl.swift) and the CarPlay station list.
// Matched by STRING like the names above.
private let appGroup = "group.com.getsubwave.app"
private let onAirKey = "subwave.onAir"
private let onAirChangedName = Notification.Name("SubwaveOnAirChanged")
private let tuneControlKind = "com.getsubwave.app.tune"
// The saved stations, read by SavedStations in
// targets/live-activity/_shared/StationEntities.swift, and the app-target class
// that re-indexes them for Spotlight and the Siri phrases with a station in
// them. That code sees the entity types; this pod does not, so it is reached
// by name.
// by name. The CarPlay station list redraws on the name (savedStationsChanged
// there), also matched by STRING.
private let stationsKey = "subwave.stations"
private let stationsChangedName = Notification.Name("SubwaveStationsChanged")
private let stationIndexClass = "SubwaveStationIndex"

public class SubwaveAppIntentsModule: Module {
Expand Down Expand Up @@ -104,16 +109,20 @@ public class SubwaveAppIntentsModule: Module {
if #available(iOS 18.0, *) {
ControlCenter.shared.reloadControls(ofKind: tuneControlKind)
}
// The CarPlay station list marks the station that is playing.
NotificationCenter.default.post(name: onAirChangedName, object: nil)
}

/// The saved stations and the active one, as JSON from JS:
/// `{ active, stations: [{ id, name }] }`. Names and credential-free bases
/// only. Writes them for the intents and re-indexes Spotlight.
/// only. Writes them for the intents, re-indexes Spotlight and tells the
/// CarPlay station list.
Function("setStations") { (json: String) in
UserDefaults(suiteName: appGroup)?.set(json, forKey: stationsKey)
if let index: AnyClass = NSClassFromString(stationIndexClass) {
_ = (index as AnyObject).perform(NSSelectorFromString("reindex"))
}
NotificationCenter.default.post(name: stationsChangedName, object: nil)
}
}

Expand Down
75 changes: 75 additions & 0 deletions plugins/withCarPlay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Expo config plugin: the CarPlay app, behind SUBWAVE_CARPLAY=1.
//
// The CarPlay UI is Swift in targets/live-activity/_shared/SubwaveCarPlay.swift. This
// plugin only switches it on:
//
// 1. `com.apple.developer.carplay-audio` in the entitlements. Apple grants
// it on request, and a DEVICE build cannot be signed with it until the
// grant is on the App ID, so it is opt-in: set SUBWAVE_CARPLAY=1 for a
// simulator build (the CarPlay simulator ignores provisioning) and, once
// the grant lands, in eas.json. Unset, the app is exactly as before.
// 2. A CarPlay scene role in the scene manifest that `ios.enableSceneSupport`
// writes, multiple scenes on, and the phone role's delegate swapped for
// PhoneSceneDelegate, which adopts React Native when the car launched the
// app first and refuses a second window.
//
// Must come BEFORE expo-build-properties in app.json: a later plugin's Info.plist
// mod runs first, and this one edits the manifest that one creates.
// scripts/carplay-plugin.test.ts checks both, flag set and unset.
//
// Usage in app.json plugins: "./plugins/withCarPlay"

const { withEntitlementsPlist, withInfoPlist } = require('@expo/config-plugins');

const ENTITLEMENT = 'com.apple.developer.carplay-audio';
const PHONE_ROLE = 'UIWindowSceneSessionRoleApplication';
const CAR_ROLE = 'CPTemplateApplicationSceneSessionRoleApplication';

function carPlayEnabled() {
return process.env.SUBWAVE_CARPLAY === '1';
}

function withCarPlayEntitlement(config) {
return withEntitlementsPlist(config, (cfg) => {
if (carPlayEnabled()) cfg.modResults[ENTITLEMENT] = true;
else delete cfg.modResults[ENTITLEMENT];
return cfg;
});
}

function withCarPlayScene(config) {
return withInfoPlist(config, (cfg) => {
if (!carPlayEnabled()) return cfg;
const written = cfg.modResults.UIApplicationSceneManifest;
if (!written?.UISceneConfigurations?.[PHONE_ROLE]?.[0]) {
throw new Error(
'withCarPlay: no scene manifest. Turn on expo-build-properties ios.enableSceneSupport, ' +
'and list ./plugins/withCarPlay before expo-build-properties in app.json.',
);
}
// A copy: expo-build-properties hands over its own module-level manifest,
// and compares later ones against it to tell its manifest from the app's.
const manifest = structuredClone(written);
// Apple's CarPlay manifest (developer.apple.com/documentation/carplay/
// building-your-apps-initial-carplay-interface): multiple scenes on, since
// the app declares a phone scene and a CarPlay one, and the CarPlay class
// named. On iPad that also allows a second window, which
// PhoneSceneDelegate refuses.
manifest.UIApplicationSupportsMultipleScenes = true;
manifest.UISceneConfigurations[PHONE_ROLE][0].UISceneDelegateClassName =
'SubwavePhoneSceneDelegate';
manifest.UISceneConfigurations[CAR_ROLE] = [
{
UISceneClassName: 'CPTemplateApplicationScene',
UISceneConfigurationName: 'CarPlay',
UISceneDelegateClassName: 'SubwaveCarPlaySceneDelegate',
},
];
cfg.modResults.UIApplicationSceneManifest = manifest;
return cfg;
});
}

module.exports = function withCarPlay(config) {
return withCarPlayScene(withCarPlayEntitlement(config));
};
Loading
Loading