mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-04 23:34:19 +01:00
Fix: connect client after server set up
This commit is contained in:
@@ -88,9 +88,7 @@ internal class PRXService : NotificationService() {
|
||||
|
||||
val device = intent!!.getParcelableExtra<ServerDevice>(DEVICE_DATA)!!
|
||||
|
||||
startServer()
|
||||
|
||||
startGattClient(device)
|
||||
startServer(device)
|
||||
|
||||
repository.stopEvent
|
||||
.onEach { disconnect() }
|
||||
@@ -103,7 +101,7 @@ internal class PRXService : NotificationService() {
|
||||
return START_REDELIVER_INTENT
|
||||
}
|
||||
|
||||
private fun startServer() {
|
||||
private fun startServer(device: ServerDevice) = lifecycleScope.launch {
|
||||
val alertLevelCharacteristic = BleServerGattCharacteristicConfig(
|
||||
uuid = ALERT_LEVEL_CHARACTERISTIC_UUID,
|
||||
properties = listOf(BleGattProperty.PROPERTY_WRITE_NO_RESPONSE),
|
||||
@@ -130,6 +128,9 @@ internal class PRXService : NotificationService() {
|
||||
|
||||
server = BleGattServer.create(this@PRXService, prxServiceConfig, linkLossServiceConfig)
|
||||
|
||||
//Order is important. We don't want to connect before services have been added to the server.
|
||||
startGattClient(device)
|
||||
|
||||
server.onNewConnection
|
||||
.onEach { setUpServerConnection(it.second) }
|
||||
.launchIn(lifecycleScope)
|
||||
@@ -192,8 +193,9 @@ internal class PRXService : NotificationService() {
|
||||
repository.onRemoteAlarmLevelSet(alarmLevel)
|
||||
}
|
||||
|
||||
private fun stopIfDisconnected(connectionState: GattConnectionState) {
|
||||
private suspend fun stopIfDisconnected(connectionState: GattConnectionState) {
|
||||
if (connectionState == GattConnectionState.STATE_DISCONNECTED) {
|
||||
server.stopServer()
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user