session-lifecycle

작성자: facebook

장치 세션 상태, 일시 중지/재개, 가용성 모니터링

npx skills add https://github.com/facebook/meta-wearables-dat-ios --skill session-lifecycle

Session Lifecycle (iOS)

Guide for managing device session states in DAT SDK integrations.

Overview

The DAT SDK runs work inside sessions. Meta glasses expose two experience types:

  • Device sessions — sustained access to device sensors and outputs
  • Transactions — short, system-owned interactions (notifications, "Hey Meta")

Your app observes session state changes — the device decides when to transition.

Session states

StateMeaningApp action
idleSession created but not startedCall start() when ready
startingSession is connecting to the deviceShow connecting state
startedSession active and ready for capabilitiesAdd or resume work
pausedTemporarily suspended by the deviceHold work, may resume
stoppingSession is cleaning upWait for terminal state
stoppedSession inactive and terminalFree resources, create a new session to restart

Observing session state

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
        }
    }
}

Stream state transitions

A Stream is obtained from the Camera 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
    }
}

Common transitions

The device changes session state when:

  • User performs a system gesture that opens another experience
  • Another app starts a device session
  • User removes or folds the glasses (Bluetooth disconnects)
  • User removes the app from Meta AI companion app
  • Connectivity between companion app and glasses drops

Pause and resume

When a session is paused:

  • The device keeps the connection alive
  • Streams stop delivering data
  • The device may resume by returning to started

Your app should not attempt to restart while paused — wait for started or stopped.

Device availability

Monitor device availability to know when sessions can start:

Task {
    for await devices in Wearables.shared.devicesStream() {
        // Update list of available glasses
    }
}

Key behaviors:

  • Closing hinges disconnects Bluetooth → forces stopped
  • Opening hinges restores Bluetooth but does not restart sessions
  • Start a new session after the device becomes available again

Implementation checklist

  • Handle all relevant session states (started, paused, stopped)
  • Monitor device availability before starting work
  • Release resources only after stopped
  • Don't infer transition causes — rely only on observable state
  • Don't restart during paused — wait for system to resume or stop

Links

facebook의 다른 스킬

binary-size-analysis
facebook
git 커밋 범위에 걸쳐 hermesvm 공유 라이브러리의 커밋별 바이너리 크기 변화를 분석합니다. 커밋별 크기와 주요 증가 및 감소 요약 테이블이 포함된 마크다운 보고서를 생성합니다.
official
modify-jsi-features
facebook
JavaScript Interface (JSI) 레이어에 새로운 JSI 기능을 추가하기 위한 가이드입니다. 사용자가 새로운 메서드나 기능을 추가, 생성 또는 구현하도록 요청할 때 사용하세요.
official
non-interactive-git-rebase
facebook
최상위 커밋이 아닌 git 커밋을 재정렬, 분할, 삭제 또는 수정해야 하며 대화형 편집기 접근이 불가능할 때 사용합니다. 프로그래밍 방식의 리베이스를 다룹니다…
official
click-target
facebook
XR에서 대상 객체를 찾아 클릭합니다. UI 상호작용 테스트, 버튼 클릭, 또는 상호작용 가능한 요소가 올바르게 작동하는지 확인할 때 사용하세요.
official
iwsdk-planner
facebook
IWSDK 프로젝트 계획 및 모범 사례 가이드. 새로운 IWSDK 기능을 계획하거나, 시스템/컴포넌트를 설계하거나, IWSDK 코드 아키텍처를 검토할 때, 또는...
official
iwsdk-ui-panel
facebook
IWSDK UI 패널을 효율적으로 개발하고 반복 개선합니다. PanelUI 구성 요소 작업, UI 레이아웃 디버깅, 또는 IWSDK 애플리케이션의 UI 디자인 개선 시 사용하세요.
official
test-all
facebook
병렬 테스트 오케스트레이터. Task 하위 에이전트와 iwsdk CLI를 통해 9개의 모든 테스트 스위트를 동시에 실행합니다. 빌드, 예제 설정, 개발 서버, 에이전트 실행 등을 처리합니다.
official
test-audio
facebook
iwsdk CLI를 사용하여 오디오 예제에 대해 오디오 시스템(AudioSource 로딩, 재생 상태, 정지, 공간 오디오)을 테스트합니다.
official