Skip to main content

BioLiveStore

BioLiveStore is an ObservableObject that accumulates real-time biosignal data, device states, and session info into @Published properties. It's designed to drive SwiftUI views directly.

Usage

Create a store and feed it events from the SDK:

import BioSDK
import Combine

let store = BioLiveStore()
var cancellables = Set<AnyCancellable>()

sdk.events
.sink { event in
switch event {
case .sample(let deviceId, let sample):
store.ingest(sample, deviceId: deviceId)
case .deviceState(let device, let connection, let stream):
store.updateDeviceState(
deviceId: device.id.uuidString,
connection: connection,
stream: stream
)
case .session(.started(let id, let devices)):
store.updateSession(id: id, devices: devices)
default:
break
}
}
.store(in: &cancellables)

Published Properties

Signal Data

// All signals by name (e.g., "ecg", "ppg", "hr")
@Published var signals: [String: [BioSample]]

// Signals organized by device
@Published var signalsByDevice: [String: [String: [BioSample]]]

// List of signal types currently being received
var availableSignals: [String]

Device State

// Device display names
@Published var deviceNames: [String: String]

// Per-device connection states
@Published var deviceConnectionStates: [String: BioConnectionState]

// Per-device streaming states
@Published var deviceStreamStates: [String: BioStreamState]

// Auto-stream enabled per device
@Published var deviceAutoStream: [String: Bool]

// Battery level per device (0-100)
@Published var deviceBattery: [String: Int]

Session State

// Active session ID
@Published var currentSessionId: String?

// Conflicting session ID (from 409 conflict)
@Published var conflictingSessionId: String?

// Session error message
@Published var sessionError: String?

SwiftUI Integration

Since BioLiveStore is an ObservableObject, inject it into your SwiftUI views:

struct DashboardView: View {
@ObservedObject var store: BioLiveStore

var body: some View {
VStack {
if let ecgSamples = store.signals["ecg"] {
BioECGChart(samples: ecgSamples)
}

ForEach(Array(store.deviceConnectionStates.keys), id: \.self) { deviceId in
let name = store.deviceNames[deviceId] ?? "Unknown"
let state = store.deviceConnectionStates[deviceId] ?? .discovered
Text("\(name): \(state)")
}
}
}
}

Memory Management

The store manages memory automatically during background/foreground transitions:

store.enterBackgroundMode()  // Reduces memory footprint
store.enterForegroundMode() // Restores full buffering

store.reset() // Clear all accumulated data

Accessing Samples

// All samples for a signal type
let ecg = store.samples(for: "ecg")

// Samples from a specific device
let deviceEcg = store.samples(for: "ecg", deviceId: "DEVICE-UUID")