Reedyuk / blue-falcon

A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android
https://bluefalcon.dev
Apache License 2.0
328 stars 43 forks source link

[ANDROID] OnConnected called when device is disconnected #37

Closed felislynx-silae closed 4 years ago

felislynx-silae commented 4 years ago

This code listens to connection change event, it doesn't check what's new state, it always tries to "connect" to device and sends that information out. So if i'm connected and turn off external device, i get information that i'm connected :) Didn't checked iOS (will do in upcoming weeks) yet.

override fun onConnectionStateChange(gatt: BluetoothGatt?, status: Int, newState: Int) {
            super.onConnectionStateChange(gatt, status, newState)
            log("onConnectionStateChange")
            gatt?.let { bluetoothGatt ->
                bluetoothGatt.device.let {
                    addGatt(bluetoothGatt)
                    bluetoothGatt.readRemoteRssi()
                    bluetoothGatt.discoverServices()
                    delegates.forEach {
                        it.didConnect(BluetoothPeripheral(bluetoothGatt.device))
                    }
                }
            }
        }
Reedyuk commented 4 years ago

good spot, we should check the status/new state to determine if connected.

Reedyuk commented 4 years ago

Hi @felislynx-silae - do you want to check my PR, this should address the issue you were experiencing.

felislynx-silae commented 4 years ago

Hi, it looks good. If more comes out during tests i'll let you know :)