simplejsble 0.0.41 → 0.0.43

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.
Files changed (30) hide show
  1. package/apple/SimpleBLE.xcframework/ios-arm64/libsimpleble.a +0 -0
  2. package/apple/SimpleBLE.xcframework/ios-arm64-simulator/libsimpleble.a +0 -0
  3. package/apple/SimpleBLE.xcframework/macos-arm64_x86_64/libsimpleble.a +0 -0
  4. package/cpp/HybridAdapter.cpp +91 -6
  5. package/cpp/HybridAdapter.hpp +33 -4
  6. package/cpp/HybridPeripheral.cpp +83 -0
  7. package/cpp/HybridPeripheral.hpp +45 -0
  8. package/lib/index.d.ts +3 -0
  9. package/lib/index.d.ts.map +1 -1
  10. package/lib/index.js +1 -0
  11. package/lib/specs/Adapter.nitro.d.ts +72 -2
  12. package/lib/specs/Adapter.nitro.d.ts.map +1 -1
  13. package/lib/specs/Adapter.nitro.js +1 -0
  14. package/lib/specs/Peripheral.nitro.d.ts +78 -0
  15. package/lib/specs/Peripheral.nitro.d.ts.map +1 -0
  16. package/lib/specs/Peripheral.nitro.js +1 -0
  17. package/nitro.json +3 -0
  18. package/nitrogen/generated/android/NitroSimplejsble+autolinking.cmake +1 -0
  19. package/nitrogen/generated/android/NitroSimplejsbleOnLoad.cpp +10 -0
  20. package/nitrogen/generated/ios/NitroSimplejsbleAutolinking.mm +10 -0
  21. package/nitrogen/generated/shared/c++/BluetoothAddressType.hpp +80 -0
  22. package/nitrogen/generated/shared/c++/HybridAdapterSpec.cpp +15 -2
  23. package/nitrogen/generated/shared/c++/HybridAdapterSpec.hpp +20 -3
  24. package/nitrogen/generated/shared/c++/HybridPeripheralSpec.cpp +35 -0
  25. package/nitrogen/generated/shared/c++/HybridPeripheralSpec.hpp +79 -0
  26. package/package.json +4 -7
  27. package/scripts/{patch-nitro-modules.sh → patch-platforms-definition.sh} +1 -11
  28. package/src/index.ts +4 -1
  29. package/src/specs/Adapter.nitro.ts +94 -7
  30. package/src/specs/Peripheral.nitro.ts +94 -0
@@ -2,19 +2,104 @@
2
2
 
3
3
  namespace margelo::nitro::simplejsble {
4
4
 
5
- std::string HybridAdapter::greet(const std::string& name) { return "Hello, " + name + "!"; }
5
+ bool HybridAdapter::bluetooth_enabled() {
6
+ return SimpleBLE::Adapter::bluetooth_enabled();
7
+ }
6
8
 
7
9
  std::vector<std::shared_ptr<HybridAdapterSpec>> HybridAdapter::get_adapters() {
8
10
  std::vector<std::shared_ptr<HybridAdapterSpec>> result;
9
-
10
11
  for (auto& adapter : SimpleBLE::Adapter::get_adapters()) {
11
- auto hybrid_adapter = std::make_shared<HybridAdapter>(adapter);
12
- result.push_back(hybrid_adapter);
12
+ result.push_back(std::make_shared<HybridAdapter>(std::move(adapter)));
13
13
  }
14
+ return result;
15
+ }
16
+
17
+ bool HybridAdapter::initialized() {
18
+ return _adapter.initialized();
19
+ }
20
+
21
+ std::string HybridAdapter::identifier() {
22
+ return _adapter.identifier();
23
+ }
24
+
25
+ std::string HybridAdapter::address() {
26
+ return _adapter.address();
27
+ }
28
+
29
+ bool HybridAdapter::is_powered() {
30
+ return _adapter.is_powered();
31
+ }
32
+
33
+ void HybridAdapter::scan_start() {
34
+ _adapter.scan_start();
35
+ }
36
+
37
+ void HybridAdapter::scan_stop() {
38
+ _adapter.scan_stop();
39
+ }
14
40
 
41
+ void HybridAdapter::scan_for(double timeout_ms) {
42
+ _adapter.scan_for(static_cast<int>(timeout_ms));
43
+ }
44
+
45
+ bool HybridAdapter::scan_is_active() {
46
+ return _adapter.scan_is_active();
47
+ }
48
+
49
+ std::vector<std::shared_ptr<HybridPeripheralSpec>> HybridAdapter::scan_get_results() {
50
+ std::vector<std::shared_ptr<HybridPeripheralSpec>> result;
51
+ for (auto& peripheral : _adapter.scan_get_results()) {
52
+ result.push_back(std::make_shared<HybridPeripheral>(std::move(peripheral)));
53
+ }
15
54
  return result;
16
55
  }
17
56
 
18
- bool HybridAdapter::bluetooth_enabled() { return SimpleBLE::Adapter::bluetooth_enabled(); }
57
+ void HybridAdapter::set_callback_on_scan_start(const std::function<void()>& callback) {
58
+ _onScanStart = callback;
59
+ _adapter.set_callback_on_scan_start([this]() {
60
+ if (_onScanStart) {
61
+ _onScanStart();
62
+ }
63
+ });
64
+ }
65
+
66
+ void HybridAdapter::set_callback_on_scan_stop(const std::function<void()>& callback) {
67
+ _onScanStop = callback;
68
+ _adapter.set_callback_on_scan_stop([this]() {
69
+ if (_onScanStop) {
70
+ _onScanStop();
71
+ }
72
+ });
73
+ }
74
+
75
+ void HybridAdapter::set_callback_on_scan_updated(
76
+ const std::function<void(const std::shared_ptr<HybridPeripheralSpec>&)>& callback) {
77
+ _onScanUpdated = callback;
78
+ _adapter.set_callback_on_scan_updated([this](SimpleBLE::Peripheral peripheral) {
79
+ if (_onScanUpdated) {
80
+ auto hybridPeripheral = std::make_shared<HybridPeripheral>(std::move(peripheral));
81
+ _onScanUpdated(hybridPeripheral);
82
+ }
83
+ });
84
+ }
85
+
86
+ void HybridAdapter::set_callback_on_scan_found(
87
+ const std::function<void(const std::shared_ptr<HybridPeripheralSpec>&)>& callback) {
88
+ _onScanFound = callback;
89
+ _adapter.set_callback_on_scan_found([this](SimpleBLE::Peripheral peripheral) {
90
+ if (_onScanFound) {
91
+ auto hybridPeripheral = std::make_shared<HybridPeripheral>(std::move(peripheral));
92
+ _onScanFound(hybridPeripheral);
93
+ }
94
+ });
95
+ }
96
+
97
+ std::vector<std::shared_ptr<HybridPeripheralSpec>> HybridAdapter::get_paired_peripherals() {
98
+ std::vector<std::shared_ptr<HybridPeripheralSpec>> result;
99
+ for (auto& peripheral : _adapter.get_paired_peripherals()) {
100
+ result.push_back(std::make_shared<HybridPeripheral>(std::move(peripheral)));
101
+ }
102
+ return result;
103
+ }
19
104
 
20
- } // namespace margelo::nitro::simplejsble
105
+ } // namespace margelo::nitro::simplejsble
@@ -1,22 +1,51 @@
1
1
  #pragma once
2
2
 
3
3
  #include "HybridAdapterSpec.hpp"
4
+ #include "HybridPeripheral.hpp"
4
5
  #include <simpleble/SimpleBLE.h>
6
+ #include <functional>
5
7
  #include <string>
8
+ #include <vector>
9
+ #include <memory>
6
10
 
7
11
  namespace margelo::nitro::simplejsble {
8
12
 
9
13
  class HybridAdapter : public HybridAdapterSpec {
10
14
  public:
11
15
  HybridAdapter() : HybridObject(TAG) {}
12
- HybridAdapter(SimpleBLE::Adapter adapter) : HybridObject(TAG), _adapter(adapter) {}
16
+ explicit HybridAdapter(SimpleBLE::Adapter adapter)
17
+ : HybridObject(TAG), _adapter(std::move(adapter)) {}
13
18
 
14
- std::string greet(const std::string& name) override;
15
- std::vector<std::shared_ptr<HybridAdapterSpec>> get_adapters() override;
16
19
  bool bluetooth_enabled() override;
20
+ std::vector<std::shared_ptr<HybridAdapterSpec>> get_adapters() override;
21
+
22
+ bool initialized() override;
23
+ std::string identifier() override;
24
+ std::string address() override;
25
+
26
+ bool is_powered() override;
27
+
28
+ void scan_start() override;
29
+ void scan_stop() override;
30
+ void scan_for(double timeout_ms) override;
31
+ bool scan_is_active() override;
32
+ std::vector<std::shared_ptr<HybridPeripheralSpec>> scan_get_results() override;
33
+ void set_callback_on_scan_start(const std::function<void()>& callback) override;
34
+ void set_callback_on_scan_stop(const std::function<void()>& callback) override;
35
+ void set_callback_on_scan_updated(
36
+ const std::function<void(const std::shared_ptr<HybridPeripheralSpec>&)>& callback) override;
37
+ void set_callback_on_scan_found(
38
+ const std::function<void(const std::shared_ptr<HybridPeripheralSpec>&)>& callback) override;
39
+
40
+ std::vector<std::shared_ptr<HybridPeripheralSpec>> get_paired_peripherals() override;
17
41
 
18
42
  private:
19
43
  SimpleBLE::Adapter _adapter;
44
+
45
+ std::function<void()> _onScanStart;
46
+ std::function<void()> _onScanStop;
47
+ std::function<void(const std::shared_ptr<HybridPeripheralSpec>&)> _onScanUpdated;
48
+ std::function<void(const std::shared_ptr<HybridPeripheralSpec>&)> _onScanFound;
20
49
  };
21
50
 
22
- } // namespace margelo::nitro::simplejsble
51
+ } // namespace margelo::nitro::simplejsble
@@ -0,0 +1,83 @@
1
+ #include "HybridPeripheral.hpp"
2
+
3
+ namespace margelo::nitro::simplejsble {
4
+
5
+ bool HybridPeripheral::initialized() {
6
+ return _peripheral.initialized();
7
+ }
8
+
9
+ std::string HybridPeripheral::identifier() {
10
+ return _peripheral.identifier();
11
+ }
12
+
13
+ std::string HybridPeripheral::address() {
14
+ return _peripheral.address();
15
+ }
16
+
17
+ BluetoothAddressType HybridPeripheral::address_type() {
18
+ auto type = _peripheral.address_type();
19
+ switch (type) {
20
+ case SimpleBLE::BluetoothAddressType::PUBLIC:
21
+ return BluetoothAddressType::PUBLIC;
22
+ case SimpleBLE::BluetoothAddressType::RANDOM:
23
+ return BluetoothAddressType::RANDOM;
24
+ default:
25
+ return BluetoothAddressType::UNSPECIFIED;
26
+ }
27
+ }
28
+
29
+ double HybridPeripheral::rssi() {
30
+ return static_cast<double>(_peripheral.rssi());
31
+ }
32
+
33
+ double HybridPeripheral::tx_power() {
34
+ return static_cast<double>(_peripheral.tx_power());
35
+ }
36
+
37
+ double HybridPeripheral::mtu() {
38
+ return static_cast<double>(_peripheral.mtu());
39
+ }
40
+
41
+ void HybridPeripheral::connect() {
42
+ _peripheral.connect();
43
+ }
44
+
45
+ void HybridPeripheral::disconnect() {
46
+ _peripheral.disconnect();
47
+ }
48
+
49
+ bool HybridPeripheral::is_connected() {
50
+ return _peripheral.is_connected();
51
+ }
52
+
53
+ bool HybridPeripheral::is_connectable() {
54
+ return _peripheral.is_connectable();
55
+ }
56
+
57
+ bool HybridPeripheral::is_paired() {
58
+ return _peripheral.is_paired();
59
+ }
60
+
61
+ void HybridPeripheral::unpair() {
62
+ _peripheral.unpair();
63
+ }
64
+
65
+ void HybridPeripheral::set_callback_on_connected(const std::function<void()>& callback) {
66
+ _onConnected = callback;
67
+ _peripheral.set_callback_on_connected([this]() {
68
+ if (_onConnected) {
69
+ _onConnected();
70
+ }
71
+ });
72
+ }
73
+
74
+ void HybridPeripheral::set_callback_on_disconnected(const std::function<void()>& callback) {
75
+ _onDisconnected = callback;
76
+ _peripheral.set_callback_on_disconnected([this]() {
77
+ if (_onDisconnected) {
78
+ _onDisconnected();
79
+ }
80
+ });
81
+ }
82
+
83
+ } // namespace margelo::nitro::simplejsble
@@ -0,0 +1,45 @@
1
+ #pragma once
2
+
3
+ #include "HybridPeripheralSpec.hpp"
4
+ #include "BluetoothAddressType.hpp"
5
+ #include <simpleble/SimpleBLE.h>
6
+ #include <functional>
7
+ #include <string>
8
+
9
+ namespace margelo::nitro::simplejsble {
10
+
11
+ class HybridPeripheral : public HybridPeripheralSpec {
12
+ public:
13
+ HybridPeripheral() : HybridObject(TAG) {}
14
+ explicit HybridPeripheral(SimpleBLE::Peripheral peripheral)
15
+ : HybridObject(TAG), _peripheral(std::move(peripheral)) {}
16
+
17
+ bool initialized() override;
18
+ std::string identifier() override;
19
+ std::string address() override;
20
+ BluetoothAddressType address_type() override;
21
+ double rssi() override;
22
+ double tx_power() override;
23
+ double mtu() override;
24
+
25
+ void connect() override;
26
+ void disconnect() override;
27
+ bool is_connected() override;
28
+ bool is_connectable() override;
29
+ bool is_paired() override;
30
+ void unpair() override;
31
+
32
+ void set_callback_on_connected(const std::function<void()>& callback) override;
33
+ void set_callback_on_disconnected(const std::function<void()>& callback) override;
34
+
35
+ SimpleBLE::Peripheral& getInternal() { return _peripheral; }
36
+ const SimpleBLE::Peripheral& getInternal() const { return _peripheral; }
37
+
38
+ private:
39
+ SimpleBLE::Peripheral _peripheral;
40
+
41
+ std::function<void()> _onConnected;
42
+ std::function<void()> _onDisconnected;
43
+ };
44
+
45
+ } // namespace margelo::nitro::simplejsble
package/lib/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  import type { Adapter } from "./specs/Adapter.nitro";
2
+ import type { Peripheral, BluetoothAddressType } from "./specs/Peripheral.nitro";
3
+ export type { Adapter, Peripheral, BluetoothAddressType };
2
4
  export declare const HybridAdapter: Adapter;
5
+ export declare const HybridPeripheral: Peripheral;
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGrD,eAAO,MAAM,aAAa,SAAsD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEjF,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC;AAE1D,eAAO,MAAM,aAAa,SAAsD,CAAC;AACjF,eAAO,MAAM,gBAAgB,YAA4D,CAAC"}
package/lib/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  import { NitroModules } from "react-native-nitro-modules";
2
2
  export const HybridAdapter = NitroModules.createHybridObject("Adapter");
3
+ export const HybridPeripheral = NitroModules.createHybridObject("Peripheral");
@@ -1,10 +1,80 @@
1
1
  import { type HybridObject } from 'react-native-nitro-modules';
2
+ import { type Peripheral } from './Peripheral.nitro';
3
+ /**
4
+ * Wraps SimpleBLE::Adapter
5
+ */
2
6
  export interface Adapter extends HybridObject<{
3
7
  ios: 'c++';
4
8
  android: 'c++';
5
9
  }> {
6
- greet(name: string): string;
7
- get_adapters(): Adapter[];
10
+ /**
11
+ * Check if Bluetooth is enabled on the system.
12
+ */
8
13
  bluetooth_enabled(): boolean;
14
+ /**
15
+ * Retrieve a list of all available Bluetooth adapters.
16
+ */
17
+ get_adapters(): Adapter[];
18
+ /**
19
+ * Check if the adapter is initialized (has a valid internal handle).
20
+ */
21
+ initialized(): boolean;
22
+ /**
23
+ * Human-readable identifier for the adapter.
24
+ */
25
+ identifier(): string;
26
+ /**
27
+ * Bluetooth address of the adapter (MAC on Android/Linux, identifier on IOS/Macos).
28
+ */
29
+ address(): string;
30
+ /**
31
+ * Check if the adapter is currently powered on.
32
+ */
33
+ is_powered(): boolean;
34
+ /**
35
+ * Start scanning for peripherals.
36
+ */
37
+ scan_start(): void;
38
+ /**
39
+ * Stop scanning for peripherals.
40
+ */
41
+ scan_stop(): void;
42
+ /**
43
+ * Scan for peripherals for a specified duration (blocking).
44
+ * @param timeout_ms Duration in milliseconds.
45
+ */
46
+ scan_for(timeout_ms: number): void;
47
+ /**
48
+ * Check if a scan is currently in progress.
49
+ */
50
+ scan_is_active(): boolean;
51
+ /**
52
+ * Get the list of peripherals discovered during the last scan.
53
+ */
54
+ scan_get_results(): Peripheral[];
55
+ /**
56
+ * Set callback to be invoked when scanning starts.
57
+ */
58
+ set_callback_on_scan_start(callback: () => void): void;
59
+ /**
60
+ * Set callback to be invoked when scanning stops.
61
+ */
62
+ set_callback_on_scan_stop(callback: () => void): void;
63
+ /**
64
+ * Set callback to be invoked when a known peripheral's advertisement is updated.
65
+ */
66
+ set_callback_on_scan_updated(callback: (peripheral: Peripheral) => void): void;
67
+ /**
68
+ * Set callback to be invoked when a new peripheral is discovered.
69
+ */
70
+ set_callback_on_scan_found(callback: (peripheral: Peripheral) => void): void;
71
+ /**
72
+ * Retrieve a list of all paired peripherals.
73
+ * - Android: Supported (uses BluetoothAdapter.getBondedDevices())
74
+ * - iOS: Not supported - CoreBluetooth does not expose a direct API to list paired devices.
75
+ * Pairing is handled at the OS level, and CoreBluetooth only exposes devices discovered via scanning
76
+ * or those you've connected to.
77
+ */
78
+ get_paired_peripherals(): Peripheral[];
9
79
  }
10
80
  //# sourceMappingURL=Adapter.nitro.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Adapter.nitro.d.ts","sourceRoot":"","sources":["../../src/specs/Adapter.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,MAAM,WAAW,OAAQ,SAAQ,YAAY,CAAC;IAC5C,GAAG,EAAE,KAAK,CAAC;IACX,OAAO,EAAE,KAAK,CAAA;CACf,CAAC;IACA,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IAC3B,YAAY,IAAI,OAAO,EAAE,CAAA;IACzB,iBAAiB,IAAI,OAAO,CAAA;CAC7B"}
1
+ {"version":3,"file":"Adapter.nitro.d.ts","sourceRoot":"","sources":["../../src/specs/Adapter.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEpD;;GAEG;AACH,MAAM,WAAW,OACf,SAAQ,YAAY,CAAC;IACnB,GAAG,EAAE,KAAK,CAAA;IACV,OAAO,EAAE,KAAK,CAAA;CACf,CAAC;IACF;;OAEG;IACH,iBAAiB,IAAI,OAAO,CAAA;IAE5B;;OAEG;IACH,YAAY,IAAI,OAAO,EAAE,CAAA;IAEzB;;OAEG;IACH,WAAW,IAAI,OAAO,CAAA;IAEtB;;OAEG;IACH,UAAU,IAAI,MAAM,CAAA;IAEpB;;OAEG;IACH,OAAO,IAAI,MAAM,CAAA;IAEjB;;OAEG;IACH,UAAU,IAAI,OAAO,CAAA;IAErB;;OAEG;IACH,UAAU,IAAI,IAAI,CAAA;IAElB;;OAEG;IACH,SAAS,IAAI,IAAI,CAAA;IAEjB;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IAElC;;OAEG;IACH,cAAc,IAAI,OAAO,CAAA;IAEzB;;OAEG;IACH,gBAAgB,IAAI,UAAU,EAAE,CAAA;IAEhC;;OAEG;IACH,0BAA0B,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAA;IAEtD;;OAEG;IACH,yBAAyB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAA;IAErD;;OAEG;IACH,4BAA4B,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,GAAG,IAAI,CAAA;IAE9E;;OAEG;IACH,0BAA0B,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,GAAG,IAAI,CAAA;IAE5E;;;;;;OAMG;IACH,sBAAsB,IAAI,UAAU,EAAE,CAAA;CACvC"}
@@ -1 +1,2 @@
1
1
  import {} from 'react-native-nitro-modules';
2
+ import {} from './Peripheral.nitro';
@@ -0,0 +1,78 @@
1
+ import { type HybridObject } from 'react-native-nitro-modules';
2
+ /**
3
+ * Bluetooth address type enumeration.
4
+ * Maps to SimpleBLE::BluetoothAddressType
5
+ */
6
+ export type BluetoothAddressType = 'public' | 'random' | 'unspecified';
7
+ /**
8
+ * Minimal wrapper for SimpleBLE::Peripheral.
9
+ * Exposes core properties and connection methods without
10
+ * introducing Service/ByteArray types.
11
+ */
12
+ export interface Peripheral extends HybridObject<{
13
+ ios: 'c++';
14
+ android: 'c++';
15
+ }> {
16
+ /**
17
+ * Check if the peripheral is initialized (has a valid internal handle).
18
+ */
19
+ initialized(): boolean;
20
+ /**
21
+ * Human- able identifier (device name or fallback).
22
+ */
23
+ identifier(): string;
24
+ /**
25
+ * Bluetooth address (MAC on Android, UUID on IOS/Macos).
26
+ */
27
+ address(): string;
28
+ /**
29
+ * Address type (public, random, or unspecified).
30
+ */
31
+ address_type(): BluetoothAddressType;
32
+ /**
33
+ * Received Signal Strength Indicator in dBm.
34
+ */
35
+ rssi(): number;
36
+ /**
37
+ * Advertised transmit power in dBm.
38
+ * Returns -32768 if not advertised.
39
+ */
40
+ tx_power(): number;
41
+ /**
42
+ * Maximum Transmission Unit size.
43
+ */
44
+ mtu(): number;
45
+ /**
46
+ * Initiate a connection to the peripheral.
47
+ */
48
+ connect(): void;
49
+ /**
50
+ * Disconnect from the peripheral.
51
+ */
52
+ disconnect(): void;
53
+ /**
54
+ * Check if the peripheral is currently connected.
55
+ */
56
+ is_connected(): boolean;
57
+ /**
58
+ * Check if the peripheral is connectable.
59
+ */
60
+ is_connectable(): boolean;
61
+ /**
62
+ * Check if the peripheral is paired with the system.
63
+ */
64
+ is_paired(): boolean;
65
+ /**
66
+ * Remove the pairing/bond with the peripheral.
67
+ */
68
+ unpair(): void;
69
+ /**
70
+ * Set callback to be invoked when a connection is established.
71
+ */
72
+ set_callback_on_connected(callback: () => void): void;
73
+ /**
74
+ * Set callback to be invoked when the peripheral disconnects.
75
+ */
76
+ set_callback_on_disconnected(callback: () => void): void;
77
+ }
78
+ //# sourceMappingURL=Peripheral.nitro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Peripheral.nitro.d.ts","sourceRoot":"","sources":["../../src/specs/Peripheral.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,QAAQ,GAAG,aAAa,CAAA;AAEtE;;;;GAIG;AACH,MAAM,WAAW,UACf,SAAQ,YAAY,CAAC;IACnB,GAAG,EAAE,KAAK,CAAA;IACV,OAAO,EAAE,KAAK,CAAA;CACf,CAAC;IACF;;OAEG;IACH,WAAW,IAAI,OAAO,CAAA;IAEtB;;OAEG;IACH,UAAU,IAAI,MAAM,CAAA;IAEpB;;OAEG;IACH,OAAO,IAAI,MAAM,CAAA;IAEjB;;OAEG;IACH,YAAY,IAAI,oBAAoB,CAAA;IAEpC;;OAEG;IACH,IAAI,IAAI,MAAM,CAAA;IAEd;;;OAGG;IACH,QAAQ,IAAI,MAAM,CAAA;IAElB;;OAEG;IACH,GAAG,IAAI,MAAM,CAAA;IAEb;;OAEG;IACH,OAAO,IAAI,IAAI,CAAA;IAEf;;OAEG;IACH,UAAU,IAAI,IAAI,CAAA;IAElB;;OAEG;IACH,YAAY,IAAI,OAAO,CAAA;IAEvB;;OAEG;IACH,cAAc,IAAI,OAAO,CAAA;IAEzB;;OAEG;IACH,SAAS,IAAI,OAAO,CAAA;IAEpB;;OAEG;IACH,MAAM,IAAI,IAAI,CAAA;IAEd;;OAEG;IACH,yBAAyB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAA;IAErD;;OAEG;IACH,4BAA4B,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAA;CACzD"}
@@ -0,0 +1 @@
1
+ import {} from 'react-native-nitro-modules';
package/nitro.json CHANGED
@@ -15,6 +15,9 @@
15
15
  "autolinking": {
16
16
  "Adapter": {
17
17
  "cpp": "HybridAdapter"
18
+ },
19
+ "Peripheral": {
20
+ "cpp": "HybridPeripheral"
18
21
  }
19
22
  },
20
23
  "ignorePaths": [
@@ -34,6 +34,7 @@ target_sources(
34
34
  ../nitrogen/generated/android/NitroSimplejsbleOnLoad.cpp
35
35
  # Shared Nitrogen C++ sources
36
36
  ../nitrogen/generated/shared/c++/HybridAdapterSpec.cpp
37
+ ../nitrogen/generated/shared/c++/HybridPeripheralSpec.cpp
37
38
  # Android-specific Nitrogen C++ sources
38
39
 
39
40
  )
@@ -16,6 +16,7 @@
16
16
  #include <NitroModules/HybridObjectRegistry.hpp>
17
17
 
18
18
  #include "HybridAdapter.hpp"
19
+ #include "HybridPeripheral.hpp"
19
20
 
20
21
  namespace margelo::nitro::simplejsble {
21
22
 
@@ -38,6 +39,15 @@ int initialize(JavaVM* vm) {
38
39
  return std::make_shared<HybridAdapter>();
39
40
  }
40
41
  );
42
+ HybridObjectRegistry::registerHybridObjectConstructor(
43
+ "Peripheral",
44
+ []() -> std::shared_ptr<HybridObject> {
45
+ static_assert(std::is_default_constructible_v<HybridPeripheral>,
46
+ "The HybridObject \"HybridPeripheral\" is not default-constructible! "
47
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
48
+ return std::make_shared<HybridPeripheral>();
49
+ }
50
+ );
41
51
  });
42
52
  }
43
53
 
@@ -11,6 +11,7 @@
11
11
  #import <type_traits>
12
12
 
13
13
  #include "HybridAdapter.hpp"
14
+ #include "HybridPeripheral.hpp"
14
15
 
15
16
  @interface NitroSimplejsbleAutolinking : NSObject
16
17
  @end
@@ -30,6 +31,15 @@
30
31
  return std::make_shared<HybridAdapter>();
31
32
  }
32
33
  );
34
+ HybridObjectRegistry::registerHybridObjectConstructor(
35
+ "Peripheral",
36
+ []() -> std::shared_ptr<HybridObject> {
37
+ static_assert(std::is_default_constructible_v<HybridPeripheral>,
38
+ "The HybridObject \"HybridPeripheral\" is not default-constructible! "
39
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
40
+ return std::make_shared<HybridPeripheral>();
41
+ }
42
+ );
33
43
  }
34
44
 
35
45
  @end
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// BluetoothAddressType.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::simplejsble {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (BluetoothAddressType).
30
+ */
31
+ enum class BluetoothAddressType {
32
+ PUBLIC SWIFT_NAME(public) = 0,
33
+ RANDOM SWIFT_NAME(random) = 1,
34
+ UNSPECIFIED SWIFT_NAME(unspecified) = 2,
35
+ } CLOSED_ENUM;
36
+
37
+ } // namespace margelo::nitro::simplejsble
38
+
39
+ namespace margelo::nitro {
40
+
41
+ // C++ BluetoothAddressType <> JS BluetoothAddressType (union)
42
+ template <>
43
+ struct JSIConverter<margelo::nitro::simplejsble::BluetoothAddressType> final {
44
+ static inline margelo::nitro::simplejsble::BluetoothAddressType fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
45
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
46
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
47
+ case hashString("public"): return margelo::nitro::simplejsble::BluetoothAddressType::PUBLIC;
48
+ case hashString("random"): return margelo::nitro::simplejsble::BluetoothAddressType::RANDOM;
49
+ case hashString("unspecified"): return margelo::nitro::simplejsble::BluetoothAddressType::UNSPECIFIED;
50
+ default: [[unlikely]]
51
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum BluetoothAddressType - invalid value!");
52
+ }
53
+ }
54
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::simplejsble::BluetoothAddressType arg) {
55
+ switch (arg) {
56
+ case margelo::nitro::simplejsble::BluetoothAddressType::PUBLIC: return JSIConverter<std::string>::toJSI(runtime, "public");
57
+ case margelo::nitro::simplejsble::BluetoothAddressType::RANDOM: return JSIConverter<std::string>::toJSI(runtime, "random");
58
+ case margelo::nitro::simplejsble::BluetoothAddressType::UNSPECIFIED: return JSIConverter<std::string>::toJSI(runtime, "unspecified");
59
+ default: [[unlikely]]
60
+ throw std::invalid_argument("Cannot convert BluetoothAddressType to JS - invalid value: "
61
+ + std::to_string(static_cast<int>(arg)) + "!");
62
+ }
63
+ }
64
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
65
+ if (!value.isString()) {
66
+ return false;
67
+ }
68
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
69
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
70
+ case hashString("public"):
71
+ case hashString("random"):
72
+ case hashString("unspecified"):
73
+ return true;
74
+ default:
75
+ return false;
76
+ }
77
+ }
78
+ };
79
+
80
+ } // namespace margelo::nitro
@@ -14,9 +14,22 @@ namespace margelo::nitro::simplejsble {
14
14
  HybridObject::loadHybridMethods();
15
15
  // load custom methods/properties
16
16
  registerHybrids(this, [](Prototype& prototype) {
17
- prototype.registerHybridMethod("greet", &HybridAdapterSpec::greet);
18
- prototype.registerHybridMethod("get_adapters", &HybridAdapterSpec::get_adapters);
19
17
  prototype.registerHybridMethod("bluetooth_enabled", &HybridAdapterSpec::bluetooth_enabled);
18
+ prototype.registerHybridMethod("get_adapters", &HybridAdapterSpec::get_adapters);
19
+ prototype.registerHybridMethod("initialized", &HybridAdapterSpec::initialized);
20
+ prototype.registerHybridMethod("identifier", &HybridAdapterSpec::identifier);
21
+ prototype.registerHybridMethod("address", &HybridAdapterSpec::address);
22
+ prototype.registerHybridMethod("is_powered", &HybridAdapterSpec::is_powered);
23
+ prototype.registerHybridMethod("scan_start", &HybridAdapterSpec::scan_start);
24
+ prototype.registerHybridMethod("scan_stop", &HybridAdapterSpec::scan_stop);
25
+ prototype.registerHybridMethod("scan_for", &HybridAdapterSpec::scan_for);
26
+ prototype.registerHybridMethod("scan_is_active", &HybridAdapterSpec::scan_is_active);
27
+ prototype.registerHybridMethod("scan_get_results", &HybridAdapterSpec::scan_get_results);
28
+ prototype.registerHybridMethod("set_callback_on_scan_start", &HybridAdapterSpec::set_callback_on_scan_start);
29
+ prototype.registerHybridMethod("set_callback_on_scan_stop", &HybridAdapterSpec::set_callback_on_scan_stop);
30
+ prototype.registerHybridMethod("set_callback_on_scan_updated", &HybridAdapterSpec::set_callback_on_scan_updated);
31
+ prototype.registerHybridMethod("set_callback_on_scan_found", &HybridAdapterSpec::set_callback_on_scan_found);
32
+ prototype.registerHybridMethod("get_paired_peripherals", &HybridAdapterSpec::get_paired_peripherals);
20
33
  });
21
34
  }
22
35
 
@@ -15,11 +15,15 @@
15
15
 
16
16
  // Forward declaration of `HybridAdapterSpec` to properly resolve imports.
17
17
  namespace margelo::nitro::simplejsble { class HybridAdapterSpec; }
18
+ // Forward declaration of `HybridPeripheralSpec` to properly resolve imports.
19
+ namespace margelo::nitro::simplejsble { class HybridPeripheralSpec; }
18
20
 
19
- #include <string>
20
21
  #include <memory>
21
22
  #include "HybridAdapterSpec.hpp"
22
23
  #include <vector>
24
+ #include <string>
25
+ #include "HybridPeripheralSpec.hpp"
26
+ #include <functional>
23
27
 
24
28
  namespace margelo::nitro::simplejsble {
25
29
 
@@ -52,9 +56,22 @@ namespace margelo::nitro::simplejsble {
52
56
 
53
57
  public:
54
58
  // Methods
55
- virtual std::string greet(const std::string& name) = 0;
56
- virtual std::vector<std::shared_ptr<HybridAdapterSpec>> get_adapters() = 0;
57
59
  virtual bool bluetooth_enabled() = 0;
60
+ virtual std::vector<std::shared_ptr<HybridAdapterSpec>> get_adapters() = 0;
61
+ virtual bool initialized() = 0;
62
+ virtual std::string identifier() = 0;
63
+ virtual std::string address() = 0;
64
+ virtual bool is_powered() = 0;
65
+ virtual void scan_start() = 0;
66
+ virtual void scan_stop() = 0;
67
+ virtual void scan_for(double timeout_ms) = 0;
68
+ virtual bool scan_is_active() = 0;
69
+ virtual std::vector<std::shared_ptr<HybridPeripheralSpec>> scan_get_results() = 0;
70
+ virtual void set_callback_on_scan_start(const std::function<void()>& callback) = 0;
71
+ virtual void set_callback_on_scan_stop(const std::function<void()>& callback) = 0;
72
+ virtual void set_callback_on_scan_updated(const std::function<void(const std::shared_ptr<HybridPeripheralSpec>& /* peripheral */)>& callback) = 0;
73
+ virtual void set_callback_on_scan_found(const std::function<void(const std::shared_ptr<HybridPeripheralSpec>& /* peripheral */)>& callback) = 0;
74
+ virtual std::vector<std::shared_ptr<HybridPeripheralSpec>> get_paired_peripherals() = 0;
58
75
 
59
76
  protected:
60
77
  // Hybrid Setup
@@ -0,0 +1,35 @@
1
+ ///
2
+ /// HybridPeripheralSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridPeripheralSpec.hpp"
9
+
10
+ namespace margelo::nitro::simplejsble {
11
+
12
+ void HybridPeripheralSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("initialized", &HybridPeripheralSpec::initialized);
18
+ prototype.registerHybridMethod("identifier", &HybridPeripheralSpec::identifier);
19
+ prototype.registerHybridMethod("address", &HybridPeripheralSpec::address);
20
+ prototype.registerHybridMethod("address_type", &HybridPeripheralSpec::address_type);
21
+ prototype.registerHybridMethod("rssi", &HybridPeripheralSpec::rssi);
22
+ prototype.registerHybridMethod("tx_power", &HybridPeripheralSpec::tx_power);
23
+ prototype.registerHybridMethod("mtu", &HybridPeripheralSpec::mtu);
24
+ prototype.registerHybridMethod("connect", &HybridPeripheralSpec::connect);
25
+ prototype.registerHybridMethod("disconnect", &HybridPeripheralSpec::disconnect);
26
+ prototype.registerHybridMethod("is_connected", &HybridPeripheralSpec::is_connected);
27
+ prototype.registerHybridMethod("is_connectable", &HybridPeripheralSpec::is_connectable);
28
+ prototype.registerHybridMethod("is_paired", &HybridPeripheralSpec::is_paired);
29
+ prototype.registerHybridMethod("unpair", &HybridPeripheralSpec::unpair);
30
+ prototype.registerHybridMethod("set_callback_on_connected", &HybridPeripheralSpec::set_callback_on_connected);
31
+ prototype.registerHybridMethod("set_callback_on_disconnected", &HybridPeripheralSpec::set_callback_on_disconnected);
32
+ });
33
+ }
34
+
35
+ } // namespace margelo::nitro::simplejsble
@@ -0,0 +1,79 @@
1
+ ///
2
+ /// HybridPeripheralSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `BluetoothAddressType` to properly resolve imports.
17
+ namespace margelo::nitro::simplejsble { enum class BluetoothAddressType; }
18
+
19
+ #include <string>
20
+ #include "BluetoothAddressType.hpp"
21
+ #include <functional>
22
+
23
+ namespace margelo::nitro::simplejsble {
24
+
25
+ using namespace margelo::nitro;
26
+
27
+ /**
28
+ * An abstract base class for `Peripheral`
29
+ * Inherit this class to create instances of `HybridPeripheralSpec` in C++.
30
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
31
+ * @example
32
+ * ```cpp
33
+ * class HybridPeripheral: public HybridPeripheralSpec {
34
+ * public:
35
+ * HybridPeripheral(...): HybridObject(TAG) { ... }
36
+ * // ...
37
+ * };
38
+ * ```
39
+ */
40
+ class HybridPeripheralSpec: public virtual HybridObject {
41
+ public:
42
+ // Constructor
43
+ explicit HybridPeripheralSpec(): HybridObject(TAG) { }
44
+
45
+ // Destructor
46
+ ~HybridPeripheralSpec() override = default;
47
+
48
+ public:
49
+ // Properties
50
+
51
+
52
+ public:
53
+ // Methods
54
+ virtual bool initialized() = 0;
55
+ virtual std::string identifier() = 0;
56
+ virtual std::string address() = 0;
57
+ virtual BluetoothAddressType address_type() = 0;
58
+ virtual double rssi() = 0;
59
+ virtual double tx_power() = 0;
60
+ virtual double mtu() = 0;
61
+ virtual void connect() = 0;
62
+ virtual void disconnect() = 0;
63
+ virtual bool is_connected() = 0;
64
+ virtual bool is_connectable() = 0;
65
+ virtual bool is_paired() = 0;
66
+ virtual void unpair() = 0;
67
+ virtual void set_callback_on_connected(const std::function<void()>& callback) = 0;
68
+ virtual void set_callback_on_disconnected(const std::function<void()>& callback) = 0;
69
+
70
+ protected:
71
+ // Hybrid Setup
72
+ void loadHybridMethods() override;
73
+
74
+ protected:
75
+ // Tag for logging
76
+ static constexpr auto TAG = "Peripheral";
77
+ };
78
+
79
+ } // namespace margelo::nitro::simplejsble
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplejsble",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "React Native Bluetooth Low Energy library using SimpleBLE with Nitro Modules",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -27,7 +27,7 @@
27
27
  "README.md"
28
28
  ],
29
29
  "scripts": {
30
- "postinstall": "bash scripts/patch-nitro-modules.sh",
30
+ "postinstall": "bash scripts/patch-platforms-definition.sh",
31
31
  "prepack": "npm run build && npx nitrogen && bash scripts/prepare-package.sh",
32
32
  "typecheck": "tsc --noEmit",
33
33
  "build": "tsc",
@@ -64,9 +64,6 @@
64
64
  "registry": "https://registry.npmjs.org/",
65
65
  "access": "public"
66
66
  },
67
- "dependencies": {
68
- "react-native-nitro-modules": ">=0.20.0"
69
- },
70
67
  "devDependencies": {
71
68
  "@react-native/eslint-config": "0.82.0",
72
69
  "@types/react": "^19.1.03",
@@ -77,12 +74,12 @@
77
74
  "prettier": "^3.3.3",
78
75
  "react": "19.1.0",
79
76
  "react-native": "0.81.5",
80
- "react-native-nitro-modules": "*",
81
77
  "typescript": "^5.8.3"
82
78
  },
83
79
  "peerDependencies": {
84
80
  "react": "*",
85
- "react-native": "*"
81
+ "react-native": "*",
82
+ "react-native-nitro-modules": ">=0.20.0"
86
83
  },
87
84
  "eslintConfig": {
88
85
  "root": true,
@@ -12,9 +12,7 @@
12
12
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13
13
  SCRIPT_NAME="[simplejsble]"
14
14
 
15
- # Possible locations for NitroModules.podspec
16
15
  PATHS=(
17
- # When simplejsble is in node_modules (user's project)
18
16
  "$SCRIPT_DIR/../../react-native-nitro-modules/NitroModules.podspec"
19
17
  )
20
18
 
@@ -31,35 +29,27 @@ if [ -z "$PODSPEC_PATH" ]; then
31
29
  exit 0
32
30
  fi
33
31
 
34
- # Check if already patched
35
32
  if grep -q "s\.ios\.deployment_target" "$PODSPEC_PATH" || grep -q "s\.macos\.deployment_target" "$PODSPEC_PATH"; then
36
33
  echo "$SCRIPT_NAME NitroModules.podspec already using standard syntax"
37
34
  exit 0
38
35
  fi
39
36
 
40
- # Check if has the old syntax
41
37
  if ! grep -q "s\.platforms" "$PODSPEC_PATH"; then
42
38
  echo "$SCRIPT_NAME NitroModules.podspec format not recognized, skipping patch"
43
39
  exit 0
44
40
  fi
45
41
 
46
- # Create the replacement
47
42
  NEW_SYNTAX="s.ios.deployment_target = '15.8'
48
43
  s.macos.deployment_target = '13.0'
49
44
  s.tvos.deployment_target = '13.4'
50
45
  s.visionos.deployment_target = '1.0'"
51
46
 
52
- # Use sed to replace the s.platforms = {...} block
53
- # This handles multiline replacement
54
- # Note: We use hardcoded values because min_ios_version_supported is only available
55
- # in React Native's Podfile context, not when CocoaPods validates the podspec directly
56
47
  sed -i.bak '/s\.platforms.*=.*{/,/}/c\
57
48
  s.ios.deployment_target = '"'"'15.8'"'"'\
58
49
  s.macos.deployment_target = '"'"'13.0'"'"'\
59
50
  s.tvos.deployment_target = '"'"'13.4'"'"'\
60
51
  s.visionos.deployment_target = '"'"'1.0'"'"'' "$PODSPEC_PATH"
61
52
 
62
- # Remove backup file
63
53
  rm -f "${PODSPEC_PATH}.bak"
64
54
 
65
- echo "$SCRIPT_NAME ✓ Patched NitroModules.podspec deployment targets"
55
+ echo "$SCRIPT_NAME ✓ Patched NitroModules.podspec platforms definition"
package/src/index.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { NitroModules } from "react-native-nitro-modules";
2
2
  import type { Adapter } from "./specs/Adapter.nitro";
3
+ import type { Peripheral, BluetoothAddressType } from "./specs/Peripheral.nitro";
3
4
 
5
+ export type { Adapter, Peripheral, BluetoothAddressType };
4
6
 
5
- export const HybridAdapter = NitroModules.createHybridObject<Adapter>("Adapter");
7
+ export const HybridAdapter = NitroModules.createHybridObject<Adapter>("Adapter");
8
+ export const HybridPeripheral = NitroModules.createHybridObject<Peripheral>("Peripheral");
@@ -1,9 +1,96 @@
1
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[]
2
+ import { type Peripheral } from './Peripheral.nitro'
3
+
4
+ /**
5
+ * Wraps SimpleBLE::Adapter
6
+ */
7
+ export interface Adapter
8
+ extends HybridObject<{
9
+ ios: 'c++'
10
+ android: 'c++'
11
+ }> {
12
+ /**
13
+ * Check if Bluetooth is enabled on the system.
14
+ */
8
15
  bluetooth_enabled(): boolean
9
- }
16
+
17
+ /**
18
+ * Retrieve a list of all available Bluetooth adapters.
19
+ */
20
+ get_adapters(): Adapter[]
21
+
22
+ /**
23
+ * Check if the adapter is initialized (has a valid internal handle).
24
+ */
25
+ initialized(): boolean
26
+
27
+ /**
28
+ * Human-readable identifier for the adapter.
29
+ */
30
+ identifier(): string
31
+
32
+ /**
33
+ * Bluetooth address of the adapter (MAC on Android/Linux, identifier on IOS/Macos).
34
+ */
35
+ address(): string
36
+
37
+ /**
38
+ * Check if the adapter is currently powered on.
39
+ */
40
+ is_powered(): boolean
41
+
42
+ /**
43
+ * Start scanning for peripherals.
44
+ */
45
+ scan_start(): void
46
+
47
+ /**
48
+ * Stop scanning for peripherals.
49
+ */
50
+ scan_stop(): void
51
+
52
+ /**
53
+ * Scan for peripherals for a specified duration (blocking).
54
+ * @param timeout_ms Duration in milliseconds.
55
+ */
56
+ scan_for(timeout_ms: number): void
57
+
58
+ /**
59
+ * Check if a scan is currently in progress.
60
+ */
61
+ scan_is_active(): boolean
62
+
63
+ /**
64
+ * Get the list of peripherals discovered during the last scan.
65
+ */
66
+ scan_get_results(): Peripheral[]
67
+
68
+ /**
69
+ * Set callback to be invoked when scanning starts.
70
+ */
71
+ set_callback_on_scan_start(callback: () => void): void
72
+
73
+ /**
74
+ * Set callback to be invoked when scanning stops.
75
+ */
76
+ set_callback_on_scan_stop(callback: () => void): void
77
+
78
+ /**
79
+ * Set callback to be invoked when a known peripheral's advertisement is updated.
80
+ */
81
+ set_callback_on_scan_updated(callback: (peripheral: Peripheral) => void): void
82
+
83
+ /**
84
+ * Set callback to be invoked when a new peripheral is discovered.
85
+ */
86
+ set_callback_on_scan_found(callback: (peripheral: Peripheral) => void): void
87
+
88
+ /**
89
+ * Retrieve a list of all paired peripherals.
90
+ * - Android: Supported (uses BluetoothAdapter.getBondedDevices())
91
+ * - iOS: Not supported - CoreBluetooth does not expose a direct API to list paired devices.
92
+ * Pairing is handled at the OS level, and CoreBluetooth only exposes devices discovered via scanning
93
+ * or those you've connected to.
94
+ */
95
+ get_paired_peripherals(): Peripheral[]
96
+ }
@@ -0,0 +1,94 @@
1
+ import { type HybridObject } from 'react-native-nitro-modules'
2
+
3
+ /**
4
+ * Bluetooth address type enumeration.
5
+ * Maps to SimpleBLE::BluetoothAddressType
6
+ */
7
+ export type BluetoothAddressType = 'public' | 'random' | 'unspecified'
8
+
9
+ /**
10
+ * Minimal wrapper for SimpleBLE::Peripheral.
11
+ * Exposes core properties and connection methods without
12
+ * introducing Service/ByteArray types.
13
+ */
14
+ export interface Peripheral
15
+ extends HybridObject<{
16
+ ios: 'c++'
17
+ android: 'c++'
18
+ }> {
19
+ /**
20
+ * Check if the peripheral is initialized (has a valid internal handle).
21
+ */
22
+ initialized(): boolean
23
+
24
+ /**
25
+ * Human- able identifier (device name or fallback).
26
+ */
27
+ identifier(): string
28
+
29
+ /**
30
+ * Bluetooth address (MAC on Android, UUID on IOS/Macos).
31
+ */
32
+ address(): string
33
+
34
+ /**
35
+ * Address type (public, random, or unspecified).
36
+ */
37
+ address_type(): BluetoothAddressType
38
+
39
+ /**
40
+ * Received Signal Strength Indicator in dBm.
41
+ */
42
+ rssi(): number
43
+
44
+ /**
45
+ * Advertised transmit power in dBm.
46
+ * Returns -32768 if not advertised.
47
+ */
48
+ tx_power(): number
49
+
50
+ /**
51
+ * Maximum Transmission Unit size.
52
+ */
53
+ mtu(): number
54
+
55
+ /**
56
+ * Initiate a connection to the peripheral.
57
+ */
58
+ connect(): void
59
+
60
+ /**
61
+ * Disconnect from the peripheral.
62
+ */
63
+ disconnect(): void
64
+
65
+ /**
66
+ * Check if the peripheral is currently connected.
67
+ */
68
+ is_connected(): boolean
69
+
70
+ /**
71
+ * Check if the peripheral is connectable.
72
+ */
73
+ is_connectable(): boolean
74
+
75
+ /**
76
+ * Check if the peripheral is paired with the system.
77
+ */
78
+ is_paired(): boolean
79
+
80
+ /**
81
+ * Remove the pairing/bond with the peripheral.
82
+ */
83
+ unpair(): void
84
+
85
+ /**
86
+ * Set callback to be invoked when a connection is established.
87
+ */
88
+ set_callback_on_connected(callback: () => void): void
89
+
90
+ /**
91
+ * Set callback to be invoked when the peripheral disconnects.
92
+ */
93
+ set_callback_on_disconnected(callback: () => void): void
94
+ }