Skip to content

Commit

Permalink
fix: fast reuse of connect to device leads to 'device not connected e…
Browse files Browse the repository at this point in the history
…rror' (only for Android)
  • Loading branch information
gmiszewski-intent committed Oct 11, 2023
1 parent 4d67f28 commit c262e3d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/BleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
ConnectionOptions,
BleManagerOptions
} from './TypeDefinition'
import { Platform } from 'react-native'

const enableDisableDeprecatedMessage =
'react-native-ble-plx: The enable and disable feature is no longer supported. In Android SDK 31+ there were major changes in permissions, which may cause problems with these functions, and in SDK 33+ they were completely removed.'
Expand Down Expand Up @@ -457,7 +458,7 @@ export class BleManager {
* @returns {Promise<Device>} Connected {@link Device} object if successful.
*/
async connectToDevice(deviceIdentifier: DeviceId, options: ?ConnectionOptions): Promise<Device> {
if (await this.isDeviceConnected(deviceIdentifier)) {
if (Platform.OS === 'android' && (await this.isDeviceConnected(deviceIdentifier))) {
await this.cancelDeviceConnection(deviceIdentifier)
}
const nativeDevice = await this._callPromise(BleModule.connectToDevice(deviceIdentifier, options))
Expand Down

0 comments on commit c262e3d

Please sign in to comment.