mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 17:05:20 +00:00
avoid duplicate conenctions to same peer, may cause infinite reconnections, not tested yet
This commit is contained in:
@@ -302,7 +302,23 @@ class BluetoothConnectionManager(
|
||||
* Public: connect/disconnect helpers for debug UI
|
||||
*/
|
||||
fun connectToAddress(address: String): Boolean = clientManager.connectToAddress(address)
|
||||
fun disconnectAddress(address: String) { connectionTracker.disconnectDevice(address) }
|
||||
fun disconnectAddress(address: String) {
|
||||
connectionScope.launch {
|
||||
try {
|
||||
val dc = connectionTracker.getDeviceConnection(address)
|
||||
if (dc != null) {
|
||||
if (dc.gatt != null) {
|
||||
try { dc.gatt.disconnect() } catch (_: Exception) { }
|
||||
} else {
|
||||
// Try canceling server-side connection if present
|
||||
try { serverManager.getGattServer()?.cancelConnection(dc.device) } catch (_: Exception) { }
|
||||
}
|
||||
}
|
||||
} catch (_: Exception) { }
|
||||
// Cleanup tracking regardless
|
||||
connectionTracker.cleanupDeviceConnection(address)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Optionally disconnect all connections (server and client)
|
||||
|
||||
Reference in New Issue
Block a user