diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ffd637a..35ab38fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.1.7 + +* Fix lack of disconnection event on iOS when connection fails to be established +* Fix errors all errors being passed through onError callbacks on Android (thanks, @eliaslecomte) + # 0.1.6 * Fix BluetoothGattCharacteristicUuid collision diff --git a/iOS/classes/BleModule.swift b/iOS/classes/BleModule.swift index 0897b5c1..754c5c14 100644 --- a/iOS/classes/BleModule.swift +++ b/iOS/classes/BleModule.swift @@ -388,11 +388,13 @@ public class BleClientManager : NSObject { timeout: Int?, promise: SafePromise) { + var peripheral: Peripheral? = nil var connectionObservable = manager.retrievePeripherals(withIdentifiers: [deviceId]) .flatMap { devices -> Observable in guard let device = devices.first else { return Observable.error(BleError.peripheralNotFound(deviceId.uuidString)) } + peripheral = device return Observable.just(device) } .flatMap { $0.connect() } @@ -401,25 +403,20 @@ public class BleClientManager : NSObject { connectionObservable = connectionObservable.timeout(Double(timeout) / 1000.0, scheduler: ConcurrentDispatchQueueScheduler(queue: queue)) } - var peripheralToConnect : Peripheral? = nil let connectionDisposable = connectionObservable .do(onSubscribe: { [weak self] in self?.dispatchEvent(BleEvent.connectingEvent, value: deviceId.uuidString) }) .subscribe( onNext: { [weak self] peripheral in - // When device is connected we save it in dectionary and clear all old cached values. - peripheralToConnect = peripheral + // When device is connected we save it in dictionary and clear all old cached values. self?.connectedPeripherals[deviceId] = peripheral self?.clearCacheForPeripheral(peripheral: peripheral) self?.dispatchEvent(BleEvent.connectedEvent, value: deviceId.uuidString) }, onError: { [weak self] error in - if let rxerror = error as? RxError, - let peripheralToConnect = peripheralToConnect, - let strongSelf = self, - case RxError.timeout = rxerror { - _ = strongSelf.manager.cancelPeripheralConnection(peripheralToConnect).subscribe() + if let peripheral = peripheral { + self?.onPeripheralDisconnected(peripheral) } error.bleError.callReject(promise) },