munim-bluetooth 0.3.26 → 0.4.0

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 +16 -0
  2. package/README.md +476 -74
  3. package/android/gradle.properties +2 -2
  4. package/android/src/main/AndroidManifest.xml +3 -1
  5. package/android/src/main/cpp/cpp-adapter.cpp +4 -1
  6. package/android/src/main/java/com/munimbluetooth/BluetoothPermissionUtils.kt +40 -0
  7. package/android/src/main/java/com/munimbluetooth/HybridMunimBluetooth.kt +2116 -217
  8. package/android/src/main/java/com/munimbluetooth/MunimBluetoothBackgroundService.kt +591 -56
  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 +22 -11
  115. package/src/index.ts +416 -31
  116. package/src/specs/munim-bluetooth.nitro.ts +298 -14
package/app.plugin.js ADDED
@@ -0,0 +1,155 @@
1
+ const { withAndroidManifest, withInfoPlist } = require('@expo/config-plugins');
2
+
3
+ const ANDROID_PERMISSIONS = [
4
+ 'android.permission.BLUETOOTH',
5
+ 'android.permission.BLUETOOTH_ADMIN',
6
+ 'android.permission.BLUETOOTH_ADVERTISE',
7
+ 'android.permission.BLUETOOTH_SCAN',
8
+ 'android.permission.BLUETOOTH_CONNECT',
9
+ 'android.permission.ACCESS_FINE_LOCATION',
10
+ 'android.permission.ACCESS_COARSE_LOCATION',
11
+ 'android.permission.FOREGROUND_SERVICE',
12
+ 'android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE',
13
+ 'android.permission.FOREGROUND_SERVICE_LOCATION',
14
+ 'android.permission.POST_NOTIFICATIONS',
15
+ ];
16
+
17
+ const IOS_BACKGROUND_MODES = ['bluetooth-central', 'bluetooth-peripheral'];
18
+ const DEFAULT_MULTIPEER_SERVICE_TYPES = ['munim-mesh'];
19
+
20
+ function ensureArray(parent, key) {
21
+ if (!parent[key]) {
22
+ parent[key] = [];
23
+ }
24
+ return parent[key];
25
+ }
26
+
27
+ function ensureAndroidPermission(manifest, permission) {
28
+ const permissions = ensureArray(manifest, 'uses-permission');
29
+ const exists = permissions.some(
30
+ (entry) => entry.$?.['android:name'] === permission
31
+ );
32
+
33
+ if (!exists) {
34
+ permissions.push({ $: { 'android:name': permission } });
35
+ }
36
+ }
37
+
38
+ function ensureAndroidFeature(manifest, featureName, required) {
39
+ const features = ensureArray(manifest, 'uses-feature');
40
+ const exists = features.some(
41
+ (entry) => entry.$?.['android:name'] === featureName
42
+ );
43
+
44
+ if (!exists) {
45
+ features.push({
46
+ $: {
47
+ 'android:name': featureName,
48
+ 'android:required': String(required),
49
+ },
50
+ });
51
+ }
52
+ }
53
+
54
+ function ensureBackgroundService(manifest) {
55
+ const application = manifest.application?.[0];
56
+ if (!application) {
57
+ return;
58
+ }
59
+
60
+ const services = ensureArray(application, 'service');
61
+ const serviceName = 'com.munimbluetooth.MunimBluetoothBackgroundService';
62
+ const exists = services.some(
63
+ (entry) => entry.$?.['android:name'] === serviceName
64
+ );
65
+
66
+ if (!exists) {
67
+ services.push({
68
+ $: {
69
+ 'android:name': serviceName,
70
+ 'android:enabled': 'true',
71
+ 'android:exported': 'false',
72
+ 'android:foregroundServiceType': 'connectedDevice|location',
73
+ },
74
+ });
75
+ }
76
+ }
77
+
78
+ function normalizeMultipeerServiceTypes(value) {
79
+ if (value === false) {
80
+ return [];
81
+ }
82
+
83
+ const serviceTypes = Array.isArray(value)
84
+ ? value
85
+ : DEFAULT_MULTIPEER_SERVICE_TYPES;
86
+
87
+ return serviceTypes
88
+ .map((serviceType) => String(serviceType).trim())
89
+ .filter(Boolean)
90
+ .map((serviceType) =>
91
+ serviceType
92
+ .replace(/^_/, '')
93
+ .replace(/\._tcp$/, '')
94
+ .replace(/^_/, '')
95
+ );
96
+ }
97
+
98
+ function bonjourServiceName(serviceType) {
99
+ return `_${serviceType}._tcp`;
100
+ }
101
+
102
+ function withMunimBluetooth(config, options = {}) {
103
+ const bluetoothBackground =
104
+ options.bluetoothBackground === undefined ? true : options.bluetoothBackground;
105
+ const multipeerServiceTypes = normalizeMultipeerServiceTypes(
106
+ options.multipeerServiceTypes
107
+ );
108
+
109
+ config = withInfoPlist(config, (pluginConfig) => {
110
+ const infoPlist = pluginConfig.modResults;
111
+ infoPlist.NSBluetoothAlwaysUsageDescription =
112
+ options.bluetoothAlwaysUsageDescription ??
113
+ infoPlist.NSBluetoothAlwaysUsageDescription ??
114
+ 'This app uses Bluetooth to scan for, connect to, and communicate with nearby devices.';
115
+ infoPlist.NSBluetoothPeripheralUsageDescription =
116
+ options.bluetoothPeripheralUsageDescription ??
117
+ infoPlist.NSBluetoothPeripheralUsageDescription ??
118
+ 'This app uses Bluetooth peripheral mode to advertise services and exchange data with nearby devices.';
119
+
120
+ if (multipeerServiceTypes.length > 0) {
121
+ infoPlist.NSLocalNetworkUsageDescription =
122
+ options.localNetworkUsageDescription ??
123
+ infoPlist.NSLocalNetworkUsageDescription ??
124
+ 'This app uses the local network to discover and communicate with nearby peer devices.';
125
+
126
+ const bonjourServices = new Set(infoPlist.NSBonjourServices ?? []);
127
+ multipeerServiceTypes
128
+ .map(bonjourServiceName)
129
+ .forEach((serviceName) => bonjourServices.add(serviceName));
130
+ infoPlist.NSBonjourServices = Array.from(bonjourServices);
131
+ }
132
+
133
+ if (bluetoothBackground) {
134
+ const modes = new Set(infoPlist.UIBackgroundModes ?? []);
135
+ IOS_BACKGROUND_MODES.forEach((mode) => modes.add(mode));
136
+ infoPlist.UIBackgroundModes = Array.from(modes);
137
+ }
138
+
139
+ return pluginConfig;
140
+ });
141
+
142
+ return withAndroidManifest(config, (pluginConfig) => {
143
+ const manifest = pluginConfig.modResults.manifest;
144
+ ANDROID_PERMISSIONS.forEach((permission) =>
145
+ ensureAndroidPermission(manifest, permission)
146
+ );
147
+ ensureAndroidFeature(manifest, 'android.hardware.bluetooth', false);
148
+ ensureAndroidFeature(manifest, 'android.hardware.bluetooth_le', true);
149
+ ensureBackgroundService(manifest);
150
+ return pluginConfig;
151
+ });
152
+ }
153
+
154
+ module.exports = withMunimBluetooth;
155
+ module.exports.default = withMunimBluetooth;