Skip to content

Commit

Permalink
Remove notifyingDataFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
dasdranagon committed Oct 16, 2024
1 parent b7c1f3b commit 96c8758
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions bluetooth/src/commonMain/kotlin/extensions/Accessors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,6 @@ import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

/**
* Provides access to device data flow by service and characteristic string uuids and automatically subscribes to updates.
* @param serviceUUID string service uuid representation
* @param characteristicUUID string characteristic uuid representation
* @param coroutineScope the [CoroutineScope] on which to subscribe to any updates to the characteristic
* @throws UUIDException.InvalidFormat
*/
fun Flow<Device?>.notifyingDataFlow(serviceUUID: String, characteristicUUID: String, coroutineScope: CoroutineScope): SharedFlow<ByteArray> {
val dataFlow = dataFlow(serviceUUID, characteristicUUID)
var job: Job? = null
val shared = MutableSharedFlow<ByteArray>()
coroutineScope.launch {
shared.subscriptionCount.map { it > 0 }.distinctUntilChanged().collect { isCollecting ->
job?.cancel()
val characteristic = characteristic(serviceUUID, characteristicUUID)
if (isCollecting) {
characteristic.enableNotification()
job = coroutineScope.launch {
shared.emitAll(dataFlow)
}
} else {
characteristic.disableNotification()
}
}
}
return shared.asSharedFlow()
}

/**
* Provides access to device data flow by service, characteristic and descriptor string uuids.
* @param serviceUUID string service uuid representation
Expand Down

0 comments on commit 96c8758

Please sign in to comment.