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.
- package/CHANGELOG.md +27 -0
- package/LICENSE +201 -21
- package/README.md +480 -75
- package/android/gradle.properties +2 -2
- package/android/src/main/AndroidManifest.xml +3 -1
- package/android/src/main/cpp/cpp-adapter.cpp +4 -1
- package/android/src/main/java/com/munimbluetooth/HybridMunimBluetooth.kt +2006 -209
- package/android/src/main/java/com/munimbluetooth/MunimBluetoothBackgroundService.kt +561 -53
- package/app.plugin.js +155 -0
- package/ios/HybridMunimBluetooth.swift +2123 -298
- package/ios/MunimBluetoothEventEmitter.swift +68 -8
- package/lib/commonjs/index.js +272 -11
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +243 -11
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +310 -7
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts +219 -5
- package/lib/typescript/src/specs/munim-bluetooth.nitro.d.ts.map +1 -1
- package/nitro.json +9 -3
- package/nitrogen/generated/android/c++/JAdvertisingDataTypes.hpp +96 -96
- package/nitrogen/generated/android/c++/JAdvertisingOptions.hpp +8 -8
- package/nitrogen/generated/android/c++/JBackgroundSessionOptions.hpp +8 -8
- package/nitrogen/generated/android/c++/JBluetoothCapabilities.hpp +105 -0
- package/nitrogen/generated/android/c++/JBluetoothPhy.hpp +61 -0
- package/nitrogen/generated/android/c++/JBluetoothPhyOption.hpp +61 -0
- package/nitrogen/generated/android/c++/JBondState.hpp +64 -0
- package/nitrogen/generated/android/c++/JDescriptorValue.hpp +69 -0
- package/nitrogen/generated/android/c++/JExtendedAdvertisingOptions.hpp +131 -0
- package/nitrogen/generated/android/c++/JGATTCharacteristic.hpp +35 -11
- package/nitrogen/generated/android/c++/JGATTDescriptor.hpp +85 -0
- package/nitrogen/generated/android/c++/JGATTService.hpp +33 -9
- package/nitrogen/generated/android/c++/JHybridMunimBluetoothSpec.cpp +422 -12
- package/nitrogen/generated/android/c++/JHybridMunimBluetoothSpec.hpp +29 -0
- package/nitrogen/generated/android/c++/JL2CAPChannel.hpp +66 -0
- package/nitrogen/generated/android/c++/JMultipeerDiscoveryInfoEntry.hpp +61 -0
- package/nitrogen/generated/android/c++/JMultipeerEncryptionPreference.hpp +61 -0
- package/nitrogen/generated/android/c++/JMultipeerPeer.hpp +93 -0
- package/nitrogen/generated/android/c++/JMultipeerPeerState.hpp +61 -0
- package/nitrogen/generated/android/c++/JMultipeerSessionOptions.hpp +105 -0
- package/nitrogen/generated/android/c++/JPhyStatus.hpp +62 -0
- package/nitrogen/generated/android/c++/JScanOptions.hpp +8 -8
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/AdvertisingDataTypes.kt +47 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/AdvertisingOptions.kt +19 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BackgroundSessionOptions.kt +27 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BluetoothCapabilities.kt +111 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BluetoothPhy.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BluetoothPhyOption.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/BondState.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/CharacteristicValue.kt +17 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/DescriptorValue.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/ExtendedAdvertisingOptions.kt +111 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/GATTCharacteristic.kt +25 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/GATTDescriptor.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/GATTService.kt +23 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/HybridMunimBluetoothSpec.kt +138 -22
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/L2CAPChannel.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MultipeerDiscoveryInfoEntry.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MultipeerEncryptionPreference.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MultipeerPeer.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MultipeerPeerState.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/MultipeerSessionOptions.kt +81 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/PhyStatus.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/ScanOptions.kt +17 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/munimbluetooth/ServiceDataEntry.kt +15 -0
- package/nitrogen/generated/ios/MunimBluetooth+autolinking.rb +2 -0
- package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Bridge.cpp +61 -5
- package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Bridge.hpp +494 -49
- package/nitrogen/generated/ios/MunimBluetooth-Swift-Cxx-Umbrella.hpp +42 -0
- package/nitrogen/generated/ios/c++/HybridMunimBluetoothSpecSwift.hpp +254 -0
- package/nitrogen/generated/ios/swift/BluetoothCapabilities.swift +89 -0
- package/nitrogen/generated/ios/swift/BluetoothPhy.swift +44 -0
- package/nitrogen/generated/ios/swift/BluetoothPhyOption.swift +44 -0
- package/nitrogen/generated/ios/swift/BondState.swift +48 -0
- package/nitrogen/generated/ios/swift/DescriptorValue.swift +44 -0
- package/nitrogen/generated/ios/swift/ExtendedAdvertisingOptions.swift +243 -0
- package/nitrogen/generated/ios/swift/Func_void_BluetoothCapabilities.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_BondState.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_DescriptorValue.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_L2CAPChannel.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_PhyStatus.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_MultipeerPeer_.swift +46 -0
- package/nitrogen/generated/ios/swift/GATTCharacteristic.swift +25 -1
- package/nitrogen/generated/ios/swift/GATTDescriptor.swift +71 -0
- package/nitrogen/generated/ios/swift/GATTService.swift +25 -1
- package/nitrogen/generated/ios/swift/HybridMunimBluetoothSpec.swift +29 -0
- package/nitrogen/generated/ios/swift/HybridMunimBluetoothSpec_cxx.swift +556 -23
- package/nitrogen/generated/ios/swift/L2CAPChannel.swift +52 -0
- package/nitrogen/generated/ios/swift/MultipeerDiscoveryInfoEntry.swift +34 -0
- package/nitrogen/generated/ios/swift/MultipeerEncryptionPreference.swift +44 -0
- package/nitrogen/generated/ios/swift/MultipeerPeer.swift +63 -0
- package/nitrogen/generated/ios/swift/MultipeerPeerState.swift +44 -0
- package/nitrogen/generated/ios/swift/MultipeerSessionOptions.swift +136 -0
- package/nitrogen/generated/ios/swift/PhyStatus.swift +34 -0
- package/nitrogen/generated/shared/c++/BluetoothCapabilities.hpp +131 -0
- package/nitrogen/generated/shared/c++/BluetoothPhy.hpp +80 -0
- package/nitrogen/generated/shared/c++/BluetoothPhyOption.hpp +80 -0
- package/nitrogen/generated/shared/c++/BondState.hpp +84 -0
- package/nitrogen/generated/shared/c++/DescriptorValue.hpp +95 -0
- package/nitrogen/generated/shared/c++/ExtendedAdvertisingOptions.hpp +138 -0
- package/nitrogen/generated/shared/c++/GATTCharacteristic.hpp +9 -3
- package/nitrogen/generated/shared/c++/GATTDescriptor.hpp +93 -0
- package/nitrogen/generated/shared/c++/GATTService.hpp +7 -2
- package/nitrogen/generated/shared/c++/HybridMunimBluetoothSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridMunimBluetoothSpec.hpp +61 -2
- package/nitrogen/generated/shared/c++/L2CAPChannel.hpp +92 -0
- package/nitrogen/generated/shared/c++/MultipeerDiscoveryInfoEntry.hpp +87 -0
- package/nitrogen/generated/shared/c++/MultipeerEncryptionPreference.hpp +80 -0
- package/nitrogen/generated/shared/c++/MultipeerPeer.hpp +102 -0
- package/nitrogen/generated/shared/c++/MultipeerPeerState.hpp +80 -0
- package/nitrogen/generated/shared/c++/MultipeerSessionOptions.hpp +114 -0
- package/nitrogen/generated/shared/c++/PhyStatus.hpp +88 -0
- package/package.json +23 -12
- package/src/index.ts +416 -31
- 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;
|