munim-bluetooth 0.3.24 → 0.3.26
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.
- package/android/src/main/AndroidManifest.xml +10 -0
- package/android/src/main/java/com/munimbluetooth/HybridMunimBluetooth.kt +87 -0
- package/android/src/main/java/com/munimbluetooth/MunimBluetoothBackgroundService.kt +344 -0
- package/ios/HybridMunimBluetooth.swift +265 -22
- package/lib/commonjs/index.js +21 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +19 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +15 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts +25 -3
- package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JBackgroundSessionOptions.hpp +107 -0
- package/nitrogen/generated/android/c++/JHybridMunimBluetoothSpec.cpp +12 -0
- package/nitrogen/generated/android/c++/JHybridMunimBluetoothSpec.hpp +2 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BackgroundSessionOptions.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/HybridMunimBluetoothSpec.kt +28 -20
- package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridMunimBluetoothSpecSwift.hpp +15 -0
- package/nitrogen/generated/ios/swift/BackgroundSessionOptions.swift +154 -0
- package/nitrogen/generated/ios/swift/HybridMunimBluetoothSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridMunimBluetoothSpec_cxx.swift +43 -21
- package/nitrogen/generated/shared/c++/BackgroundSessionOptions.hpp +115 -0
- package/nitrogen/generated/shared/c++/HybridMunimBluetoothSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridMunimBluetoothSpec.hpp +5 -0
- package/package.json +1 -1
- package/src/index.ts +23 -0
- package/src/specs/munim-bluetooth.nitro.ts +28 -3
|
@@ -10,6 +10,9 @@ import CoreBluetooth
|
|
|
10
10
|
import NitroModules
|
|
11
11
|
import React
|
|
12
12
|
|
|
13
|
+
private let centralRestoreIdentifier = "com.munimbluetooth.central"
|
|
14
|
+
private let peripheralRestoreIdentifier = "com.munimbluetooth.peripheral"
|
|
15
|
+
|
|
13
16
|
private final class PeripheralManagerDelegateProxy: NSObject, CBPeripheralManagerDelegate {
|
|
14
17
|
weak var owner: HybridMunimBluetooth?
|
|
15
18
|
|
|
@@ -28,6 +31,10 @@ private final class PeripheralManagerDelegateProxy: NSObject, CBPeripheralManage
|
|
|
28
31
|
func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) {
|
|
29
32
|
owner?.handlePeripheralManagerDidAddService(peripheral, service: service, error: error)
|
|
30
33
|
}
|
|
34
|
+
|
|
35
|
+
func peripheralManager(_ peripheral: CBPeripheralManager, willRestoreState dict: [String : Any]) {
|
|
36
|
+
owner?.handlePeripheralManagerWillRestoreState(peripheral, state: dict)
|
|
37
|
+
}
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
private final class CentralManagerDelegateProxy: NSObject, CBCentralManagerDelegate {
|
|
@@ -40,6 +47,10 @@ private final class CentralManagerDelegateProxy: NSObject, CBCentralManagerDeleg
|
|
|
40
47
|
func centralManagerDidUpdateState(_ central: CBCentralManager) {
|
|
41
48
|
owner?.handleCentralManagerDidUpdateState(central)
|
|
42
49
|
}
|
|
50
|
+
|
|
51
|
+
func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) {
|
|
52
|
+
owner?.handleCentralManagerWillRestoreState(central, state: dict)
|
|
53
|
+
}
|
|
43
54
|
|
|
44
55
|
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String: Any], rssi RSSI: NSNumber) {
|
|
45
56
|
owner?.handleCentralManagerDidDiscover(central, peripheral: peripheral, advertisementData: advertisementData, rssi: RSSI)
|
|
@@ -97,16 +108,34 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
97
108
|
private var discoveredPeripherals: [String: CBPeripheral] = [:]
|
|
98
109
|
private var connectedPeripherals: [String: CBPeripheral] = [:]
|
|
99
110
|
private var peripheralCharacteristics: [String: [CBCharacteristic]] = [:]
|
|
111
|
+
private var pendingConnectionPromises: [String: Promise<Void>] = [:]
|
|
112
|
+
private var pendingServiceDiscoveryPromises: [String: Promise<[GATTService]>] = [:]
|
|
113
|
+
private var pendingCharacteristicDiscoveryCounts: [String: Int] = [:]
|
|
114
|
+
private var pendingReadPromises: [String: Promise<CharacteristicValue>] = [:]
|
|
115
|
+
private var pendingRSSIPromises: [String: Promise<Double>] = [:]
|
|
100
116
|
private var scanOptions: ScanOptions?
|
|
101
117
|
private var isScanning = false
|
|
118
|
+
private var isBackgroundSessionActive = false
|
|
102
119
|
private lazy var peripheralManagerDelegateProxy = PeripheralManagerDelegateProxy(owner: self)
|
|
103
120
|
private lazy var centralManagerDelegateProxy = CentralManagerDelegateProxy(owner: self)
|
|
104
121
|
private lazy var peripheralDelegateProxy = PeripheralDelegateProxy(owner: self)
|
|
105
122
|
|
|
106
123
|
override init() {
|
|
107
124
|
super.init()
|
|
108
|
-
peripheralManager = CBPeripheralManager(
|
|
109
|
-
|
|
125
|
+
peripheralManager = CBPeripheralManager(
|
|
126
|
+
delegate: peripheralManagerDelegateProxy,
|
|
127
|
+
queue: nil,
|
|
128
|
+
options: [
|
|
129
|
+
CBPeripheralManagerOptionRestoreIdentifierKey: peripheralRestoreIdentifier
|
|
130
|
+
]
|
|
131
|
+
)
|
|
132
|
+
centralManager = CBCentralManager(
|
|
133
|
+
delegate: centralManagerDelegateProxy,
|
|
134
|
+
queue: nil,
|
|
135
|
+
options: [
|
|
136
|
+
CBCentralManagerOptionRestoreIdentifierKey: centralRestoreIdentifier
|
|
137
|
+
]
|
|
138
|
+
)
|
|
110
139
|
}
|
|
111
140
|
|
|
112
141
|
// MARK: - Event Emission
|
|
@@ -366,8 +395,12 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
366
395
|
if let options = options {
|
|
367
396
|
scanOptions[CBCentralManagerScanOptionAllowDuplicatesKey] = options.allowDuplicates ?? false
|
|
368
397
|
}
|
|
369
|
-
|
|
370
|
-
|
|
398
|
+
|
|
399
|
+
let serviceUUIDs = options?.serviceUUIDs?.map { CBUUID(string: $0) }
|
|
400
|
+
centralManager.scanForPeripherals(
|
|
401
|
+
withServices: serviceUUIDs?.isEmpty == false ? serviceUUIDs : nil,
|
|
402
|
+
options: scanOptions as [String : Any]
|
|
403
|
+
)
|
|
371
404
|
}
|
|
372
405
|
|
|
373
406
|
func stopScan() throws {
|
|
@@ -377,14 +410,19 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
377
410
|
|
|
378
411
|
func connect(deviceId: String) throws -> Promise<Void> {
|
|
379
412
|
let promise = Promise<Void>()
|
|
413
|
+
if connectedPeripherals[deviceId] != nil {
|
|
414
|
+
promise.resolve(withResult: ())
|
|
415
|
+
return promise
|
|
416
|
+
}
|
|
417
|
+
|
|
380
418
|
guard let peripheral = self.discoveredPeripherals[deviceId] else {
|
|
381
419
|
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not found"]))
|
|
382
420
|
return promise
|
|
383
421
|
}
|
|
384
|
-
|
|
422
|
+
|
|
423
|
+
pendingConnectionPromises[deviceId] = promise
|
|
424
|
+
peripheral.delegate = peripheralDelegateProxy
|
|
385
425
|
self.centralManager?.connect(peripheral, options: nil)
|
|
386
|
-
self.connectedPeripherals[deviceId] = peripheral
|
|
387
|
-
promise.resolve(withResult: ())
|
|
388
426
|
return promise
|
|
389
427
|
}
|
|
390
428
|
|
|
@@ -392,6 +430,7 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
392
430
|
guard let peripheral = connectedPeripherals[deviceId] else { return }
|
|
393
431
|
centralManager?.cancelPeripheralConnection(peripheral)
|
|
394
432
|
connectedPeripherals.removeValue(forKey: deviceId)
|
|
433
|
+
rejectPendingOperations(for: deviceId, error: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Disconnected from \(deviceId)"]))
|
|
395
434
|
}
|
|
396
435
|
|
|
397
436
|
func discoverServices(deviceId: String) throws -> Promise<[GATTService]> {
|
|
@@ -400,15 +439,37 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
400
439
|
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not connected"]))
|
|
401
440
|
return promise
|
|
402
441
|
}
|
|
403
|
-
|
|
442
|
+
|
|
443
|
+
if let services = peripheral.services,
|
|
444
|
+
services.allSatisfy({ $0.characteristics != nil }) {
|
|
445
|
+
promise.resolve(withResult: buildGATTServices(from: services))
|
|
446
|
+
return promise
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
pendingServiceDiscoveryPromises[deviceId] = promise
|
|
404
450
|
peripheral.discoverServices(nil)
|
|
405
|
-
promise.resolve(withResult: [])
|
|
406
451
|
return promise
|
|
407
452
|
}
|
|
408
453
|
|
|
409
454
|
func readCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String) throws -> Promise<CharacteristicValue> {
|
|
410
455
|
let promise = Promise<CharacteristicValue>()
|
|
411
|
-
|
|
456
|
+
|
|
457
|
+
guard let peripheral = connectedPeripherals[deviceId] else {
|
|
458
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not connected"]))
|
|
459
|
+
return promise
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
guard let characteristic = findCharacteristic(
|
|
463
|
+
deviceId: deviceId,
|
|
464
|
+
serviceUUID: serviceUUID,
|
|
465
|
+
characteristicUUID: characteristicUUID
|
|
466
|
+
) else {
|
|
467
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Characteristic not found"]))
|
|
468
|
+
return promise
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
pendingReadPromises[characteristicKey(deviceId: deviceId, serviceUUID: serviceUUID, characteristicUUID: characteristicUUID)] = promise
|
|
472
|
+
peripheral.readValue(for: characteristic)
|
|
412
473
|
return promise
|
|
413
474
|
}
|
|
414
475
|
|
|
@@ -438,11 +499,37 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
438
499
|
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not connected"]))
|
|
439
500
|
return promise
|
|
440
501
|
}
|
|
441
|
-
|
|
502
|
+
|
|
503
|
+
pendingRSSIPromises[deviceId] = promise
|
|
442
504
|
peripheral.readRSSI()
|
|
443
|
-
promise.resolve(withResult: 0)
|
|
444
505
|
return promise
|
|
445
506
|
}
|
|
507
|
+
|
|
508
|
+
func startBackgroundSession(options: BackgroundSessionOptions) throws {
|
|
509
|
+
isBackgroundSessionActive = true
|
|
510
|
+
|
|
511
|
+
let advertisingOptions = AdvertisingOptions(
|
|
512
|
+
serviceUUIDs: options.serviceUUIDs,
|
|
513
|
+
localName: options.localName,
|
|
514
|
+
manufacturerData: nil,
|
|
515
|
+
advertisingData: nil
|
|
516
|
+
)
|
|
517
|
+
|
|
518
|
+
try startAdvertising(options: advertisingOptions)
|
|
519
|
+
try startScan(
|
|
520
|
+
options: ScanOptions(
|
|
521
|
+
serviceUUIDs: options.serviceUUIDs,
|
|
522
|
+
allowDuplicates: options.allowDuplicates,
|
|
523
|
+
scanMode: options.scanMode
|
|
524
|
+
)
|
|
525
|
+
)
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
func stopBackgroundSession() throws {
|
|
529
|
+
isBackgroundSessionActive = false
|
|
530
|
+
try stopScan()
|
|
531
|
+
try stopAdvertising()
|
|
532
|
+
}
|
|
446
533
|
|
|
447
534
|
func addListener(eventName: String) throws {
|
|
448
535
|
// Event management
|
|
@@ -486,11 +573,83 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
486
573
|
}
|
|
487
574
|
}
|
|
488
575
|
|
|
576
|
+
private func characteristicKey(deviceId: String, serviceUUID: String, characteristicUUID: String) -> String {
|
|
577
|
+
"\(deviceId.lowercased())|\(serviceUUID.lowercased())|\(characteristicUUID.lowercased())"
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
private func buildGATTServices(from services: [CBService]) -> [GATTService] {
|
|
581
|
+
services.map { service in
|
|
582
|
+
GATTService(
|
|
583
|
+
uuid: service.uuid.uuidString,
|
|
584
|
+
characteristics: (service.characteristics ?? []).map { characteristic in
|
|
585
|
+
GATTCharacteristic(
|
|
586
|
+
uuid: characteristic.uuid.uuidString,
|
|
587
|
+
properties: mapProperties(characteristic.properties),
|
|
588
|
+
value: characteristic.value?.map { String(format: "%02x", $0) }.joined()
|
|
589
|
+
)
|
|
590
|
+
}
|
|
591
|
+
)
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
private func mapProperties(_ properties: CBCharacteristicProperties) -> [String] {
|
|
596
|
+
var result: [String] = []
|
|
597
|
+
if properties.contains(.read) {
|
|
598
|
+
result.append("read")
|
|
599
|
+
}
|
|
600
|
+
if properties.contains(.write) {
|
|
601
|
+
result.append("write")
|
|
602
|
+
}
|
|
603
|
+
if properties.contains(.writeWithoutResponse) {
|
|
604
|
+
result.append("writeWithoutResponse")
|
|
605
|
+
}
|
|
606
|
+
if properties.contains(.notify) {
|
|
607
|
+
result.append("notify")
|
|
608
|
+
}
|
|
609
|
+
if properties.contains(.indicate) {
|
|
610
|
+
result.append("indicate")
|
|
611
|
+
}
|
|
612
|
+
return result
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
private func findCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String) -> CBCharacteristic? {
|
|
616
|
+
guard let peripheral = connectedPeripherals[deviceId],
|
|
617
|
+
let services = peripheral.services else {
|
|
618
|
+
return nil
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
let matchingService = services.first {
|
|
622
|
+
$0.uuid.uuidString.caseInsensitiveCompare(serviceUUID) == .orderedSame
|
|
623
|
+
}
|
|
624
|
+
let matchingCharacteristic = matchingService?.characteristics?.first {
|
|
625
|
+
$0.uuid.uuidString.caseInsensitiveCompare(characteristicUUID) == .orderedSame
|
|
626
|
+
}
|
|
627
|
+
return matchingCharacteristic
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
private func rejectPendingOperations(for deviceId: String, error: Error) {
|
|
631
|
+
pendingConnectionPromises.removeValue(forKey: deviceId)?.reject(withError: error)
|
|
632
|
+
pendingServiceDiscoveryPromises.removeValue(forKey: deviceId)?.reject(withError: error)
|
|
633
|
+
pendingCharacteristicDiscoveryCounts.removeValue(forKey: deviceId)
|
|
634
|
+
pendingRSSIPromises.removeValue(forKey: deviceId)?.reject(withError: error)
|
|
635
|
+
|
|
636
|
+
let prefix = "\(deviceId.lowercased())|"
|
|
637
|
+
for key in pendingReadPromises.keys where key.hasPrefix(prefix) {
|
|
638
|
+
pendingReadPromises.removeValue(forKey: key)?.reject(withError: error)
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
489
642
|
// MARK: - CoreBluetooth Delegate Forwarding
|
|
490
643
|
|
|
491
644
|
func handlePeripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
|
|
492
645
|
// Handle state updates
|
|
493
646
|
}
|
|
647
|
+
|
|
648
|
+
func handlePeripheralManagerWillRestoreState(_ peripheral: CBPeripheralManager, state: [String: Any]) {
|
|
649
|
+
if peripheral.isAdvertising {
|
|
650
|
+
isBackgroundSessionActive = true
|
|
651
|
+
}
|
|
652
|
+
}
|
|
494
653
|
|
|
495
654
|
func handlePeripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) {
|
|
496
655
|
if let error = error {
|
|
@@ -512,6 +671,18 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
512
671
|
let state = central.state
|
|
513
672
|
NSLog("Bluetooth event")
|
|
514
673
|
}
|
|
674
|
+
|
|
675
|
+
func handleCentralManagerWillRestoreState(_ central: CBCentralManager, state: [String: Any]) {
|
|
676
|
+
if let scanServices = state[CBCentralManagerRestoredStateScanServicesKey] as? [CBUUID] {
|
|
677
|
+
scanOptions = ScanOptions(
|
|
678
|
+
serviceUUIDs: scanServices.map { $0.uuidString },
|
|
679
|
+
allowDuplicates: nil,
|
|
680
|
+
scanMode: nil
|
|
681
|
+
)
|
|
682
|
+
isScanning = true
|
|
683
|
+
isBackgroundSessionActive = true
|
|
684
|
+
}
|
|
685
|
+
}
|
|
515
686
|
|
|
516
687
|
func handleCentralManagerDidDiscover(_ central: CBCentralManager, peripheral: CBPeripheral, advertisementData: [String: Any], rssi RSSI: NSNumber) {
|
|
517
688
|
let deviceId = peripheral.identifier.uuidString
|
|
@@ -527,6 +698,7 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
527
698
|
let deviceId = peripheral.identifier.uuidString
|
|
528
699
|
connectedPeripherals[deviceId] = peripheral
|
|
529
700
|
peripheral.delegate = peripheralDelegateProxy
|
|
701
|
+
pendingConnectionPromises.removeValue(forKey: deviceId)?.resolve(withResult: ())
|
|
530
702
|
|
|
531
703
|
NSLog("Bluetooth event")
|
|
532
704
|
}
|
|
@@ -535,20 +707,45 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
535
707
|
let deviceId = peripheral.identifier.uuidString
|
|
536
708
|
connectedPeripherals.removeValue(forKey: deviceId)
|
|
537
709
|
peripheralCharacteristics.removeValue(forKey: deviceId)
|
|
710
|
+
rejectPendingOperations(
|
|
711
|
+
for: deviceId,
|
|
712
|
+
error: error ?? NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Disconnected from \(deviceId)"])
|
|
713
|
+
)
|
|
538
714
|
|
|
539
715
|
NSLog("Bluetooth event")
|
|
540
716
|
}
|
|
541
717
|
|
|
542
718
|
func handleCentralManagerDidFailToConnect(_ central: CBCentralManager, peripheral: CBPeripheral, error: Error?) {
|
|
543
719
|
let deviceId = peripheral.identifier.uuidString
|
|
720
|
+
rejectPendingOperations(
|
|
721
|
+
for: deviceId,
|
|
722
|
+
error: error ?? NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Failed to connect to \(deviceId)"])
|
|
723
|
+
)
|
|
544
724
|
NSLog("Bluetooth: connectionFailed")
|
|
545
725
|
}
|
|
546
726
|
|
|
547
727
|
func handlePeripheralDidDiscoverServices(_ peripheral: CBPeripheral, error: Error?) {
|
|
548
728
|
let deviceId = peripheral.identifier.uuidString
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
729
|
+
|
|
730
|
+
if let error = error {
|
|
731
|
+
pendingServiceDiscoveryPromises.removeValue(forKey: deviceId)?.reject(withError: error)
|
|
732
|
+
pendingCharacteristicDiscoveryCounts.removeValue(forKey: deviceId)
|
|
733
|
+
return
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
guard let services = peripheral.services else {
|
|
737
|
+
pendingServiceDiscoveryPromises.removeValue(forKey: deviceId)?.resolve(withResult: [])
|
|
738
|
+
pendingCharacteristicDiscoveryCounts.removeValue(forKey: deviceId)
|
|
739
|
+
return
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
if services.isEmpty {
|
|
743
|
+
pendingServiceDiscoveryPromises.removeValue(forKey: deviceId)?.resolve(withResult: [])
|
|
744
|
+
pendingCharacteristicDiscoveryCounts.removeValue(forKey: deviceId)
|
|
745
|
+
return
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
pendingCharacteristicDiscoveryCounts[deviceId] = services.count
|
|
552
749
|
for service in services {
|
|
553
750
|
peripheral.discoverCharacteristics(nil, for: service)
|
|
554
751
|
}
|
|
@@ -558,23 +755,66 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
558
755
|
|
|
559
756
|
func handlePeripheralDidDiscoverCharacteristics(_ peripheral: CBPeripheral, service: CBService, error: Error?) {
|
|
560
757
|
let deviceId = peripheral.identifier.uuidString
|
|
561
|
-
|
|
758
|
+
|
|
759
|
+
if let error = error {
|
|
760
|
+
pendingServiceDiscoveryPromises.removeValue(forKey: deviceId)?.reject(withError: error)
|
|
761
|
+
pendingCharacteristicDiscoveryCounts.removeValue(forKey: deviceId)
|
|
762
|
+
return
|
|
763
|
+
}
|
|
764
|
+
|
|
562
765
|
guard let characteristics = service.characteristics else { return }
|
|
563
|
-
|
|
766
|
+
|
|
564
767
|
if peripheralCharacteristics[deviceId] == nil {
|
|
565
768
|
peripheralCharacteristics[deviceId] = []
|
|
566
769
|
}
|
|
567
770
|
peripheralCharacteristics[deviceId]?.append(contentsOf: characteristics)
|
|
771
|
+
|
|
772
|
+
if let remaining = pendingCharacteristicDiscoveryCounts[deviceId] {
|
|
773
|
+
let nextRemaining = max(remaining - 1, 0)
|
|
774
|
+
if nextRemaining == 0 {
|
|
775
|
+
pendingCharacteristicDiscoveryCounts.removeValue(forKey: deviceId)
|
|
776
|
+
pendingServiceDiscoveryPromises.removeValue(forKey: deviceId)?.resolve(
|
|
777
|
+
withResult: buildGATTServices(from: peripheral.services ?? [])
|
|
778
|
+
)
|
|
779
|
+
} else {
|
|
780
|
+
pendingCharacteristicDiscoveryCounts[deviceId] = nextRemaining
|
|
781
|
+
}
|
|
782
|
+
}
|
|
568
783
|
|
|
569
784
|
NSLog("Bluetooth event")
|
|
570
785
|
}
|
|
571
786
|
|
|
572
787
|
func handlePeripheralDidUpdateValue(_ peripheral: CBPeripheral, characteristic: CBCharacteristic, error: Error?) {
|
|
573
788
|
let deviceId = peripheral.identifier.uuidString
|
|
574
|
-
|
|
789
|
+
let serviceUUID = characteristic.service?.uuid.uuidString ?? ""
|
|
790
|
+
|
|
791
|
+
if let error = error {
|
|
792
|
+
pendingReadPromises.removeValue(
|
|
793
|
+
forKey: characteristicKey(
|
|
794
|
+
deviceId: deviceId,
|
|
795
|
+
serviceUUID: serviceUUID,
|
|
796
|
+
characteristicUUID: characteristic.uuid.uuidString
|
|
797
|
+
)
|
|
798
|
+
)?.reject(withError: error)
|
|
799
|
+
return
|
|
800
|
+
}
|
|
801
|
+
|
|
575
802
|
guard let data = characteristic.value else { return }
|
|
576
|
-
|
|
803
|
+
|
|
577
804
|
let hexString = data.map { String(format: "%02x", $0) }.joined()
|
|
805
|
+
pendingReadPromises.removeValue(
|
|
806
|
+
forKey: characteristicKey(
|
|
807
|
+
deviceId: deviceId,
|
|
808
|
+
serviceUUID: serviceUUID,
|
|
809
|
+
characteristicUUID: characteristic.uuid.uuidString
|
|
810
|
+
)
|
|
811
|
+
)?.resolve(
|
|
812
|
+
withResult: CharacteristicValue(
|
|
813
|
+
value: hexString,
|
|
814
|
+
serviceUUID: serviceUUID,
|
|
815
|
+
characteristicUUID: characteristic.uuid.uuidString
|
|
816
|
+
)
|
|
817
|
+
)
|
|
578
818
|
|
|
579
819
|
NSLog("Bluetooth: characteristicValueChanged")
|
|
580
820
|
}
|
|
@@ -591,11 +831,14 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
591
831
|
|
|
592
832
|
func handlePeripheralDidReadRSSI(_ peripheral: CBPeripheral, rssi RSSI: NSNumber, error: Error?) {
|
|
593
833
|
let deviceId = peripheral.identifier.uuidString
|
|
594
|
-
|
|
834
|
+
|
|
595
835
|
if let error = error {
|
|
836
|
+
pendingRSSIPromises.removeValue(forKey: deviceId)?.reject(withError: error)
|
|
596
837
|
NSLog("Bluetooth event")
|
|
597
|
-
|
|
598
|
-
NSLog("Bluetooth event")
|
|
838
|
+
return
|
|
599
839
|
}
|
|
840
|
+
|
|
841
|
+
pendingRSSIPromises.removeValue(forKey: deviceId)?.resolve(withResult: RSSI.doubleValue)
|
|
842
|
+
NSLog("Bluetooth event")
|
|
600
843
|
}
|
|
601
844
|
}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -19,8 +19,10 @@ exports.removeListeners = removeListeners;
|
|
|
19
19
|
exports.requestBluetoothPermission = requestBluetoothPermission;
|
|
20
20
|
exports.setServices = setServices;
|
|
21
21
|
exports.startAdvertising = startAdvertising;
|
|
22
|
+
exports.startBackgroundSession = startBackgroundSession;
|
|
22
23
|
exports.startScan = startScan;
|
|
23
24
|
exports.stopAdvertising = stopAdvertising;
|
|
25
|
+
exports.stopBackgroundSession = stopBackgroundSession;
|
|
24
26
|
exports.stopScan = stopScan;
|
|
25
27
|
exports.subscribeToCharacteristic = subscribeToCharacteristic;
|
|
26
28
|
exports.unsubscribeFromCharacteristic = unsubscribeFromCharacteristic;
|
|
@@ -228,6 +230,23 @@ function readRSSI(deviceId) {
|
|
|
228
230
|
return MunimBluetooth.readRSSI(deviceId);
|
|
229
231
|
}
|
|
230
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Start a best-effort background BLE session.
|
|
235
|
+
*
|
|
236
|
+
* Android uses a foreground service. iOS relies on the host app's Bluetooth
|
|
237
|
+
* background modes and state restoration.
|
|
238
|
+
*/
|
|
239
|
+
function startBackgroundSession(options) {
|
|
240
|
+
return MunimBluetooth.startBackgroundSession(options);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Stop the active background BLE session.
|
|
245
|
+
*/
|
|
246
|
+
function stopBackgroundSession() {
|
|
247
|
+
return MunimBluetooth.stopBackgroundSession();
|
|
248
|
+
}
|
|
249
|
+
|
|
231
250
|
// ========== Event Management ==========
|
|
232
251
|
|
|
233
252
|
/**
|
|
@@ -302,6 +321,8 @@ var _default = exports.default = {
|
|
|
302
321
|
unsubscribeFromCharacteristic,
|
|
303
322
|
getConnectedDevices,
|
|
304
323
|
readRSSI,
|
|
324
|
+
startBackgroundSession,
|
|
325
|
+
stopBackgroundSession,
|
|
305
326
|
// Events
|
|
306
327
|
addDeviceFoundListener,
|
|
307
328
|
addEventListener,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeNitroModules","require","_reactNative","MunimBluetooth","NitroModules","createHybridObject","nativeEventModule","Platform","OS","NativeModules","MunimBluetoothEventEmitter","console","log","Object","keys","filter","key","includes","eventEmitter","DeviceEventEmitter","NativeEventEmitter","error","warn","startAdvertising","options","updateAdvertisingData","advertisingData","getAdvertisingData","stopAdvertising","setServices","services","isBluetoothEnabled","requestBluetoothPermission","startScan","stopScan","connect","deviceId","disconnect","discoverServices","readCharacteristic","serviceUUID","characteristicUUID","writeCharacteristic","value","writeType","subscribeToCharacteristic","unsubscribeFromCharacteristic","getConnectedDevices","readRSSI","addDeviceFoundListener","callback","subscription","addListener","remove","addEventListener","eventName","removeListeners","count","_default","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","_reactNative","MunimBluetooth","NitroModules","createHybridObject","nativeEventModule","Platform","OS","NativeModules","MunimBluetoothEventEmitter","console","log","Object","keys","filter","key","includes","eventEmitter","DeviceEventEmitter","NativeEventEmitter","error","warn","startAdvertising","options","updateAdvertisingData","advertisingData","getAdvertisingData","stopAdvertising","setServices","services","isBluetoothEnabled","requestBluetoothPermission","startScan","stopScan","connect","deviceId","disconnect","discoverServices","readCharacteristic","serviceUUID","characteristicUUID","writeCharacteristic","value","writeType","subscribeToCharacteristic","unsubscribeFromCharacteristic","getConnectedDevices","readRSSI","startBackgroundSession","stopBackgroundSession","addDeviceFoundListener","callback","subscription","addListener","remove","addEventListener","eventName","removeListeners","count","_default","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAgBA,MAAME,cAAc,GAClBC,qCAAY,CAACC,kBAAkB,CAAqB,gBAAgB,CAAC;;AAEvE;AACA;AACA,MAAMC,iBAAiB,GACrBC,q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;EACzBC,6BAA6B;EAC7BC,mBAAmB;EACnBC,QAAQ;EACRC,sBAAsB;EACtBC,qBAAqB;EACrB;EACAC,sBAAsB;EACtBK,gBAAgB;EAChBF,WAAW;EACXI;AACF,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -202,6 +202,23 @@ export function readRSSI(deviceId) {
|
|
|
202
202
|
return MunimBluetooth.readRSSI(deviceId);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Start a best-effort background BLE session.
|
|
207
|
+
*
|
|
208
|
+
* Android uses a foreground service. iOS relies on the host app's Bluetooth
|
|
209
|
+
* background modes and state restoration.
|
|
210
|
+
*/
|
|
211
|
+
export function startBackgroundSession(options) {
|
|
212
|
+
return MunimBluetooth.startBackgroundSession(options);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Stop the active background BLE session.
|
|
217
|
+
*/
|
|
218
|
+
export function stopBackgroundSession() {
|
|
219
|
+
return MunimBluetooth.stopBackgroundSession();
|
|
220
|
+
}
|
|
221
|
+
|
|
205
222
|
// ========== Event Management ==========
|
|
206
223
|
|
|
207
224
|
/**
|
|
@@ -277,6 +294,8 @@ export default {
|
|
|
277
294
|
unsubscribeFromCharacteristic,
|
|
278
295
|
getConnectedDevices,
|
|
279
296
|
readRSSI,
|
|
297
|
+
startBackgroundSession,
|
|
298
|
+
stopBackgroundSession,
|
|
280
299
|
// Events
|
|
281
300
|
addDeviceFoundListener,
|
|
282
301
|
addEventListener,
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NitroModules","DeviceEventEmitter","NativeEventEmitter","NativeModules","Platform","MunimBluetooth","createHybridObject","nativeEventModule","OS","MunimBluetoothEventEmitter","console","log","Object","keys","filter","key","includes","eventEmitter","error","warn","startAdvertising","options","updateAdvertisingData","advertisingData","getAdvertisingData","stopAdvertising","setServices","services","isBluetoothEnabled","requestBluetoothPermission","startScan","stopScan","connect","deviceId","disconnect","discoverServices","readCharacteristic","serviceUUID","characteristicUUID","writeCharacteristic","value","writeType","subscribeToCharacteristic","unsubscribeFromCharacteristic","getConnectedDevices","readRSSI","addDeviceFoundListener","callback","subscription","addListener","remove","addEventListener","eventName","removeListeners","count"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AACzD,SACEC,kBAAkB,EAClBC,kBAAkB,EAClBC,aAAa,EACbC,QAAQ,QACH,cAAc;
|
|
1
|
+
{"version":3,"names":["NitroModules","DeviceEventEmitter","NativeEventEmitter","NativeModules","Platform","MunimBluetooth","createHybridObject","nativeEventModule","OS","MunimBluetoothEventEmitter","console","log","Object","keys","filter","key","includes","eventEmitter","error","warn","startAdvertising","options","updateAdvertisingData","advertisingData","getAdvertisingData","stopAdvertising","setServices","services","isBluetoothEnabled","requestBluetoothPermission","startScan","stopScan","connect","deviceId","disconnect","discoverServices","readCharacteristic","serviceUUID","characteristicUUID","writeCharacteristic","value","writeType","subscribeToCharacteristic","unsubscribeFromCharacteristic","getConnectedDevices","readRSSI","startBackgroundSession","stopBackgroundSession","addDeviceFoundListener","callback","subscription","addListener","remove","addEventListener","eventName","removeListeners","count"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AACzD,SACEC,kBAAkB,EAClBC,kBAAkB,EAClBC,aAAa,EACbC,QAAQ,QACH,cAAc;AAWrB,MAAMC,cAAc,GAClBL,YAAY,CAACM,kBAAkB,CAAqB,gBAAgB,CAAC;;AAEvE;AACA;AACA,MAAMC,iBAAiB,GACrBH,QAAQ,CAACI,EAAE,KAAK,KAAK,GAAGL,aAAa,CAACM,0BAA0B,GAAG,IAAI;AAEzEC,OAAO,CAACC,GAAG,CACT,iDAAiD,EACjDP,QAAQ,CAACI,EAAE,KAAK,SAAS,GACrB,4BAA4B,GAC5BD,iBAAiB,GACf,OAAO,GACP,WACR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BK,gBAAgB;EAChBF,WAAW;EACXI;AACF,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AdvertisingDataTypes, BLEDevice, ScanOptions, GATTService, CharacteristicValue } from './specs/munim-bluetooth.nitro';
|
|
1
|
+
import type { AdvertisingDataTypes, BLEDevice, BackgroundSessionOptions, ScanOptions, GATTService, CharacteristicValue } from './specs/munim-bluetooth.nitro';
|
|
2
2
|
/**
|
|
3
3
|
* Start advertising as a Bluetooth peripheral with supported advertising data.
|
|
4
4
|
*
|
|
@@ -123,6 +123,17 @@ export declare function getConnectedDevices(): Promise<string[]>;
|
|
|
123
123
|
* @returns Promise resolving to RSSI value in dBm.
|
|
124
124
|
*/
|
|
125
125
|
export declare function readRSSI(deviceId: string): Promise<number>;
|
|
126
|
+
/**
|
|
127
|
+
* Start a best-effort background BLE session.
|
|
128
|
+
*
|
|
129
|
+
* Android uses a foreground service. iOS relies on the host app's Bluetooth
|
|
130
|
+
* background modes and state restoration.
|
|
131
|
+
*/
|
|
132
|
+
export declare function startBackgroundSession(options: BackgroundSessionOptions): void;
|
|
133
|
+
/**
|
|
134
|
+
* Stop the active background BLE session.
|
|
135
|
+
*/
|
|
136
|
+
export declare function stopBackgroundSession(): void;
|
|
126
137
|
/**
|
|
127
138
|
* Add a device found event listener (for scanning).
|
|
128
139
|
*
|
|
@@ -150,7 +161,7 @@ export declare function addListener(eventName: string): void;
|
|
|
150
161
|
* @param count - Number of listeners to remove.
|
|
151
162
|
*/
|
|
152
163
|
export declare function removeListeners(count: number): void;
|
|
153
|
-
export type { AdvertisingDataTypes, BLEDevice, ScanOptions, GATTService, CharacteristicValue, };
|
|
164
|
+
export type { AdvertisingDataTypes, BLEDevice, BackgroundSessionOptions, ScanOptions, GATTService, CharacteristicValue, };
|
|
154
165
|
declare const _default: {
|
|
155
166
|
startAdvertising: typeof startAdvertising;
|
|
156
167
|
stopAdvertising: typeof stopAdvertising;
|
|
@@ -170,6 +181,8 @@ declare const _default: {
|
|
|
170
181
|
unsubscribeFromCharacteristic: typeof unsubscribeFromCharacteristic;
|
|
171
182
|
getConnectedDevices: typeof getConnectedDevices;
|
|
172
183
|
readRSSI: typeof readRSSI;
|
|
184
|
+
startBackgroundSession: typeof startBackgroundSession;
|
|
185
|
+
stopBackgroundSession: typeof stopBackgroundSession;
|
|
173
186
|
addDeviceFoundListener: typeof addDeviceFoundListener;
|
|
174
187
|
addEventListener: typeof addEventListener;
|
|
175
188
|
addListener: typeof addListener;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,WAAW,EACX,mBAAmB,EACpB,MAAM,+BAA+B,CAAA;AAmDtC;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,eAAe,CAAC,EAAE,oBAAoB,CAAA;CACvC,GAAG,IAAI,CAEP;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,eAAe,EAAE,oBAAoB,GACpC,IAAI,CAEN;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAElE;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAEzD;AAID;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAErD;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,IAAI,OAAO,CAAC,OAAO,CAAC,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,CA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