Skip to content

Commit

Permalink
Squashed merge: fix services not available after discoverAllServicesA…
Browse files Browse the repository at this point in the history
…ndCharacteristics
  • Loading branch information
intent-kacper-cyranowski authored and aliberski committed Dec 20, 2024
1 parent 36f0b56 commit 149e84c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
15 changes: 15 additions & 0 deletions android/src/main/java/com/bleplx/adapter/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -61,6 +62,20 @@ public List<Service> getServices() {
return services;
}

@Nullable
public List<UUID> getServicesUUIDs() {
if (services == null) {
return null;
}

List<UUID> servicesUUIDs = new ArrayList<>();
for (Service service : services) {
servicesUUIDs.add(service.getUuid());
}

return servicesUUIDs;
}

public void setServices(@Nullable List<Service> services) {
this.services = services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.bleplx.converter;

import android.util.Log;

import com.bleplx.adapter.Device;
import com.bleplx.utils.ReadableArrayConverter;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.WritableMap;

import java.util.List;
import java.util.UUID;

public class DeviceToJsObjectConverter extends JSObjectConverter<Device> {

private interface Metadata {
Expand Down Expand Up @@ -39,10 +46,15 @@ public WritableMap toJSObject(Device value) {
result.putNull(Metadata.MTU);
}

if(value.getServices() != null) {
result.putArray(Metadata.SERVICE_UUIDS, ReadableArrayConverter.toReadableArray(value.getServicesUUIDs()));
} else {
result.putNull(Metadata.SERVICE_UUIDS);
}

// Advertisement data is not set
result.putNull(Metadata.MANUFACTURER_DATA);
result.putNull(Metadata.SERVICE_DATA);
result.putNull(Metadata.SERVICE_UUIDS);
result.putNull(Metadata.LOCAL_NAME);
result.putNull(Metadata.TX_POWER_LEVEL);
result.putNull(Metadata.SOLICITED_SERVICE_UUIDS);
Expand Down
15 changes: 15 additions & 0 deletions android/src/main/java/com/bleplx/utils/ReadableArrayConverter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.bleplx.utils;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.WritableArray;

import java.util.List;
import java.util.UUID;

public class ReadableArrayConverter {
public static String[] toStringArray(ReadableArray readableArray) {
Expand All @@ -10,4 +15,14 @@ public static String[] toStringArray(ReadableArray readableArray) {
}
return stringArray;
}

public static ReadableArray toReadableArray(List<UUID> uuids) {
WritableArray array = Arguments.createArray();

for (UUID uuid : uuids) {
array.pushString(uuid.toString());
}

return array;
}
}
4 changes: 2 additions & 2 deletions ios/MultiplatformBleAdapter/BleExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ extension Peripheral {

"manufacturerData": NSNull(),
"serviceData": NSNull(),
"serviceUUIDs": NSNull(),
"serviceUUIDs": services?.map { $0.uuid.fullUUIDString } ?? NSNull(),
"localName": NSNull(),
"txPowerLevel": NSNull(),
"solicitedServiceUUIDs": NSNull(),
Expand Down Expand Up @@ -233,4 +233,4 @@ extension BluetoothState {
case .poweredOn: return "PoweredOn"
}
}
}
}

0 comments on commit 149e84c

Please sign in to comment.