class DeviceSession
errors
: SharedFlow<DeviceSessionError>
[Get] |
A SharedFlow that emits session errors.
Errors are emitted when DeviceSession.start fails (e.g., device becomes unavailable during connection), when the device disconnects externally, or when the session is ended by the device. Observe this flow alongside DeviceSession.state for comprehensive session monitoring.
Example:
session.errors.collect { error ->
when (error) {
DeviceSessionError.DEVICE_DISCONNECTED -> showReconnectPrompt()
DeviceSessionError.DEVICE_POWERED_OFF -> showDeviceOffMessage()
else -> showError(error.description)
}
}
Signature
val errors: SharedFlow<DeviceSessionError> |
state
: StateFlow<DeviceSessionState>
[Get] |
A StateFlow that provides the current state of this session.
The state progresses through DeviceSessionState.IDLE → DeviceSessionState.STARTING → DeviceSessionState.STARTED → DeviceSessionState.STOPPING → DeviceSessionState.STOPPED. The session may also transition to DeviceSessionState.PAUSED and back to DeviceSessionState.STARTED. Observe this flow to react to session lifecycle changes, including external termination (device disconnect, power off).
Both DeviceSession.start and DeviceSession.stop are sync fire-and-forget — observe this flow for completion signals.
Signature
val state: StateFlow<DeviceSessionState> |
addDisplay
(
config
)
|
Adds a display capability to this session.
Creates and starts a display connection to the device connected to this session. Only one display can exist per session — calling this method when a display is already attached returns DeviceSessionError.CAPABILITY_ALREADY_ADDED.
The display must be added after the session reaches DeviceSessionState.STARTED. Adding a display to an idle session returns DeviceSessionError.SESSION_IDLE, and adding to a stopped session returns DeviceSessionError.SESSION_ALREADY_STOPPED.
Example:
session.addDisplay().fold(
onSuccess = { display ->
display.sendContent { flexBox { text("Hello") } }
},
onFailure = { error -> showError(error.description) }
)
Signature
fun DeviceSession.addDisplay(config: DisplayConfiguration = DisplayConfiguration()): DatResult<Display, DeviceSessionError> Parameters |
addStream
(
streamConfiguration
)
|
Adds a camera streaming capability to this session.
Creates and starts a video stream from the device connected to this session. Only one stream can exist per session — calling this method when a stream is already attached returns DeviceSessionError.CAPABILITY_ALREADY_ADDED.
The stream must be added after the session reaches DeviceSessionState.STARTED. Adding a stream to an idle session returns DeviceSessionError.SESSION_IDLE, and adding to a stopped session returns DeviceSessionError.SESSION_ALREADY_STOPPED.
Example:
session.addStream(
streamConfiguration = StreamConfiguration(videoQuality = VideoQuality.HIGH),
).fold(
onSuccess = { stream ->
stream.videoStream.collect { frame -> processFrame(frame) }
},
onFailure = { error -> showError(error.description) }
)
Signature
fun DeviceSession.addStream(streamConfiguration: StreamConfiguration = StreamConfiguration()): DatResult<Stream, DeviceSessionError> Parameters |
removeDisplay
()
|
Removes the display capability from this session.
Stops the display and detaches it from the session. After removal, a new display can be added via DeviceSession.addDisplay.
Signature
fun DeviceSession.removeDisplay(): DatResult<Unit, DeviceSessionError> |
removeStream
()
|
Removes the camera streaming capability from this session.
Stops the stream and detaches it from the session. After removal, a new stream can be added via DeviceSession.addStream.
Signature
fun DeviceSession.removeStream(): DatResult<Unit, DeviceSessionError> |
start
()
|
Starts the session, connecting to the device resolved during Wearables.createSession.
This method is sync fire-and-forget: it returns immediately and the connection proceeds in the background. Observe DeviceSession.state for DeviceSessionState.STARTING → DeviceSessionState.STARTED transitions, and DeviceSession.errors for failure details.
Calling DeviceSession.start on a session that is not in DeviceSessionState.IDLE is a no-op.
Signature
fun start() |
stop
()
|
Stops the session and all attached capabilities.
This method is sync fire-and-forget: it transitions to DeviceSessionState.STOPPING and then DeviceSessionState.STOPPED, performing cleanup. All attached capabilities are stopped (cascading stop). The session is unregistered from the session registry, releasing the device for new sessions.
Calling DeviceSession.stop on an already-stopped or stopping session is a no-op.
Signature
fun stop() |