Skip to content

Commit

Permalink
Merge pull request #1134 from dotintent/feature/949-raw_scan_data
Browse files Browse the repository at this point in the history
feat: rawScanRecord
  • Loading branch information
dominik-czupryna-withintent authored Nov 14, 2023
2 parents 33a766b + 555a192 commit 26b6188
Show file tree
Hide file tree
Showing 10 changed files with 718 additions and 917 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface Metadata {
String LOCAL_NAME = "localName";
String TX_POWER_LEVEL = "txPowerLevel";
String SOLICITED_SERVICE_UUIDS = "solicitedServiceUUIDs";
String RAW_SCAN_RECORD = "rawScanRecord";
String IS_CONNECTABLE = "isConnectable";
String OVERFLOW_SERVICE_UUIDS = "overflowServiceUUIDs";
}
Expand Down Expand Up @@ -88,6 +89,12 @@ public WritableMap toJSObject(@NonNull ScanResult scanResult) {
result.putNull(Metadata.SOLICITED_SERVICE_UUIDS);
}

if (advData.getRawScanRecord() != null) {
result.putString(Metadata.RAW_SCAN_RECORD, Base64Converter.encode(advData.getRawScanRecord()));
} else {
result.putNull(Metadata.RAW_SCAN_RECORD);
}

// Attributes which are not accessible on Android
result.putNull(Metadata.OVERFLOW_SERVICE_UUIDS);
return result;
Expand Down
110 changes: 55 additions & 55 deletions example/ios/BlePlxExample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ PODS:
- React-jsinspector (0.72.4)
- React-logger (0.72.4):
- glog
- react-native-ble-plx (3.0.0):
- react-native-ble-plx (3.1.1):
- MultiplatformBleAdapter (= 0.2.0)
- RCT-Folly (= 2021.07.22.00)
- React-Core
Expand Down Expand Up @@ -708,7 +708,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594
React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f
React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77
react-native-ble-plx: 6f7f7d6e57bb109ff5751b8e5fce2654a9d7c033
react-native-ble-plx: 74ef9a718eff574f2072d49b2e8950fb24ecdf22
react-native-safe-area-context: 7aa8e6d9d0f3100a820efb1a98af68aa747f9284
React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f
React-perflogger: 496a1a3dc6737f964107cb3ddae7f9e265ddda58
Expand All @@ -734,4 +734,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: e43e14d964b1de567b73b376b4538cddb7c50ca9

COCOAPODS: 1.13.0
COCOAPODS: 1.12.1
1 change: 1 addition & 0 deletions example/src/components/molecules/BleDevice/BleDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function BleDevice({ device, onPress }: BleDeviceProps) {
<DeviceProperty name="localName" value={device.localName} />
<DeviceProperty name="id" value={device.id} />
<DeviceProperty name="manufacturerData" value={device.manufacturerData} />
<DeviceProperty name="rawScanRecord" value={device.rawScanRecord} />
<DeviceProperty name="isConnectable" value={parsedIsConnectable} />
<DeviceProperty name="mtu" value={device.mtu.toString()} />
<DeviceProperty name="rssi" value={device.rssi} />
Expand Down
26 changes: 17 additions & 9 deletions ios/MultiplatformBleAdapter/BleExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,28 @@ extension ScannedPeripheral {
.solicitedServiceUUIDs?
.map { (uuid: CBUUID) in uuid.fullUUIDString }

return [
"id": peripheral.identifier.uuidString,
"name": peripheral.name as Any,
"rssi": rssi,
"mtu": mtu,

let advertisementDataDict: [AnyHashable: Any] = [
"localName": advertisementData.localName as Any,
"manufacturerData": manufacturerData as Any,
"serviceData": serviceData as Any,
"serviceUUIDs": serviceUUIDs as Any,
"localName": advertisementData.localName as Any,
"txPowerLevel": advertisementData.txPowerLevel as Any,
"solicitedServiceUUIDs": solicitedServiceUUIDs as Any,
"isConnectable": advertisementData.isConnectable as Any,
"solicitedServiceUUIDs": solicitedServiceUUIDs as Any,
"overflowServiceUUIDs": overflowServiceUUIDs as Any
]

let advertisementDataJSON = try? JSONSerialization.data(withJSONObject: advertisementDataDict, options: [])
let advertisementDataBase64 = advertisementDataJSON?.base64EncodedString()

return [
"id": peripheral.identifier.uuidString,
"name": peripheral.name as Any,
"rssi": rssi,
"mtu": mtu,
"rawScanRecord": advertisementDataBase64 as Any
]
}
}

Expand All @@ -88,7 +95,8 @@ extension Peripheral {
"txPowerLevel": NSNull(),
"solicitedServiceUUIDs": NSNull(),
"isConnectable": NSNull(),
"overflowServiceUUIDs": NSNull()
"overflowServiceUUIDs": NSNull(),
"rawScanRecord": NSNull()
]
}
}
Expand Down Expand Up @@ -211,4 +219,4 @@ extension BluetoothState {
case .poweredOn: return "PoweredOn"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct AdvertisementData {
public var manufacturerData: Data? {
return advertisementData[CBAdvertisementDataManufacturerDataKey] as? Data
}

/// A dictionary containing service-specific advertisement data.
/// The keys are CBUUID objects, representing CBService UUIDs. The values are Data objects,
/// representing service-specific data.
Expand Down
7 changes: 7 additions & 0 deletions src/BleModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ export interface NativeDevice {
*/
manufacturerData: ?Base64;

/**
* Raw device scan data. When you have specific advertiser data,
* you can implement your own processing.
* @private
*/
rawScanRecord: Base64;

/**
* Map od service UUIDs with associated data.
* @private
Expand Down
7 changes: 7 additions & 0 deletions src/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export class Device implements NativeDevice {
*/
manufacturerData: ?Base64

/**
* Raw device scan data. When you have specific advertiser data,
* you can implement your own processing.
* @private
*/
rawScanRecord: Base64

/**
* Map of service UUIDs (as keys) with associated data (as values).
*/
Expand Down
14 changes: 14 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,13 @@ declare module 'react-native-ble-plx' {
*/
manufacturerData: Base64 | null

/**
* Raw device scan data. When you have specific advertiser data,
* you can implement your own processing.
* @private
*/
rawScanRecord: Base64

/**
* Map od service UUIDs with associated data.
* @private
Expand Down Expand Up @@ -1430,6 +1437,13 @@ declare module 'react-native-ble-plx' {
*/
manufacturerData: Base64 | null

/**
* Raw device scan data. When you have specific advertiser data,
* you can implement your own processing.
* @private
*/
rawScanRecord: Base64

/**
* Map of service UUIDs (as keys) with associated data (as values).
*/
Expand Down
Loading

0 comments on commit 26b6188

Please sign in to comment.