Skip to content

Commit

Permalink
feat: add Bluetooth device type property on NativeDevice class (#344)
Browse files Browse the repository at this point in the history
* feat: add Bluetooth device type property on NativeDevice class

* feat: add bluetooth connection type in NativeDevice class on iOS side
  • Loading branch information
marllonfrizzo authored Feb 4, 2025
1 parent 7e5c889 commit c8a2bbc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public <T> T putExtra(String key, T value) {
return (T) mExtra.put(key, value);
}

private String getBlutoothTypeString() {
return switch (mDevice.getType()) {
case BluetoothDevice.DEVICE_TYPE_CLASSIC -> "CLASSIC";
case BluetoothDevice.DEVICE_TYPE_LE -> "LOW_ENERGY";
case BluetoothDevice.DEVICE_TYPE_DUAL -> "DUAL";
default -> "UNKNOWN";
};
}

@Override
public WritableMap map() {
WritableMap mapped = Arguments.createMap();
Expand All @@ -66,6 +75,7 @@ public WritableMap map() {
mapped.putString("address", mDevice.getAddress());
mapped.putString("id", mDevice.getAddress());
mapped.putBoolean("bonded", mDevice.getBondState() == BluetoothDevice.BOND_BONDED);
mapped.putString("type", this.getBlutoothTypeString());

if (mDevice.getBluetoothClass() != null) {
WritableMap deviceClass = Arguments.createMap();
Expand Down
1 change: 1 addition & 0 deletions ios/device/NativeDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class NativeDevice: NSObject, Mappable {
"bonded": accessory.isConnected,
"deviceClass": accessory.modelNumber,
"protocolStrings": accessory.protocolStrings,
"type": "CLASSIC",
"extra": [:]
];
}
Expand Down
2 changes: 2 additions & 0 deletions src/BluetoothDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
bonded?: Boolean;
deviceClass?: string;
rssi: Number;
type: 'CLASSIC' | 'LOW_ENERGY' | 'DUAL' | 'UNKNOWN';
extra: Map<string, Object>;

constructor(nativeDevice: BluetoothNativeDevice, bluetoothModule: BluetoothModule) {
Expand All @@ -37,6 +38,7 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
this.bonded = nativeDevice.bonded;
this.deviceClass = nativeDevice.deviceClass;
this.rssi = nativeDevice.rssi;
this.type = nativeDevice.type;
this.extra = nativeDevice.extra;
}

Expand Down
5 changes: 5 additions & 0 deletions src/BluetoothNativeDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export default interface BluetoothNativeDevice {
*/
rssi: Number;

/**
* Bluetooth device type of the remote device
*/
type: 'CLASSIC' | 'LOW_ENERGY' | 'DUAL' | 'UNKNOWN'

/**
* Extra information. This could contain things like RSSI value
* or other details.
Expand Down

0 comments on commit c8a2bbc

Please sign in to comment.