dat-conventions

द्वारा facebook

Kotlin पैटर्न, DatResult, सत्र और क्षमता सम्मेलन DAT SDK Android विकास के लिए

npx skills add https://github.com/facebook/meta-wearables-dat-android --skill dat-conventions

DAT SDK Conventions (Android)

Quick Reference

TaskCommand
Build app./gradlew assembleDebug
Run tests./gradlew test
Install app./gradlew installDebug
Lint app./gradlew lint

Architecture

The SDK is organized into four public modules:

  • mwdat-core: Registration, permissions, devices, and session creation
  • mwdat-camera: Camera capability, video frames, and photo capture
  • mwdat-display: Display capability, display UI components, icons, images, buttons, and video
  • mwdat-mockdevice: MockDeviceKit for testing without hardware

Initialization and session setup

DeviceSession.start() is fire-and-forget and returns Unit; capabilities can only be attached once the session reports DeviceSessionState.STARTED.

Wearables.initialize(context)

Wearables.createSession(AutoDeviceSelector()).fold(
    onSuccess = { session ->
        lifecycleScope.launch {
            session.state.collect { state ->
                if (state == DeviceSessionState.STARTED) {
                    session.addCamera(StreamConfiguration()).fold(
                        onSuccess = { camera ->
                            camera.stream.start().onFailure { error, _ ->
                                showError(error.description)
                            }
                        },
                        onFailure = { error, _ -> showError(error.description) },
                    )
                }
            }
        }
        lifecycleScope.launch {
            session.errors.collect { error -> showError(error.description) }
        }
        session.start()
    },
    onFailure = { error, _ -> showError(error.description) },
)

Kotlin patterns

  • Use DatResult<T, E> for typed success and failure handling
  • Prefer fold, onSuccess, and the two-parameter onFailure { error, cause -> } overload, which hands you the typed DatError with a description
  • getOrElse { } receives a raw Throwable, not a typed DatError, so it cannot read error.description
  • Observe state with StateFlow and Flow
  • Create a DeviceSession first, then attach capabilities such as Camera or Display after it reaches STARTED
  • Keep frame handling off the main thread when doing heavier processing

Error handling

Wearables.checkPermissionStatus(Permission.CAMERA)
    .onSuccess { status -> /* handle status */ }
    .onFailure { error, _ -> /* handle error */ }

Avoid getOrThrow() in user-facing samples. Surface typed errors from DatResult instead.

Naming conventions

TypePurposeExample
DeviceSessionDevice connection lifecycleWearables.createSession(...)
CameraCamera capability on a sessionsession.addCamera(...)
StreamVideo stream from a cameracamera.stream
DisplayDisplay capability on a sessionsession.addDisplay(...)
*SelectorDevice targetingAutoDeviceSelector, SpecificDeviceSelector
*ErrorTyped failure surfaceDeviceSessionError, StreamError, CaptureError

Key types

  • Wearables — SDK entry point
  • DeviceSession — lifecycle for an interaction with a linked device
  • Camera — camera capability attached to a session
  • Stream — video stream accessed through camera.stream
  • Display — display capability attached to a session
  • StreamConfiguration — video quality, frame rate, and compression configuration
  • MockDeviceKit — simulated device environment for testing

Live docs search

If your editor supports remote MCP servers, connect https://mcp.developer.meta.com/wearables and use search_dat_docs for current DAT setup, session lifecycle, camera streaming, MockDeviceKit, permissions, and exact API symbols. This public docs server does not require authentication; do not configure tokens, OAuth, or custom authorization headers for it.

See the dat-docs-mcp skill for client setup and troubleshooting. Use llms.txt when your tool only supports static reference context.

Testing with MockDeviceKit

val mockDeviceKit = MockDeviceKit.getInstance(context)
mockDeviceKit.enable()
mockDeviceKit.pairGlasses(GlassesModel.RAYBAN_META).fold(
    onSuccess = { device -> onMockDevicePaired(device) },
    onFailure = { error, _ -> showError(error.description) },
)

Use MockDeviceKit to drive registration, device availability, streaming media, and permission scenarios without physical hardware.

Common pitfalls

  • Do not call SDK APIs before Wearables.initialize(context)
  • Do not call addCamera(...) or addDisplay() immediately after session.start(); wait for DeviceSessionState.STARTED
  • Do not assume a session implies streaming or display access; capabilities are attached separately
  • Do not ignore DatResult failures from createSession, start, addCamera, addDisplay, or capturePhoto
  • Do not reuse terminally stopped sessions, cameras, or streams

Links

facebook की और Skills

gc-safe-coding
facebook
पूर्ण स्पष्टीकरण और तर्क के लिए, doc/GCSafeCoding.md देखें।
app-review-prep
facebook
Meta ऐप को App Review के लिए तैयार करें — वर्तमान स्थिति, लंबित आवश्यकताएँ, प्रदत्त विशेषाधिकार, और सबमिशन इतिहास जाँचें। ऐप सबमिट करने से पहले उपयोग करें…
api-health
facebook
मेटा ऐप के लिए API स्वास्थ्य की निगरानी करें — दर सीमाएँ, कॉल वॉल्यूम और API डिप्रिकेशन जाँचें। थ्रॉटलिंग का निदान करने, क्षमता की योजना बनाने या API संस्करण… के लिए तैयारी करने हेतु उपयोग करें।
debug-webhooks
facebook
मेटा ऐप के लिए वेबहुक समस्याओं का निवारण करें — सक्रिय सदस्यताओं की जाँच करें, गलत कॉन्फ़िगरेशन की पहचान करें, और डिलीवरी सत्यापित करने के लिए परीक्षण पेलोड भेजें। तब उपयोग करें जब…
api-integration
facebook
किसी डेवलपर को शुरू से Meta API इंटीग्रेशन सेट करने में मार्गदर्शन करें — सही APIs खोजें, सेटअप गाइड प्राप्त करें, प्रमाणीकरण आवश्यकताएँ,…
webhook-setup
facebook
Meta ऐप के लिए webhooks को end-to-end सेट करें — उपलब्ध topics खोजें, fields को subscribe करें, और test payload से verify करें। इसका उपयोग webhooks कॉन्फ़िगर करते समय करें…
test-ui
facebook
iwsdk CLI का उपयोग करके पोक उदाहरण के विरुद्ध Test UI सिस्टम (PanelUI, ScreenSpace) का परीक्षण करें।
flags
facebook
React रिलीज़ चैनलों में फीचर फ्लैग स्थितियों का निरीक्षण और तुलना करें। सभी चैनलों (www, www-modern, canary, next, experimental, rn वेरिएंट) में सभी फ्लैग देखें या --diff के साथ विशिष्ट चैनलों की तुलना करें। आउटपुट प्रारूपों में डिफ़ॉल्ट तालिका दृश्य, CSV निर्यात और क्लीनअप स्थिति समूहीकरण शामिल है। फ्लैग स्थितियाँ प्रतीकों द्वारा इंगित की जाती हैं: सक्षम (✅), अक्षम (❌), वेरिएंट परीक्षण (🧪), केवल प्रोफाइलिंग