Skip to content

Commit

Permalink
fix(android): do not reconnect with the same device (#95)
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht authored Jan 16, 2024
1 parent 8f405ad commit 68e14ef
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ class CentralManager(private val context: ReactContext) {

@RequiresPermission(allOf = ["android.permission.BLUETOOTH_CONNECT", "android.permission.BLUETOOTH_SCAN"])
fun connect(peripheralId: String) {
val maybeDevice = discoveredPeripherals.find { it.address == peripheralId }
val device = discoveredPeripherals.find { it.address == peripheralId }
?: throw CentralManagerException.PeripheralNotFound()

connectedGatt = maybeDevice.connectGatt(context, false, gattClientCallback)
if(connectedGatt?.device?.address != peripheralId) {
connectedGatt = device.connectGatt(context, false, gattClientCallback)
}

stopScan()
}

Expand Down

0 comments on commit 68e14ef

Please sign in to comment.