@capacitor-community/bluetooth-le 2.2.2 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -187,6 +187,12 @@ class Device(
|
|
|
187
187
|
) {
|
|
188
188
|
val key = "connect"
|
|
189
189
|
callbackMap[key] = callback
|
|
190
|
+
if (isConnected()) {
|
|
191
|
+
resolve(key, "Already connected.")
|
|
192
|
+
return
|
|
193
|
+
}
|
|
194
|
+
bluetoothGatt?.close()
|
|
195
|
+
connectionState = STATE_CONNECTING
|
|
190
196
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
191
197
|
bluetoothGatt = device.connectGatt(
|
|
192
198
|
context, false, gattCallback, BluetoothDevice.TRANSPORT_LE
|
|
@@ -196,7 +202,6 @@ class Device(
|
|
|
196
202
|
context, false, gattCallback
|
|
197
203
|
)
|
|
198
204
|
}
|
|
199
|
-
connectionState = STATE_CONNECTING
|
|
200
205
|
setConnectionTimeout(key, "Connection timeout.", bluetoothGatt, timeout)
|
|
201
206
|
}
|
|
202
207
|
|
|
@@ -205,7 +210,7 @@ class Device(
|
|
|
205
210
|
}
|
|
206
211
|
|
|
207
212
|
fun isConnected(): Boolean {
|
|
208
|
-
return connectionState == STATE_CONNECTED
|
|
213
|
+
return bluetoothGatt != null && connectionState == STATE_CONNECTED
|
|
209
214
|
}
|
|
210
215
|
|
|
211
216
|
private fun requestMtu(mtu: Int) {
|
|
@@ -541,6 +546,7 @@ class Device(
|
|
|
541
546
|
val handler = Handler(Looper.getMainLooper())
|
|
542
547
|
timeoutMap[key] = handler
|
|
543
548
|
handler.postDelayed({
|
|
549
|
+
connectionState = STATE_DISCONNECTED
|
|
544
550
|
gatt?.disconnect()
|
|
545
551
|
gatt?.close()
|
|
546
552
|
reject(key, message)
|