audio-streaming
Receive synchronized PCM audio frames through a Camera stream on iOS
Device session states, pause/resume, availability monitoring
$ npx -y skills add facebook/meta-wearables-dat-ios --skill session-lifecycle --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/session-lifecycleContext preview
The summary Claude sees to decide when to auto-load this skill.
Device session states, pause/resume, availability monitoring
name: session-lifecycle description: Device session states, pause/resume, availability monitoring
Guide for managing device session states in DAT SDK integrations.
The DAT SDK runs work inside sessions. Meta glasses expose two experience types:
Your app observes session state changes — the device decides when to transition.
| State | Meaning | App action | |-------|---------|------------| | `idle` | Session created but not started | Call `start()` when ready | | `starting` | Session is connecting to the device | Show connecting state | | `started` | Session active and ready for capabilities | Add or resume work | | `paused` | Temporarily suspended by the device | Hold work, may resume | | `stopping` | Session is cleaning up | Wait for terminal state | | `stopped` | Session inactive and terminal | Free resources, create a new session to restart |
let session = try Wearables.shared.createSession(deviceSelector: AutoDeviceSelector(wearables: Wearables.shared))
try session.start()
Task {
for await state in session.stateStream() {
switch state {
case .started:
// Confirm UI shows session is live
case .paused:
// Keep connection, wait for started or stopped
case .stopped:
// Release resources, allow user to restart
default:
break
}
}
}`DeviceSession` exposes both shapes: `stateStream()` / `errorStream()` as `AsyncStream`, and `statePublisher` / `errorPublisher` as listener-token `Announcer`s. Pick one per call site; subscribe before calling `start()` so no initial transition is missed.
`errorStream()` and `errorPublisher` emit `DeviceSessionError`. Handle `.noEligibleDevice` (no matching device yet), `.sessionAlreadyExists`, `.capabilityAlreadyActive`, the thermal/battery cases (`.thermalCritical`, `.thermalEmergency`, `.peakPowerShutdown`, `.batteryCritical`), and `.datAppOnTheGlassesUpdateRequired`, which is delivered as a one-shot event and should open `Wearables.shared.openDATGlassesAppUpdate()`.
`start()` uses typed throws, so you can catch the specific case:
do throws(DeviceSessionError) {
try session.start()
} catch .datAppOnTheGlassesUpdateRequired {
showGlassesAppUpdatePrompt()
} catch {
showError(error.localizedDescription)
}A `Stream` is a capability attached to a started `DeviceSession`:
stopped → waitingForDevice → starting → streaming → paused → stopped
guard let camera = try session.addCamera(config: StreamConfiguration()) else { return }
let stream = camera.stream
let token = stream.statePublisher.listen { state in
Task { @MainActor in
// React to state changes
}
}The device changes session state when:
When a session is paused:
Your app should **not** attempt to restart while paused — wait for `started` or `stopped`.
Monitor device availability to know when sessions can start:
Task {
for await deviceIds in Wearables.shared.devicesStream() {
// deviceIds is [DeviceIdentifier]; resolve details with deviceForIdentifier(_:)
}
}A `DeviceSelector` also reports availability directly. `AutoDeviceSelector` and `SpecificDeviceSelector` both expose `activeDevice` and `activeDeviceStream()`, which yields `nil` when no eligible device is available:
let selector = AutoDeviceSelector(wearables: Wearables.shared)
Task {
for await deviceId in selector.activeDeviceStream() {
hasActiveDevice = deviceId != nil
}
}Key behaviors:
The Meta Wearables Device Access Toolkit enables developers to utilize Meta's AI glasses to build hands-free wearable experiences into their mobile applications.
Receive synchronized PCM audio frames through a Camera stream on iOS
Capture standalone high-quality photos from connected glasses on iOS
Stream, video frames, photo capture, resolution/frame rate configuration
Swift patterns, async/await, naming conventions, key types for DAT SDK iOS development
Use the Wearables DAT MCP server for live DAT documentation search with `search_dat_docs`,…