simplejsble 0.0.9 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -113,6 +113,9 @@ android {
113
113
 
114
114
  sourceSets {
115
115
  main {
116
+ // Include simpledroidbridge Java sources (BluetoothGattCallback, ScanCallback)
117
+ java.srcDirs += ["../simpledroidbridge/src/main/java"]
118
+
116
119
  if (isNewArchitectureEnabled()) {
117
120
  java.srcDirs += [
118
121
  // React Codegen files
@@ -1,6 +1,11 @@
1
1
  #include <jni.h>
2
2
  #include "NitroSimplejsbleOnLoad.hpp"
3
+ #include <simpleble/Advanced.h>
3
4
 
4
5
  JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
6
+ SimpleBLE::Advanced::Android::set_jvm(vm);
7
+
5
8
  return margelo::nitro::simplejsble::initialize(vm);
6
9
  }
10
+
11
+
@@ -21,10 +21,16 @@ class VM {
21
21
  }
22
22
  instance._jvm = jvm_override;
23
23
  } else if (instance._jvm == nullptr) {
24
+ #ifdef __ANDROID__
25
+ // On Android (React Native/Expo), JNI_GetCreatedJavaVMs is not available at runtime.
26
+ // The JVM must be set explicitly via set_jvm() in JNI_OnLoad.
27
+ throw std::runtime_error("JavaVM not set. Call set_jvm() in JNI_OnLoad first.");
28
+ #else
24
29
  jsize count;
25
30
  if (JNI_GetCreatedJavaVMs(&instance._jvm, 1, &count) != JNI_OK || count == 0) {
26
31
  throw std::runtime_error("Failed to retrieve the Java Virtual Machine");
27
32
  }
33
+ #endif
28
34
  }
29
35
  return instance._jvm;
30
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplejsble",
3
- "version": "0.0.9",
3
+ "version": "0.0.15",
4
4
  "description": "React Native Bluetooth Low Energy library using SimpleBLE with Nitro Modules",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -15,6 +15,7 @@
15
15
  "ios/",
16
16
  "cpp/",
17
17
  "simpleble/",
18
+ "simpledroidbridge/",
18
19
  "cmake/",
19
20
  "dependencies/",
20
21
  "VERSION",
@@ -0,0 +1,24 @@
1
+ plugins {
2
+ id("com.android.library") version "8.7.1"
3
+ }
4
+
5
+ version = "v${file("../VERSION").readText().trim()}"
6
+
7
+ android {
8
+ namespace = "org.simpleble.android.bridge"
9
+ compileSdk = 31
10
+
11
+ defaultConfig {
12
+ minSdk = 31
13
+ }
14
+
15
+ compileOptions {
16
+ sourceCompatibility = JavaVersion.VERSION_1_9
17
+ targetCompatibility = JavaVersion.VERSION_1_9
18
+ }
19
+ buildTypes {
20
+ getByName("debug") {
21
+ isJniDebuggable = true
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,22 @@
1
+ pluginManagement {
2
+ repositories {
3
+ google {
4
+ content {
5
+ includeGroupByRegex("com\\.android.*")
6
+ includeGroupByRegex("com\\.google.*")
7
+ includeGroupByRegex("androidx.*")
8
+ }
9
+ }
10
+ mavenCentral()
11
+ gradlePluginPortal()
12
+ }
13
+ }
14
+ dependencyResolutionManagement {
15
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
16
+ repositories {
17
+ google()
18
+ mavenCentral()
19
+ }
20
+ }
21
+
22
+ rootProject.name = "simpledroidbridge"
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <manifest
3
+ xmlns:android="http://schemas.android.com/apk/res/android"
4
+ >
5
+ <uses-permission android:name="android.permission.BLUETOOTH"/>
6
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
7
+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
8
+ <uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
9
+ </manifest>
@@ -0,0 +1,141 @@
1
+ package org.simpleble.android.bridge;
2
+
3
+ import android.bluetooth.BluetoothGatt;
4
+ import android.bluetooth.BluetoothGattCharacteristic;
5
+ import android.bluetooth.BluetoothGattDescriptor;
6
+ import android.util.Log;
7
+
8
+ public class BluetoothGattCallback extends android.bluetooth.BluetoothGattCallback {
9
+
10
+ public BluetoothGattCallback() {}
11
+
12
+ @Override
13
+ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
14
+ // NOTE: This method has been deprecated on API 33, but we're still using API 31, so we need to support this.
15
+ super.onCharacteristicChanged(gatt, characteristic);
16
+ onCharacteristicChangedCallback(gatt, characteristic, characteristic.getValue());
17
+ }
18
+
19
+ // @Override
20
+ // public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value) {
21
+ // // NOTE: This method is only available from API 33 onwards.
22
+ // super.onCharacteristicChanged(gatt, characteristic, value);
23
+ // onCharacteristicChangedCallback(gatt, characteristic, value);
24
+ // }
25
+
26
+ @Override
27
+ public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
28
+ // NOTE: This method has been deprecated on API 33, but we're still using API 31, so we need to support this.
29
+ super.onCharacteristicRead(gatt, characteristic, status);
30
+ onCharacteristicReadCallback(gatt, characteristic, characteristic.getValue(), status);
31
+ }
32
+
33
+ // @Override
34
+ // public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value, int status) {
35
+ // // NOTE: This method is only available from API 33 onwards.
36
+ // super.onCharacteristicRead(gatt, characteristic, value, status);
37
+ // onCharacteristicReadCallback(gatt, characteristic, value, status);
38
+ // }
39
+
40
+ @Override
41
+ public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
42
+ super.onCharacteristicWrite(gatt, characteristic, status);
43
+ onCharacteristicWriteCallback(gatt, characteristic, status);
44
+ }
45
+
46
+ @Override
47
+ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
48
+ super.onConnectionStateChange(gatt, status, newState);
49
+ onConnectionStateChangeCallback(gatt, status, newState);
50
+ }
51
+
52
+ // NOTE: This method is only available from API 33 onwards
53
+ @Override
54
+ public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
55
+ // NOTE: This method has been deprecated on API 33, but we're still using API 31, so we need to support this.
56
+ super.onDescriptorRead(gatt, descriptor, status);
57
+ onDescriptorReadCallback(gatt, descriptor, descriptor.getValue(), status);
58
+ }
59
+
60
+ // @Override
61
+ // public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status, byte[] value) {
62
+ // // NOTE: This method is only available from API 33 onwards.
63
+ // super.onDescriptorRead(gatt, descriptor, status, value);
64
+ // onDescriptorReadCallback(gatt, descriptor, value, status);
65
+ // }
66
+
67
+ @Override
68
+ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
69
+ super.onDescriptorWrite(gatt, descriptor, status);
70
+ onDescriptorWriteCallback(gatt, descriptor, status);
71
+ }
72
+
73
+ @Override
74
+ public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
75
+ super.onMtuChanged(gatt, mtu, status);
76
+ onMtuChangedCallback(gatt, mtu, status);
77
+ }
78
+
79
+ @Override
80
+ public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
81
+ super.onPhyRead(gatt, txPhy, rxPhy, status);
82
+ onPhyReadCallback(gatt, txPhy, rxPhy, status);
83
+ }
84
+
85
+ @Override
86
+ public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
87
+ super.onPhyUpdate(gatt, txPhy, rxPhy, status);
88
+ onPhyUpdateCallback(gatt, txPhy, rxPhy, status);
89
+ }
90
+
91
+ @Override
92
+ public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
93
+ super.onReadRemoteRssi(gatt, rssi, status);
94
+ onReadRemoteRssiCallback(gatt, rssi, status);
95
+ }
96
+
97
+ @Override
98
+ public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
99
+ super.onReliableWriteCompleted(gatt, status);
100
+ onReliableWriteCompletedCallback(gatt, status);
101
+ }
102
+
103
+ @Override
104
+ public void onServiceChanged(BluetoothGatt gatt) {
105
+ super.onServiceChanged(gatt);
106
+ onServiceChangedCallback(gatt);
107
+ }
108
+
109
+ @Override
110
+ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
111
+ super.onServicesDiscovered(gatt, status);
112
+ onServicesDiscoveredCallback(gatt, status);
113
+ }
114
+
115
+ private native void onCharacteristicChangedCallback(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value);
116
+
117
+ private native void onCharacteristicReadCallback(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value, int status);
118
+
119
+ private native void onCharacteristicWriteCallback(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status);
120
+
121
+ private native void onConnectionStateChangeCallback(BluetoothGatt gatt, int status, int newState);
122
+
123
+ private native void onDescriptorReadCallback(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, byte[] value, int status);
124
+
125
+ private native void onDescriptorWriteCallback(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status);
126
+
127
+ private native void onMtuChangedCallback(BluetoothGatt gatt, int mtu, int status);
128
+
129
+ private native void onPhyReadCallback(BluetoothGatt gatt, int txPhy, int rxPhy, int status);
130
+
131
+ private native void onPhyUpdateCallback(BluetoothGatt gatt, int txPhy, int rxPhy, int status);
132
+
133
+ private native void onReadRemoteRssiCallback(BluetoothGatt gatt, int rssi, int status);
134
+
135
+ private native void onReliableWriteCompletedCallback(BluetoothGatt gatt, int status);
136
+
137
+ private native void onServiceChangedCallback(BluetoothGatt gatt);
138
+
139
+ private native void onServicesDiscoveredCallback(BluetoothGatt gatt, int status);
140
+ }
141
+
@@ -0,0 +1,36 @@
1
+ package org.simpleble.android.bridge;
2
+
3
+ import android.bluetooth.le.ScanResult;
4
+
5
+ import java.util.List;
6
+ import android.util.Log;
7
+
8
+ public class ScanCallback extends android.bluetooth.le.ScanCallback {
9
+
10
+ public ScanCallback() {}
11
+
12
+ @Override
13
+ public void onScanResult(int callbackType, ScanResult result) {
14
+ super.onScanResult(callbackType, result);
15
+ onScanResultCallback(callbackType, result);
16
+ }
17
+
18
+ @Override
19
+ public void onBatchScanResults(List<ScanResult> results) {
20
+ super.onBatchScanResults(results);
21
+ onBatchScanResultsCallback(results);
22
+ }
23
+
24
+ @Override
25
+ public void onScanFailed(int errorCode) {
26
+ super.onScanFailed(errorCode);
27
+ onScanFailedCallback(errorCode);
28
+ }
29
+
30
+ private native void onScanResultCallback(int callbackType, android.bluetooth.le.ScanResult result);
31
+
32
+ private native void onScanFailedCallback(int errorCode);
33
+
34
+ private native void onBatchScanResultsCallback(List<android.bluetooth.le.ScanResult> results);
35
+
36
+ }
package/lib/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { Adapter } from "./specs/Adapter.nitro";
2
- export declare const HybridAdapter: Adapter;
package/lib/index.js DELETED
@@ -1,2 +0,0 @@
1
- import { NitroModules } from "react-native-nitro-modules";
2
- export const HybridAdapter = NitroModules.createHybridObject("Adapter");
@@ -1,9 +0,0 @@
1
- import { type HybridObject } from 'react-native-nitro-modules';
2
- export interface Adapter extends HybridObject<{
3
- ios: 'c++';
4
- android: 'c++';
5
- }> {
6
- greet(name: string): string;
7
- get_adapters(): Adapter[];
8
- bluetooth_enabled(): boolean;
9
- }
@@ -1 +0,0 @@
1
- import {} from 'react-native-nitro-modules';