munim-bluetooth 0.3.27 → 0.4.1

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 (116) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +201 -21
  3. package/README.md +480 -75
  4. package/android/gradle.properties +2 -2
  5. package/android/src/main/AndroidManifest.xml +3 -1
  6. package/android/src/main/cpp/cpp-adapter.cpp +4 -1
  7. package/android/src/main/java/com/munimbluetooth/HybridMunimBluetooth.kt +2006 -209
  8. package/android/src/main/java/com/munimbluetooth/MunimBluetoothBackgroundService.kt +561 -53
  9. package/app.plugin.js +155 -0
  10. package/ios/HybridMunimBluetooth.swift +2123 -298
  11. package/ios/MunimBluetoothEventEmitter.swift +68 -8
  12. package/lib/commonjs/index.js +272 -11
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/module/index.js +243 -11
  15. package/lib/module/index.js.map +1 -1
  16. package/lib/typescript/src/index.d.ts +310 -7
  17. package/lib/typescript/src/index.d.ts.map +1 -1
  18. package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts +219 -5
  19. package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts.map +1 -1
  20. package/nitro.json +9 -3
  21. package/nitrogen/generated/android/c++/JAdvertisingDataTypes.hpp +96 -96
  22. package/nitrogen/generated/android/c++/JAdvertisingOptions.hpp +8 -8
  23. package/nitrogen/generated/android/c++/JBackgroundSessionOptions.hpp +8 -8
  24. package/nitrogen/generated/android/c++/JBluetoothCapabilities.hpp +105 -0
  25. package/nitrogen/generated/android/c++/JBluetoothPhy.hpp +61 -0
  26. package/nitrogen/generated/android/c++/JBluetoothPhyOption.hpp +61 -0
  27. package/nitrogen/generated/android/c++/JBondState.hpp +64 -0
  28. package/nitrogen/generated/android/c++/JDescriptorValue.hpp +69 -0
  29. package/nitrogen/generated/android/c++/JExtendedAdvertisingOptions.hpp +131 -0
  30. package/nitrogen/generated/android/c++/JGATTCharacteristic.hpp +35 -11
  31. package/nitrogen/generated/android/c++/JGATTDescriptor.hpp +85 -0
  32. package/nitrogen/generated/android/c++/JGATTService.hpp +33 -9
  33. package/nitrogen/generated/android/c++/JHybridMunimBluetoothSpec.cpp +422 -12
  34. package/nitrogen/generated/android/c++/JHybridMunimBluetoothSpec.hpp +29 -0
  35. package/nitrogen/generated/android/c++/JL2CAPChannel.hpp +66 -0
  36. package/nitrogen/generated/android/c++/JMultipeerDiscoveryInfoEntry.hpp +61 -0
  37. package/nitrogen/generated/android/c++/JMultipeerEncryptionPreference.hpp +61 -0
  38. package/nitrogen/generated/android/c++/JMultipeerPeer.hpp +93 -0
  39. package/nitrogen/generated/android/c++/JMultipeerPeerState.hpp +61 -0
  40. package/nitrogen/generated/android/c++/JMultipeerSessionOptions.hpp +105 -0
  41. package/nitrogen/generated/android/c++/JPhyStatus.hpp +62 -0
  42. package/nitrogen/generated/android/c++/JScanOptions.hpp +8 -8
  43. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/AdvertisingDataTypes.kt +47 -0
  44. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/AdvertisingOptions.kt +19 -0
  45. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BackgroundSessionOptions.kt +27 -0
  46. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BluetoothCapabilities.kt +111 -0
  47. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BluetoothPhy.kt +24 -0
  48. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BluetoothPhyOption.kt +24 -0
  49. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BondState.kt +25 -0
  50. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/CharacteristicValue.kt +17 -0
  51. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/DescriptorValue.kt +66 -0
  52. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/ExtendedAdvertisingOptions.kt +111 -0
  53. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/GATTCharacteristic.kt +25 -3
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/GATTDescriptor.kt +61 -0
  55. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/GATTService.kt +23 -3
  56. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/HybridMunimBluetoothSpec.kt +138 -22
  57. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/L2CAPChannel.kt +61 -0
  58. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MultipeerDiscoveryInfoEntry.kt +56 -0
  59. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MultipeerEncryptionPreference.kt +24 -0
  60. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MultipeerPeer.kt +66 -0
  61. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MultipeerPeerState.kt +24 -0
  62. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MultipeerSessionOptions.kt +81 -0
  63. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/PhyStatus.kt +56 -0
  64. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/ScanOptions.kt +17 -0
  65. package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/ServiceDataEntry.kt +15 -0
  66. package/nitrogen/generated/ios/MunimBluetooth+autolinking.rb +2 -0
  67. package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Bridge.cpp +61 -5
  68. package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Bridge.hpp +494 -49
  69. package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Umbrella.hpp +42 -0
  70. package/nitrogen/generated/ios/c++/HybridMunimBluetoothSpecSwift.hpp +254 -0
  71. package/nitrogen/generated/ios/swift/BluetoothCapabilities.swift +89 -0
  72. package/nitrogen/generated/ios/swift/BluetoothPhy.swift +44 -0
  73. package/nitrogen/generated/ios/swift/BluetoothPhyOption.swift +44 -0
  74. package/nitrogen/generated/ios/swift/BondState.swift +48 -0
  75. package/nitrogen/generated/ios/swift/DescriptorValue.swift +44 -0
  76. package/nitrogen/generated/ios/swift/ExtendedAdvertisingOptions.swift +243 -0
  77. package/nitrogen/generated/ios/swift/Func_void_BluetoothCapabilities.swift +46 -0
  78. package/nitrogen/generated/ios/swift/Func_void_BondState.swift +46 -0
  79. package/nitrogen/generated/ios/swift/Func_void_DescriptorValue.swift +46 -0
  80. package/nitrogen/generated/ios/swift/Func_void_L2CAPChannel.swift +46 -0
  81. package/nitrogen/generated/ios/swift/Func_void_PhyStatus.swift +46 -0
  82. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
  83. package/nitrogen/generated/ios/swift/Func_void_std__vector_MultipeerPeer_.swift +46 -0
  84. package/nitrogen/generated/ios/swift/GATTCharacteristic.swift +25 -1
  85. package/nitrogen/generated/ios/swift/GATTDescriptor.swift +71 -0
  86. package/nitrogen/generated/ios/swift/GATTService.swift +25 -1
  87. package/nitrogen/generated/ios/swift/HybridMunimBluetoothSpec.swift +29 -0
  88. package/nitrogen/generated/ios/swift/HybridMunimBluetoothSpec_cxx.swift +556 -23
  89. package/nitrogen/generated/ios/swift/L2CAPChannel.swift +52 -0
  90. package/nitrogen/generated/ios/swift/MultipeerDiscoveryInfoEntry.swift +34 -0
  91. package/nitrogen/generated/ios/swift/MultipeerEncryptionPreference.swift +44 -0
  92. package/nitrogen/generated/ios/swift/MultipeerPeer.swift +63 -0
  93. package/nitrogen/generated/ios/swift/MultipeerPeerState.swift +44 -0
  94. package/nitrogen/generated/ios/swift/MultipeerSessionOptions.swift +136 -0
  95. package/nitrogen/generated/ios/swift/PhyStatus.swift +34 -0
  96. package/nitrogen/generated/shared/c++/BluetoothCapabilities.hpp +131 -0
  97. package/nitrogen/generated/shared/c++/BluetoothPhy.hpp +80 -0
  98. package/nitrogen/generated/shared/c++/BluetoothPhyOption.hpp +80 -0
  99. package/nitrogen/generated/shared/c++/BondState.hpp +84 -0
  100. package/nitrogen/generated/shared/c++/DescriptorValue.hpp +95 -0
  101. package/nitrogen/generated/shared/c++/ExtendedAdvertisingOptions.hpp +138 -0
  102. package/nitrogen/generated/shared/c++/GATTCharacteristic.hpp +9 -3
  103. package/nitrogen/generated/shared/c++/GATTDescriptor.hpp +93 -0
  104. package/nitrogen/generated/shared/c++/GATTService.hpp +7 -2
  105. package/nitrogen/generated/shared/c++/HybridMunimBluetoothSpec.cpp +29 -0
  106. package/nitrogen/generated/shared/c++/HybridMunimBluetoothSpec.hpp +61 -2
  107. package/nitrogen/generated/shared/c++/L2CAPChannel.hpp +92 -0
  108. package/nitrogen/generated/shared/c++/MultipeerDiscoveryInfoEntry.hpp +87 -0
  109. package/nitrogen/generated/shared/c++/MultipeerEncryptionPreference.hpp +80 -0
  110. package/nitrogen/generated/shared/c++/MultipeerPeer.hpp +102 -0
  111. package/nitrogen/generated/shared/c++/MultipeerPeerState.hpp +80 -0
  112. package/nitrogen/generated/shared/c++/MultipeerSessionOptions.hpp +114 -0
  113. package/nitrogen/generated/shared/c++/PhyStatus.hpp +88 -0
  114. package/package.json +23 -12
  115. package/src/index.ts +416 -31
  116. package/src/specs/munim-bluetooth.nitro.ts +298 -14
package/src/index.ts CHANGED
@@ -10,11 +10,105 @@ import type {
10
10
  AdvertisingDataTypes,
11
11
  BLEDevice,
12
12
  BackgroundSessionOptions,
13
+ MultipeerSessionOptions,
14
+ MultipeerPeer,
15
+ MultipeerDiscoveryInfoEntry,
16
+ MultipeerEncryptionPreference,
17
+ MultipeerPeerState,
13
18
  ScanOptions,
14
19
  GATTService,
20
+ GATTDescriptor,
15
21
  CharacteristicValue,
22
+ DescriptorValue,
23
+ BluetoothCapabilities,
24
+ BluetoothPhy,
25
+ BluetoothPhyOption,
26
+ BondState,
27
+ PhyStatus,
28
+ ExtendedAdvertisingOptions,
29
+ L2CAPChannel,
16
30
  } from './specs/munim-bluetooth.nitro'
17
31
 
32
+ export type BluetoothEventMap = {
33
+ deviceFound: BLEDevice
34
+ onDeviceFound: BLEDevice
35
+ scanResult: BLEDevice
36
+ scanFailed: { errorCode: number; message: string }
37
+ advertisingStarted: Record<string, never>
38
+ advertisingStartFailed: { error?: string; errorCode?: number; message?: string }
39
+ classicDeviceFound: BLEDevice & { bondState?: string }
40
+ classicScanFailed: { message: string }
41
+ classicScanFinished: Record<string, never>
42
+ classicConnected: { deviceId: string }
43
+ classicDisconnected: { deviceId: string }
44
+ classicConnectionReceived: { deviceId: string }
45
+ classicServerStarted: { serviceUUID: string; serviceName: string }
46
+ classicServerStopped: { serviceUUID: string }
47
+ classicDataReceived: { deviceId: string; value: string }
48
+ deviceConnected: { deviceId: string }
49
+ deviceDisconnected: { deviceId: string }
50
+ servicesDiscovered: { deviceId: string; services: GATTService[] }
51
+ characteristicValueChanged: CharacteristicValue & { deviceId: string }
52
+ l2capChannelPublished: { channelId: string; psm: number }
53
+ l2capChannelPublishFailed: { psm?: number; error: string }
54
+ l2capChannelUnpublished: { psm: number; error?: string }
55
+ l2capChannelOpened: { channelId: string; psm: number; deviceId?: string }
56
+ l2capChannelOpenFailed: { deviceId?: string; error: string }
57
+ l2capChannelClosed: { channelId: string; psm?: number; deviceId?: string }
58
+ l2capDataReceived: {
59
+ channelId: string
60
+ psm?: number
61
+ deviceId?: string
62
+ value: string
63
+ }
64
+ peripheralReadRequest: CharacteristicValue & { centralId: string }
65
+ peripheralWriteRequest: CharacteristicValue & { centralId: string }
66
+ peripheralSubscribed: {
67
+ centralId: string
68
+ serviceUUID: string
69
+ characteristicUUID: string
70
+ }
71
+ peripheralUnsubscribed: {
72
+ centralId: string
73
+ serviceUUID: string
74
+ characteristicUUID: string
75
+ }
76
+ rssiUpdated: { deviceId: string; rssi: number }
77
+ backgroundSessionStarted: {
78
+ platform: string
79
+ serviceUUIDs?: string[]
80
+ localName?: string | null
81
+ }
82
+ backgroundSessionStopped: { platform: string }
83
+ backgroundSessionRestored: {
84
+ platform: string
85
+ role?: 'central' | 'peripheral'
86
+ isScanning?: boolean
87
+ isAdvertising?: boolean
88
+ serviceUUIDs?: string[]
89
+ deviceIds?: string[]
90
+ }
91
+ backgroundSessionStartFailed: { platform: string; error: string }
92
+ multipeerStarted: {
93
+ platform: string
94
+ serviceType: string
95
+ peerId: string
96
+ displayName: string
97
+ }
98
+ multipeerStopped: { platform: string }
99
+ multipeerStartFailed: { platform: string; error: string }
100
+ multipeerPeerFound: MultipeerPeer
101
+ multipeerPeerLost: { peerId: string }
102
+ multipeerPeerStateChanged: MultipeerPeer
103
+ multipeerMessageReceived: {
104
+ peerId: string
105
+ displayName: string
106
+ value: string
107
+ }
108
+ }
109
+
110
+ export type BluetoothEventName = keyof BluetoothEventMap
111
+
18
112
  const MunimBluetooth =
19
113
  NitroModules.createHybridObject<MunimBluetoothSpec>('MunimBluetooth')
20
114
 
@@ -23,51 +117,28 @@ const MunimBluetooth =
23
117
  const nativeEventModule =
24
118
  Platform.OS === 'ios' ? NativeModules.MunimBluetoothEventEmitter : null
25
119
 
26
- console.log(
27
- '[munim-bluetooth] Checking for event emitter...',
28
- Platform.OS === 'android'
29
- ? 'USING_DEVICE_EVENT_EMITTER'
30
- : nativeEventModule
31
- ? 'FOUND'
32
- : 'NOT FOUND'
33
- )
34
- console.log(
35
- '[munim-bluetooth] Available NativeModules:',
36
- Object.keys(NativeModules).filter(
37
- (key) => key.includes('Bluetooth') || key.includes('Munim')
38
- )
39
- )
40
-
41
120
  let eventEmitter: Pick<NativeEventEmitter, 'addListener'> | null = null
42
121
 
43
122
  if (Platform.OS === 'android') {
44
123
  eventEmitter = DeviceEventEmitter
45
- console.log('[munim-bluetooth] Using DeviceEventEmitter on Android')
46
124
  } else if (nativeEventModule) {
47
125
  try {
48
126
  eventEmitter = new NativeEventEmitter(nativeEventModule)
49
- console.log('[munim-bluetooth] Event emitter initialized successfully')
50
127
  } catch (error) {
51
128
  console.error(
52
129
  '[munim-bluetooth] Failed to initialize event emitter:',
53
130
  error
54
131
  )
55
132
  }
56
- } else {
57
- console.warn(
58
- '[munim-bluetooth] Event emitter module not found in NativeModules - device discovery events will not work'
59
- )
60
- console.warn(
61
- '[munim-bluetooth] This usually means the native module was not linked properly or needs a rebuild'
62
- )
63
133
  }
64
134
 
65
135
  // ========== Peripheral Features ==========
66
136
 
67
137
  /**
68
- * Start advertising as a Bluetooth peripheral with supported advertising data.
138
+ * Start advertising as a Bluetooth peripheral with platform-aware advertising data.
69
139
  *
70
- * @param options - An object with serviceUUIDs (string[]) and supported advertising data types.
140
+ * @param options - An object with serviceUUIDs (string[]) and advertising data types.
141
+ * iOS only advertises local name and service UUIDs.
71
142
  */
72
143
  export function startAdvertising(options: {
73
144
  serviceUUIDs: string[]
@@ -114,6 +185,24 @@ export function setServices(services: GATTService[]): void {
114
185
  return MunimBluetooth.setServices(services)
115
186
  }
116
187
 
188
+ /**
189
+ * Update a local peripheral characteristic value and optionally notify/indicate
190
+ * subscribed centrals.
191
+ */
192
+ export function updateCharacteristicValue(
193
+ serviceUUID: string,
194
+ characteristicUUID: string,
195
+ value: string,
196
+ notify?: boolean
197
+ ): Promise<void> {
198
+ return MunimBluetooth.updateCharacteristicValue(
199
+ serviceUUID,
200
+ characteristicUUID,
201
+ value,
202
+ notify
203
+ )
204
+ }
205
+
117
206
  // ========== Central/Manager Features ==========
118
207
 
119
208
  /**
@@ -134,6 +223,13 @@ export function requestBluetoothPermission(): Promise<boolean> {
134
223
  return MunimBluetooth.requestBluetoothPermission()
135
224
  }
136
225
 
226
+ /**
227
+ * Return the Bluetooth feature set supported by the current platform/device.
228
+ */
229
+ export function getCapabilities(): Promise<BluetoothCapabilities> {
230
+ return MunimBluetooth.getCapabilities()
231
+ }
232
+
137
233
  /**
138
234
  * Start scanning for BLE devices.
139
235
  *
@@ -199,6 +295,23 @@ export function readCharacteristic(
199
295
  )
200
296
  }
201
297
 
298
+ /**
299
+ * Read a descriptor value from a connected device.
300
+ */
301
+ export function readDescriptor(
302
+ deviceId: string,
303
+ serviceUUID: string,
304
+ characteristicUUID: string,
305
+ descriptorUUID: string
306
+ ): Promise<DescriptorValue> {
307
+ return MunimBluetooth.readDescriptor(
308
+ deviceId,
309
+ serviceUUID,
310
+ characteristicUUID,
311
+ descriptorUUID
312
+ )
313
+ }
314
+
202
315
  /**
203
316
  * Write a value to a characteristic on a connected device.
204
317
  *
@@ -225,6 +338,25 @@ export function writeCharacteristic(
225
338
  )
226
339
  }
227
340
 
341
+ /**
342
+ * Write a descriptor value to a connected device.
343
+ */
344
+ export function writeDescriptor(
345
+ deviceId: string,
346
+ serviceUUID: string,
347
+ characteristicUUID: string,
348
+ descriptorUUID: string,
349
+ value: string
350
+ ): Promise<void> {
351
+ return MunimBluetooth.writeDescriptor(
352
+ deviceId,
353
+ serviceUUID,
354
+ characteristicUUID,
355
+ descriptorUUID,
356
+ value
357
+ )
358
+ }
359
+
228
360
  /**
229
361
  * Subscribe to notifications/indications from a characteristic.
230
362
  *
@@ -282,11 +414,178 @@ export function readRSSI(deviceId: string): Promise<number> {
282
414
  return MunimBluetooth.readRSSI(deviceId)
283
415
  }
284
416
 
417
+ /**
418
+ * Request an ATT MTU. Android supports this directly; iOS rejects with unsupported.
419
+ */
420
+ export function requestMTU(deviceId: string, mtu: number): Promise<number> {
421
+ return MunimBluetooth.requestMTU(deviceId, mtu)
422
+ }
423
+
424
+ /**
425
+ * Set preferred BLE PHY. Android 8+ supports this when hardware allows it.
426
+ */
427
+ export function setPreferredPhy(
428
+ deviceId: string,
429
+ txPhy: BluetoothPhy,
430
+ rxPhy: BluetoothPhy,
431
+ phyOption?: BluetoothPhyOption
432
+ ): Promise<void> {
433
+ return MunimBluetooth.setPreferredPhy(deviceId, txPhy, rxPhy, phyOption)
434
+ }
435
+
436
+ /**
437
+ * Read current BLE PHY. Android 8+ supports this when hardware allows it.
438
+ */
439
+ export function readPhy(deviceId: string): Promise<PhyStatus> {
440
+ return MunimBluetooth.readPhy(deviceId)
441
+ }
442
+
443
+ /**
444
+ * Return current platform bond state for a device.
445
+ */
446
+ export function getBondState(deviceId: string): Promise<BondState> {
447
+ return MunimBluetooth.getBondState(deviceId)
448
+ }
449
+
450
+ /**
451
+ * Start platform pairing/bonding for a device.
452
+ */
453
+ export function createBond(deviceId: string): Promise<BondState> {
454
+ return MunimBluetooth.createBond(deviceId)
455
+ }
456
+
457
+ /**
458
+ * Remove a platform bond where supported.
459
+ */
460
+ export function removeBond(deviceId: string): Promise<BondState> {
461
+ return MunimBluetooth.removeBond(deviceId)
462
+ }
463
+
464
+ /**
465
+ * Start BLE extended advertising where supported.
466
+ */
467
+ export function startExtendedAdvertising(
468
+ options: ExtendedAdvertisingOptions
469
+ ): Promise<string> {
470
+ return MunimBluetooth.startExtendedAdvertising(options)
471
+ }
472
+
473
+ /**
474
+ * Stop a BLE extended advertising set.
475
+ */
476
+ export function stopExtendedAdvertising(advertisingId: string): void {
477
+ return MunimBluetooth.stopExtendedAdvertising(advertisingId)
478
+ }
479
+
480
+ /**
481
+ * Publish a local BLE L2CAP channel where supported.
482
+ */
483
+ export function publishL2CAPChannel(
484
+ encryptionRequired?: boolean
485
+ ): Promise<L2CAPChannel> {
486
+ return MunimBluetooth.publishL2CAPChannel(encryptionRequired)
487
+ }
488
+
489
+ /**
490
+ * Stop a local BLE L2CAP channel.
491
+ */
492
+ export function unpublishL2CAPChannel(psm: number): void {
493
+ return MunimBluetooth.unpublishL2CAPChannel(psm)
494
+ }
495
+
496
+ /**
497
+ * Open an outbound BLE L2CAP channel.
498
+ */
499
+ export function openL2CAPChannel(
500
+ deviceId: string,
501
+ psm: number
502
+ ): Promise<L2CAPChannel> {
503
+ return MunimBluetooth.openL2CAPChannel(deviceId, psm)
504
+ }
505
+
506
+ /**
507
+ * Close an L2CAP channel.
508
+ */
509
+ export function closeL2CAPChannel(channelId: string): void {
510
+ return MunimBluetooth.closeL2CAPChannel(channelId)
511
+ }
512
+
513
+ /**
514
+ * Send hex data over an open L2CAP channel.
515
+ */
516
+ export function sendL2CAPData(
517
+ channelId: string,
518
+ value: string
519
+ ): Promise<void> {
520
+ return MunimBluetooth.sendL2CAPData(channelId, value)
521
+ }
522
+
523
+ /**
524
+ * Start Classic Bluetooth discovery where supported.
525
+ */
526
+ export function startClassicScan(): void {
527
+ return MunimBluetooth.startClassicScan()
528
+ }
529
+
530
+ /**
531
+ * Stop Classic Bluetooth discovery.
532
+ */
533
+ export function stopClassicScan(): void {
534
+ return MunimBluetooth.stopClassicScan()
535
+ }
536
+
537
+ /**
538
+ * Connect to a Classic Bluetooth RFCOMM service where supported.
539
+ */
540
+ export function connectClassic(
541
+ deviceId: string,
542
+ serviceUUID?: string
543
+ ): Promise<void> {
544
+ return MunimBluetooth.connectClassic(deviceId, serviceUUID)
545
+ }
546
+
547
+ /**
548
+ * Listen for incoming Classic Bluetooth RFCOMM connections on Android.
549
+ */
550
+ export function startClassicServer(
551
+ serviceUUID?: string,
552
+ serviceName?: string
553
+ ): Promise<void> {
554
+ return MunimBluetooth.startClassicServer(serviceUUID, serviceName)
555
+ }
556
+
557
+ /**
558
+ * Stop a Classic Bluetooth RFCOMM listener on Android.
559
+ */
560
+ export function stopClassicServer(serviceUUID?: string): void {
561
+ return MunimBluetooth.stopClassicServer(serviceUUID)
562
+ }
563
+
564
+ /**
565
+ * Disconnect a Classic Bluetooth device.
566
+ */
567
+ export function disconnectClassic(deviceId: string): void {
568
+ return MunimBluetooth.disconnectClassic(deviceId)
569
+ }
570
+
571
+ /**
572
+ * Write hex data to a Classic Bluetooth RFCOMM connection.
573
+ */
574
+ export function writeClassic(
575
+ deviceId: string,
576
+ value: string
577
+ ): Promise<void> {
578
+ return MunimBluetooth.writeClassic(deviceId, value)
579
+ }
580
+
285
581
  /**
286
582
  * Start a best-effort background BLE session.
287
583
  *
288
- * Android uses a foreground service. iOS relies on the host app's Bluetooth
289
- * background modes and state restoration.
584
+ * Android uses a foreground service and restores scan/advertising/configured
585
+ * GATT services after normal service process recreation. iOS relies on the host
586
+ * app's Bluetooth background modes and CoreBluetooth state restoration, with
587
+ * terminated-state relaunch still limited by Apple's current relaunch rules.
588
+ * User force-quit/force-stop is controlled by the OS and cannot be bypassed.
290
589
  */
291
590
  export function startBackgroundSession(
292
591
  options: BackgroundSessionOptions
@@ -301,6 +600,49 @@ export function stopBackgroundSession(): void {
301
600
  return MunimBluetooth.stopBackgroundSession()
302
601
  }
303
602
 
603
+ /**
604
+ * Start Apple Multipeer Connectivity transport. This is iOS/iPadOS/macOS/tvOS
605
+ * only; Android cannot join Apple Multipeer sessions.
606
+ */
607
+ export function startMultipeerSession(
608
+ options: MultipeerSessionOptions
609
+ ): void {
610
+ return MunimBluetooth.startMultipeerSession(options)
611
+ }
612
+
613
+ /**
614
+ * Stop the active Apple Multipeer Connectivity session.
615
+ */
616
+ export function stopMultipeerSession(): void {
617
+ return MunimBluetooth.stopMultipeerSession()
618
+ }
619
+
620
+ /**
621
+ * Invite a discovered Multipeer peer by runtime peer id.
622
+ */
623
+ export function inviteMultipeerPeer(peerId: string): void {
624
+ return MunimBluetooth.inviteMultipeerPeer(peerId)
625
+ }
626
+
627
+ /**
628
+ * Return discovered/connected Apple Multipeer peers.
629
+ */
630
+ export function getMultipeerPeers(): Promise<MultipeerPeer[]> {
631
+ return MunimBluetooth.getMultipeerPeers()
632
+ }
633
+
634
+ /**
635
+ * Send hex data over Apple Multipeer Connectivity. Omit peerIds to broadcast
636
+ * to all connected peers.
637
+ */
638
+ export function sendMultipeerMessage(
639
+ value: string,
640
+ peerIds?: string[],
641
+ reliable?: boolean
642
+ ): Promise<void> {
643
+ return MunimBluetooth.sendMultipeerMessage(value, peerIds, reliable)
644
+ }
645
+
304
646
  // ========== Event Management ==========
305
647
 
306
648
  /**
@@ -330,9 +672,9 @@ export function addDeviceFoundListener(
330
672
  * @param callback - The callback to invoke when the event occurs.
331
673
  * @returns A function to remove the listener
332
674
  */
333
- export function addEventListener(
334
- eventName: string,
335
- callback: (data: any) => void
675
+ export function addEventListener<EventName extends BluetoothEventName>(
676
+ eventName: EventName,
677
+ callback: (data: BluetoothEventMap[EventName]) => void
336
678
  ): () => void {
337
679
  if (!eventEmitter) {
338
680
  console.warn(
@@ -369,9 +711,23 @@ export type {
369
711
  AdvertisingDataTypes,
370
712
  BLEDevice,
371
713
  BackgroundSessionOptions,
714
+ MultipeerSessionOptions,
715
+ MultipeerPeer,
716
+ MultipeerDiscoveryInfoEntry,
717
+ MultipeerEncryptionPreference,
718
+ MultipeerPeerState,
372
719
  ScanOptions,
373
720
  GATTService,
721
+ GATTDescriptor,
374
722
  CharacteristicValue,
723
+ DescriptorValue,
724
+ BluetoothCapabilities,
725
+ BluetoothPhy,
726
+ BluetoothPhyOption,
727
+ BondState,
728
+ PhyStatus,
729
+ ExtendedAdvertisingOptions,
730
+ L2CAPChannel,
375
731
  }
376
732
 
377
733
  // Default export for convenience
@@ -382,22 +738,51 @@ export default {
382
738
  updateAdvertisingData,
383
739
  getAdvertisingData,
384
740
  setServices,
741
+ updateCharacteristicValue,
385
742
  // Central
386
743
  isBluetoothEnabled,
387
744
  requestBluetoothPermission,
745
+ getCapabilities,
388
746
  startScan,
389
747
  stopScan,
390
748
  connect,
391
749
  disconnect,
392
750
  discoverServices,
393
751
  readCharacteristic,
752
+ readDescriptor,
394
753
  writeCharacteristic,
754
+ writeDescriptor,
395
755
  subscribeToCharacteristic,
396
756
  unsubscribeFromCharacteristic,
397
757
  getConnectedDevices,
398
758
  readRSSI,
759
+ requestMTU,
760
+ setPreferredPhy,
761
+ readPhy,
762
+ getBondState,
763
+ createBond,
764
+ removeBond,
765
+ startExtendedAdvertising,
766
+ stopExtendedAdvertising,
767
+ publishL2CAPChannel,
768
+ unpublishL2CAPChannel,
769
+ openL2CAPChannel,
770
+ closeL2CAPChannel,
771
+ sendL2CAPData,
772
+ startClassicScan,
773
+ stopClassicScan,
774
+ connectClassic,
775
+ startClassicServer,
776
+ stopClassicServer,
777
+ disconnectClassic,
778
+ writeClassic,
399
779
  startBackgroundSession,
400
780
  stopBackgroundSession,
781
+ startMultipeerSession,
782
+ stopMultipeerSession,
783
+ inviteMultipeerPeer,
784
+ getMultipeerPeers,
785
+ sendMultipeerMessage,
401
786
  // Events
402
787
  addDeviceFoundListener,
403
788
  addEventListener,