class Session
errors
: SharedFlow<SessionError>
[Get] |
A SharedFlow that emits session errors.
Errors are emitted when Session.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 Session.state for comprehensive session monitoring.
Example:
session.errors.collect { error ->
when (error) {
SessionError.DEVICE_DISCONNECTED -> showReconnectPrompt()
SessionError.DEVICE_POWERED_OFF -> showDeviceOffMessage()
else -> showError(error.description)
}
}
Signature
val errors: SharedFlow<SessionError> |
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 Session.start and Session.stop are sync fire-and-forget — observe this flow for completion signals.
Signature
val state: StateFlow<DeviceSessionState> |
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 SessionError.CAPABILITY_ALREADY_ADDED.
The stream must be added after the session reaches DeviceSessionState.STARTED. Adding a stream to an idle session returns SessionError.SESSION_IDLE, and adding to a stopped session returns SessionError.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 Session.addStream(streamConfiguration: StreamConfiguration = StreamConfiguration()): DatResult<Stream, SessionError> Parameters |
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 Session.addStream.
Signature
fun Session.removeStream(): DatResult<Unit, SessionError> |
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 Session.state for DeviceSessionState.STARTING → DeviceSessionState.STARTED transitions, and Session.errors for failure details.
Calling Session.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 Session.stop on an already-stopped or stopping session is a no-op.
Signature
fun stop() |