Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve disengage and scanning issues; add missing manifest perm… #77

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.annotation.RequiresPermission
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.evva.xesar.abrevva.ble.BleManager
import com.evva.xesar.abrevva.disengage.DisengageStatusType
import com.evva.xesar.abrevva.util.bytesToString
import com.evva.xesar.abrevva.util.stringToBytes
import com.facebook.react.bridge.Arguments
Expand Down Expand Up @@ -181,6 +182,7 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
@ReactMethod
fun stopLEScan(promise: Promise) {
manager.stopScan()
promise.resolve("success")
}

@ReactMethod
Expand Down Expand Up @@ -314,9 +316,9 @@ class AbrevvaBleModule(reactContext: ReactApplicationContext) :
mobileGroupId,
mobileAccessData,
isPermanentRelease
) { status: Any ->
) { status: DisengageStatusType ->
val result = Arguments.createMap()
result.putString("value", status as String)
result.putString("value", status.toString())

promise.resolve(result)
}
Expand Down
2 changes: 2 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

<application
android:name=".MainApplication"
Expand Down
41 changes: 21 additions & 20 deletions example/src/BleScreenComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const ScanResults = ({ props }) => {
});
};

const onRefresh = () => {
const onRefresh = async () => {
setStatus('none');
setScanNoftification('scanning ...');
setRefreshing(true);
Expand All @@ -54,23 +54,24 @@ const ScanResults = ({ props }) => {
setRefreshing(false);
setScanNoftification('');
}, 3_000);
AbrevvaBle.stopLEScan()
.then(() => {
void AbrevvaBle.requestLEScan(
scanRequestCallback,
(address: string) => {
console.log(`connected to Device =${address}`);
},
(address: string) => {
console.log(`disconnected from Device =${address}`);
},
10_000,
);
})
.catch((e) => {
console.log(e);
clearTimeout(timeout);
});

await AbrevvaBle.stopLEScan();

try {
await AbrevvaBle.requestLEScan(
scanRequestCallback,
(address: string) => {
console.log(`connected to Device =${address}`);
},
(address: string) => {
console.log(`disconnected from Device =${address}`);
},
10_000,
);
} catch (err) {
console.log(err);
clearTimeout(timeout);
}
};

useEffect(() => {
Expand All @@ -86,15 +87,15 @@ const ScanResults = ({ props }) => {
<SafeAreaView style={bleStyles.BleScanResult}>
<TouchableOpacity
onPress={async () => {
AbrevvaBle.connect(item.item.device.deviceId, 10_000);
AbrevvaBle.disengage(
const result = await AbrevvaBle.disengage(
'deviceId',
'mobileId',
'deviceKey',
'mobilegroudId',
'mobileAccessData',
true,
);
console.log(`Disengage Status: ${result}`);
}}
>
<Text>{item.item.device.deviceId}</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class AbrevvaBleModule implements AbrevvaBLEInterface {
}

async stopLEScan(): Promise<void> {
return await NativeModuleBle.stopLEScan();
return NativeModuleBle.stopLEScan();
}

async connect(deviceId: string, timeout?: number): Promise<void> {
Expand Down
Loading