AnyBio
API Reference

Session Management

SessionManager, SessionState, SessionLifecycle, and device session tracking types.

The SDK manages backend sessions that track which devices are streaming data for a given user. Sessions persist across app backgrounding and device reconnections.

SessionManager

Thread-safe session state manager. Access via sdk.session.

public final class SessionManager: @unchecked Sendable

Properties

PropertyTypeDescription
stateSessionStateCurrent session state (read-only snapshot)
statePublisherPassthroughSubject<SessionState, Never>Publishes state changes

Reading State

// Get a consistent snapshot of session state
public func withState<T>(_ operation: (SessionState) -> T) -> T

Example:

let isActive = sdk.session.withState { $0.isActive }
let deviceCount = sdk.session.withState { $0.connectedDeviceCount }

Lifecycle Methods

public func beginStartingSession(xuserId: String)
public func sessionStarted(
    sessionId: String,
    devices: [(bleId: String, ingestDeviceId: String, name: String,
               deviceProfileId: String?, make: String?, model: String?)]
)
public func sessionResumed(
    sessionId: String,
    devices: [(bleId: String, ingestDeviceId: String, name: String,
               deviceProfileId: String?, make: String?, model: String?)]
)
public func beginEndingSession()
public func sessionEnded()
public func sessionOperationFailed()

Device Updates

public func deviceConnected(_ bleId: String, name: String)
public func deviceDisconnected(_ bleId: String)
public func deviceStreamStateChanged(_ bleId: String, state: BioStreamState)
public func deviceBatteryUpdated(_ bleId: String, battery: Int)
public func deviceStreamingProfileChanged(_ bleId: String, profileName: String?)

Configuration

public func updateConfiguration(
    organizationKey: String?,
    projectKey: String?,
    ingestBaseURL: URL?
)

SessionState

The complete state of the current session, including all enrolled devices.

public struct SessionState: Codable, Sendable {
    public var lifecycle: SessionLifecycle
    public var sessionId: String?
    public var xuserId: String?
    public var startedAt: Date?
    public var devices: [String: DeviceSessionState]
    public var organizationKey: String?
    public var projectKey: String?
    public var ingestBaseURL: URL?
    public var lastPersistedAt: Date?
    public var lastProcessId: Int32?
}

Computed Properties

PropertyTypeDescription
isActiveBoolWhether a session is currently active
shouldAutoReconnectBoolWhether the SDK should auto-reconnect devices
connectedDeviceCountIntNumber of connected devices
streamingDeviceCountIntNumber of actively streaming devices
deviceIds[String]All enrolled device IDs
deviceMapping[String: String]BLE ID → ingest device ID mapping

Methods

// Reset all state to defaults
public mutating func reset()

SessionLifecycle

The lifecycle stage of a session.

public enum SessionLifecycle: String, Codable, Sendable {
    case idle
    case starting
    case active
    case paused
    case ending
}
StateDescription
.idleNo active session
.startingSession start request in progress
.activeSession is active and streaming
.pausedSession paused (e.g., all devices disconnected)
.endingSession end request in progress
// Whether the session is in a live state (active or paused)
public var isLive: Bool { get }

DeviceSessionState

Per-device state within a session.

public struct DeviceSessionState: Codable, Sendable {
    public var name: String
    public var ingestDeviceId: String?
    public var connectionState: BioConnectionState
    public var streamState: BioStreamState
    public var battery: Int?
    public var deviceProfileId: String?
    public var make: String?
    public var model: String?
    public var streamingProfileName: String?
}

Computed Properties

public var isConnected: Bool { get }   // connectionState == .ready
public var isStreaming: Bool { get }    // streamState == .streaming

Initializer

public init(
    name: String,
    ingestDeviceId: String? = nil,
    connectionState: BioConnectionState = .disconnected,
    streamState: BioStreamState = .idle,
    battery: Int? = nil,
    deviceProfileId: String? = nil,
    make: String? = nil,
    model: String? = nil,
    streamingProfileName: String? = nil
)

Buffer & Upload Types

Advanced buffer and upload monitoring types are available as part of the AnyBio Enterprise plan. Contact us to learn more about enabling these capabilities for your organization.

On this page