# Spectra > Spectra is a Kotlin Multiplatform wrapper around Meta's Wearables Device Access Toolkit (DAT). It exposes one coroutine-and-Flow API in commonMain for app registration, permissions, device sessions, camera streaming, photo capture, the Ray-Ban Display, and Bluetooth audio (A2DP playback / HFP mic), with an Android backend that delegates to the real mwdat-* artifacts, a complete iOS Swift bridge (SpectraBridge.swift, against Wearables.shared), and a fully in-memory mock client for tests and previews. A developer-only MockDeviceKit simulates a Ray-Ban Meta with no hardware. Library version 0.2.1. Targets Android (minSdk 29) and iOS (15.2+). ## Core call sequence (do this in order) 1. `spectra.initialize()` — once per process, before anything else. 2. `spectra.startRegistration()` — one-time link to the Meta AI app (returns via a custom URL scheme on iOS, e.g. `spectrademo://`; no Universal Link needed). 3. Wait on `spectra.hasActiveDevice` (a `Flow`) until true — this is the reliable "device ready" signal, fed by the SDK's auto-selector. 4. `spectra.requestPermission(Permission.CAMERA)` — gates the stream's contents (not the device's existence). 5. `spectra.createSession(DeviceSelector.Auto)`, then `session.start()`, then wait for `SessionState.RUNNING`. 6. `session.openCameraStream(StreamConfiguration(...))` and/or `session.attachDisplay()`. ## Key facts and gotchas - Do NOT gate on `spectra.devices` being non-empty: with real glasses connected, the raw device list can stay empty. Wait on `spectra.hasActiveDevice` instead (the iOS backend folds `AutoDeviceSelector.activeDeviceStream()` into `devices`). When glasses fold/sleep the active device goes back to nil and the session stops. - Run the whole pipeline with no hardware via `spectra.mockDeviceKit` (null on backends that can't fake one): `enable()` then `pairGlasses()` makes a simulated device active. In the demo it's the ladybug debug button → Enable MockDeviceKit → Pair Ray-Ban Meta. - Session state is device-driven and asynchronous. Observe it; never assume the cause of a transition. `PAUSED` means hold and wait — do not restart. - Camera resolution and frame rate are requests, not guarantees; Bluetooth runs an automatic quality ladder (drops resolution first, then frame rate, never below 15fps). Valid frame rates: 2, 7, 15, 24, 30. - You cannot reconfigure a stream within a session. Stop the session and start a new one. - Display: every `sendContent` replaces the whole screen; no partial updates; the glasses retain no state. Always keep a root (L0) view because the back gesture from root ends the session. - Audio is NOT a DAT API — the glasses' speakers/mic are plain Bluetooth (A2DP output hi-fi, HFP mic 8 kHz mono), shared with the system audio stack. Spectra wraps the platform audio session behind `SpectraClient.audio: SpectraAudio?` (null if unsupported): `playToGlasses(text)` (A2DP), `startMicCapture()`/`stopMicCapture()` (HFP, emits `AudioState.micLevel`), `state: Flow`. A2DP and HFP are mutually exclusive. If capturing mic alongside a camera stream: addStream → start+settle HFP mic → then start the stream, or the route fails silently. iOS uses AVAudioSession/AVAudioEngine; Android uses AudioManager/AudioRecord and needs RECORD_AUDIO. - Use `Spectra.mock()` for tests/previews — no token, no hardware. `MockConfig(autoGrantPermissions = false)` and `MockConfig(failRegistration = true)` exercise failure paths. - Build/test: `./gradlew :spectra:allTests` (no token). Use the Gradle wrapper (Gradle 9.1 / AGP 9 / Kotlin 2.4 / Compose MP 1.11). The Android backend needs a GitHub Packages token (`github_token` in local.properties, or `GH_TOKEN` env). - Consume the published library three ways. (1) GitHub Packages / Maven (Android, KMP): add `maven { url = uri("https://maven.pkg.github.com/jacksonmafra-umain/spectra"); credentials { username = ""; password = } }` and `implementation("com.umain.spectra:spectra:0.2.1")`; also add the `com.meta.wearable` GitHub Packages repo since the Android backend is a transitive dependency. GitHub Packages requires a token even for public reads. (2) SPM (iOS): `.package(url: "https://github.com/jacksonmafra-umain/spectra", from: "0.2.1")` — a prebuilt `Spectra.xcframework` shipped as a binaryTarget on the GitHub Release, no token needed. (3) Maven Local for offline iteration: `./gradlew :spectra:publishToMavenLocal` then add `mavenLocal()`. Releases are cut by `publish.sh` (version lives in `gradle/libs.versions.toml`). ## Spectra documentation - [Spectra Docs (human site)](https://example.vercel.app/): Install, quickstart, concepts, platform notes, references. - [AGENTS.md](https://example.vercel.app/AGENTS.md): Agent-oriented rules, the call sequence, and anti-patterns to avoid. - [README](https://github.com/): Project overview, module layout, build instructions. ## Upstream Meta references (the SDK Spectra wraps) - [Device Access Toolkit overview](https://wearables.developer.meta.com/docs/develop/dat/) - [Getting started / setup](https://wearables.developer.meta.com/docs/develop/dat/getting-started-toolkit) - [Integration overview](https://wearables.developer.meta.com/docs/develop/dat/build-overview) - [Android integration](https://wearables.developer.meta.com/docs/develop/dat/build-integration-android) - [iOS integration](https://wearables.developer.meta.com/docs/develop/dat/build-integration-ios) - [Session lifecycle](https://wearables.developer.meta.com/docs/develop/dat/lifecycle-events) - [Permissions and registration](https://wearables.developer.meta.com/docs/develop/dat/permissions-requests) - [Display overview](https://wearables.developer.meta.com/docs/develop/dat/display-overview) - [Display — Android](https://wearables.developer.meta.com/docs/develop/dat/display-android) - [Display — iOS](https://wearables.developer.meta.com/docs/develop/dat/display-ios) - [Display icons](https://wearables.developer.meta.com/docs/develop/dat/display-icons) - [AI-assisted development](https://wearables.developer.meta.com/docs/develop/dat/ai-assisted) - [Known issues](https://wearables.developer.meta.com/docs/develop/dat/knownissues) - [Full Meta DAT API reference for LLMs](https://wearables.developer.meta.com/llms.txt?full=true)