munim-bluetooth 0.3.13 → 0.3.15
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/ios/HybridMunimBluetooth.swift +95 -46
- package/ios/MunimBluetoothEventEmitter.m +15 -0
- package/ios/MunimBluetoothEventEmitter.swift +38 -0
- package/lib/commonjs/index.js +47 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +45 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +17 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +46 -0
|
@@ -30,6 +30,52 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
30
30
|
centralManager = CBCentralManager(delegate: self, queue: nil)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// MARK: - Event Emission
|
|
34
|
+
private func emitDeviceFound(device: CBPeripheral, advertisementData: [String: Any], rssi: NSNumber) {
|
|
35
|
+
// Build device data dictionary
|
|
36
|
+
var deviceData: [String: Any] = [
|
|
37
|
+
"id": device.identifier.uuidString,
|
|
38
|
+
"rssi": rssi.intValue
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
// Add device name if available
|
|
42
|
+
if let name = device.name {
|
|
43
|
+
deviceData["name"] = name
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Extract and add advertising data
|
|
47
|
+
if let localName = advertisementData[CBAdvertisementDataLocalNameKey] as? String {
|
|
48
|
+
deviceData["localName"] = localName
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if let serviceUUIDs = advertisementData[CBAdvertisementDataServiceUUIDsKey] as? [CBUUID] {
|
|
52
|
+
deviceData["serviceUUIDs"] = serviceUUIDs.map { $0.uuidString }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if let manufacturerData = advertisementData[CBAdvertisementDataManufacturerDataKey] as? Data {
|
|
56
|
+
deviceData["manufacturerData"] = manufacturerData.map { String(format: "%02x", $0) }.joined()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if let txPowerLevel = advertisementData[CBAdvertisementDataTxPowerLevelKey] as? NSNumber {
|
|
60
|
+
deviceData["txPowerLevel"] = txPowerLevel.intValue
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if let isConnectable = advertisementData[CBAdvertisementDataIsConnectable] as? NSNumber {
|
|
64
|
+
deviceData["isConnectable"] = isConnectable.boolValue
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Store advertising data
|
|
68
|
+
deviceData["advertisingData"] = advertisementData
|
|
69
|
+
|
|
70
|
+
// Emit event through the event emitter
|
|
71
|
+
if let emitter = MunimBluetoothEventEmitter.shared {
|
|
72
|
+
emitter.emitDeviceFound(deviceData)
|
|
73
|
+
NSLog("[MunimBluetooth] ✅ Device found event emitted: %@", device.identifier.uuidString)
|
|
74
|
+
} else {
|
|
75
|
+
NSLog("[MunimBluetooth] ⚠️ Event emitter not initialized!")
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
33
79
|
// MARK: - Peripheral Features
|
|
34
80
|
|
|
35
81
|
func startAdvertising(options: AdvertisingOptions) throws {
|
|
@@ -82,9 +128,9 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
82
128
|
}
|
|
83
129
|
|
|
84
130
|
func getAdvertisingData() throws -> Promise<AdvertisingDataTypes> {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
131
|
+
let promise = Promise<AdvertisingDataTypes>()
|
|
132
|
+
promise.resolve(withResult: self.currentAdvertisingData ?? AdvertisingDataTypes())
|
|
133
|
+
return promise
|
|
88
134
|
}
|
|
89
135
|
|
|
90
136
|
func stopAdvertising() throws {
|
|
@@ -154,17 +200,17 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
154
200
|
// MARK: - Central/Manager Features
|
|
155
201
|
|
|
156
202
|
func isBluetoothEnabled() throws -> Promise<Bool> {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
203
|
+
let promise = Promise<Bool>()
|
|
204
|
+
let isEnabled = self.centralManager?.state == .poweredOn
|
|
205
|
+
promise.resolve(withResult: isEnabled ?? false)
|
|
206
|
+
return promise
|
|
161
207
|
}
|
|
162
208
|
|
|
163
209
|
func requestBluetoothPermission() throws -> Promise<Bool> {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
210
|
+
let promise = Promise<Bool>()
|
|
211
|
+
// In iOS, permissions are handled by CBPeripheralManager/CBCentralManager
|
|
212
|
+
promise.resolve(withResult: true)
|
|
213
|
+
return promise
|
|
168
214
|
}
|
|
169
215
|
|
|
170
216
|
func startScan(options: ScanOptions?) throws {
|
|
@@ -190,16 +236,16 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
190
236
|
}
|
|
191
237
|
|
|
192
238
|
func connect(deviceId: String) throws -> Promise<Void> {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
self.centralManager?.connect(peripheral, options: nil)
|
|
200
|
-
self.connectedPeripherals[deviceId] = peripheral
|
|
201
|
-
resolver.resolve(())
|
|
239
|
+
let promise = Promise<Void>()
|
|
240
|
+
guard let peripheral = self.discoveredPeripherals[deviceId] else {
|
|
241
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not found"]))
|
|
242
|
+
return promise
|
|
202
243
|
}
|
|
244
|
+
|
|
245
|
+
self.centralManager?.connect(peripheral, options: nil)
|
|
246
|
+
self.connectedPeripherals[deviceId] = peripheral
|
|
247
|
+
promise.resolve(withResult: ())
|
|
248
|
+
return promise
|
|
203
249
|
}
|
|
204
250
|
|
|
205
251
|
func disconnect(deviceId: String) throws {
|
|
@@ -209,27 +255,27 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
209
255
|
}
|
|
210
256
|
|
|
211
257
|
func discoverServices(deviceId: String) throws -> Promise<[GATTService]> {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
peripheral.discoverServices(nil)
|
|
219
|
-
resolver.resolve([])
|
|
258
|
+
let promise = Promise<[GATTService]>()
|
|
259
|
+
guard let peripheral = self.connectedPeripherals[deviceId] else {
|
|
260
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not connected"]))
|
|
261
|
+
return promise
|
|
220
262
|
}
|
|
263
|
+
|
|
264
|
+
peripheral.discoverServices(nil)
|
|
265
|
+
promise.resolve(withResult: [])
|
|
266
|
+
return promise
|
|
221
267
|
}
|
|
222
268
|
|
|
223
269
|
func readCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String) throws -> Promise<CharacteristicValue> {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
270
|
+
let promise = Promise<CharacteristicValue>()
|
|
271
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Not implemented"]))
|
|
272
|
+
return promise
|
|
227
273
|
}
|
|
228
274
|
|
|
229
275
|
func writeCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String, value: String, writeType: WriteType?) throws -> Promise<Void> {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
276
|
+
let promise = Promise<Void>()
|
|
277
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Not implemented"]))
|
|
278
|
+
return promise
|
|
233
279
|
}
|
|
234
280
|
|
|
235
281
|
func subscribeToCharacteristic(deviceId: String, serviceUUID: String, characteristicUUID: String) throws {
|
|
@@ -241,21 +287,21 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
241
287
|
}
|
|
242
288
|
|
|
243
289
|
func getConnectedDevices() throws -> Promise<[String]> {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
290
|
+
let promise = Promise<[String]>()
|
|
291
|
+
promise.resolve(withResult: Array(self.connectedPeripherals.keys))
|
|
292
|
+
return promise
|
|
247
293
|
}
|
|
248
294
|
|
|
249
295
|
func readRSSI(deviceId: String) throws -> Promise<Double> {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
peripheral.readRSSI()
|
|
257
|
-
resolver.resolve(0)
|
|
296
|
+
let promise = Promise<Double>()
|
|
297
|
+
guard let peripheral = self.connectedPeripherals[deviceId] else {
|
|
298
|
+
promise.reject(withError: NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Device not connected"]))
|
|
299
|
+
return promise
|
|
258
300
|
}
|
|
301
|
+
|
|
302
|
+
peripheral.readRSSI()
|
|
303
|
+
promise.resolve(withResult: 0)
|
|
304
|
+
return promise
|
|
259
305
|
}
|
|
260
306
|
|
|
261
307
|
func addListener(eventName: String) throws {
|
|
@@ -335,7 +381,10 @@ extension HybridMunimBluetooth: CBCentralManagerDelegate {
|
|
|
335
381
|
let deviceId = peripheral.identifier.uuidString
|
|
336
382
|
discoveredPeripherals[deviceId] = peripheral
|
|
337
383
|
|
|
338
|
-
|
|
384
|
+
// Emit the device found event
|
|
385
|
+
emitDeviceFound(device: peripheral, advertisementData: advertisementData, rssi: RSSI)
|
|
386
|
+
|
|
387
|
+
NSLog("Bluetooth: deviceFound - %@", deviceId)
|
|
339
388
|
}
|
|
340
389
|
|
|
341
390
|
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MunimBluetoothEventEmitter.m
|
|
3
|
+
// munim-bluetooth
|
|
4
|
+
//
|
|
5
|
+
// Objective-C bridge for event emitter
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <React/RCTBridgeModule.h>
|
|
9
|
+
#import <React/RCTEventEmitter.h>
|
|
10
|
+
|
|
11
|
+
@interface RCT_EXTERN_MODULE(MunimBluetoothEventEmitter, RCTEventEmitter)
|
|
12
|
+
|
|
13
|
+
RCT_EXTERN_METHOD(supportedEvents)
|
|
14
|
+
|
|
15
|
+
@end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MunimBluetoothEventEmitter.swift
|
|
3
|
+
// munim-bluetooth
|
|
4
|
+
//
|
|
5
|
+
// Event emitter for Bluetooth events
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import React
|
|
10
|
+
|
|
11
|
+
@objc(MunimBluetoothEventEmitter)
|
|
12
|
+
class MunimBluetoothEventEmitter: RCTEventEmitter {
|
|
13
|
+
|
|
14
|
+
public static var shared: MunimBluetoothEventEmitter?
|
|
15
|
+
|
|
16
|
+
override init() {
|
|
17
|
+
super.init()
|
|
18
|
+
MunimBluetoothEventEmitter.shared = self
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
override func supportedEvents() -> [String]! {
|
|
22
|
+
return [
|
|
23
|
+
"deviceFound",
|
|
24
|
+
"onDeviceFound",
|
|
25
|
+
"scanResult",
|
|
26
|
+
"connectionStateChanged",
|
|
27
|
+
"characteristicValueChanged"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override static func requiresMainQueueSetup() -> Bool {
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
func emitDeviceFound(_ deviceData: [String: Any]) {
|
|
36
|
+
sendEvent(withName: "deviceFound", body: deviceData)
|
|
37
|
+
}
|
|
38
|
+
}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.addDeviceFoundListener = addDeviceFoundListener;
|
|
7
|
+
exports.addEventListener = addEventListener;
|
|
6
8
|
exports.addListener = addListener;
|
|
7
9
|
exports.connect = connect;
|
|
8
10
|
exports.default = void 0;
|
|
@@ -25,8 +27,20 @@ exports.unsubscribeFromCharacteristic = unsubscribeFromCharacteristic;
|
|
|
25
27
|
exports.updateAdvertisingData = updateAdvertisingData;
|
|
26
28
|
exports.writeCharacteristic = writeCharacteristic;
|
|
27
29
|
var _reactNativeNitroModules = require("react-native-nitro-modules");
|
|
30
|
+
var _reactNative = require("react-native");
|
|
28
31
|
const MunimBluetooth = _reactNativeNitroModules.NitroModules.createHybridObject('MunimBluetooth');
|
|
29
32
|
|
|
33
|
+
// Event Emitter for Bluetooth events
|
|
34
|
+
const {
|
|
35
|
+
MunimBluetoothEventEmitter
|
|
36
|
+
} = _reactNative.NativeModules;
|
|
37
|
+
let eventEmitter = null;
|
|
38
|
+
if (MunimBluetoothEventEmitter) {
|
|
39
|
+
eventEmitter = new _reactNative.NativeEventEmitter(MunimBluetoothEventEmitter);
|
|
40
|
+
} else {
|
|
41
|
+
console.warn('[munim-bluetooth] Event emitter not available - device discovery events will not work');
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
// ========== Peripheral Features ==========
|
|
31
45
|
|
|
32
46
|
/**
|
|
@@ -206,10 +220,41 @@ function readRSSI(deviceId) {
|
|
|
206
220
|
|
|
207
221
|
// ========== Event Management ==========
|
|
208
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Add a device found event listener (for scanning).
|
|
225
|
+
*
|
|
226
|
+
* @param callback - Function to call when a device is found
|
|
227
|
+
* @returns A function to remove the listener
|
|
228
|
+
*/
|
|
229
|
+
function addDeviceFoundListener(callback) {
|
|
230
|
+
if (!eventEmitter) {
|
|
231
|
+
console.warn('[munim-bluetooth] Cannot add listener - event emitter not available');
|
|
232
|
+
return () => {};
|
|
233
|
+
}
|
|
234
|
+
const subscription = eventEmitter.addListener('deviceFound', callback);
|
|
235
|
+
return () => subscription.remove();
|
|
236
|
+
}
|
|
237
|
+
|
|
209
238
|
/**
|
|
210
239
|
* Add an event listener.
|
|
211
240
|
*
|
|
212
241
|
* @param eventName - The name of the event to listen for.
|
|
242
|
+
* @param callback - The callback to invoke when the event occurs.
|
|
243
|
+
* @returns A function to remove the listener
|
|
244
|
+
*/
|
|
245
|
+
function addEventListener(eventName, callback) {
|
|
246
|
+
if (!eventEmitter) {
|
|
247
|
+
console.warn('[munim-bluetooth] Cannot add listener - event emitter not available');
|
|
248
|
+
return () => {};
|
|
249
|
+
}
|
|
250
|
+
const subscription = eventEmitter.addListener(eventName, callback);
|
|
251
|
+
return () => subscription.remove();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Add an event listener (legacy method).
|
|
256
|
+
*
|
|
257
|
+
* @param eventName - The name of the event to listen for.
|
|
213
258
|
*/
|
|
214
259
|
function addListener(eventName) {
|
|
215
260
|
return MunimBluetooth.addListener(eventName);
|
|
@@ -248,6 +293,8 @@ var _default = exports.default = {
|
|
|
248
293
|
getConnectedDevices,
|
|
249
294
|
readRSSI,
|
|
250
295
|
// Events
|
|
296
|
+
addDeviceFoundListener,
|
|
297
|
+
addEventListener,
|
|
251
298
|
addListener,
|
|
252
299
|
removeListeners
|
|
253
300
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeNitroModules","require","MunimBluetooth","NitroModules","createHybridObject","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","addListener","eventName","removeListeners","count","_default","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","_reactNative","MunimBluetooth","NitroModules","createHybridObject","MunimBluetoothEventEmitter","NativeModules","eventEmitter","NativeEventEmitter","console","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAUA,MAAME,cAAc,GAClBC,qCAAY,CAACC,kBAAkB,CAAqB,gBAAgB,CAAC;;AAEvE;AACA,MAAM;EAAEC;AAA2B,CAAC,GAAGC,0BAAa;AACpD,IAAIC,YAAuC,GAAG,IAAI;AAElD,IAAIF,0BAA0B,EAAE;EAC9BE,YAAY,GAAG,IAAIC,+BAAkB,CAACH,0BAA0B,CAAC;AACnE,CAAC,MAAM;EACLI,OAAO,CAACC,IAAI,CAAC,uFAAuF,CAAC;AACvG;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAACC,OAKhC,EAAQ;EACP,OAAOV,cAAc,CAACS,gBAAgB,CAACC,OAAO,CAAC;AACjD;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CACnCC,eAAqC,EAC/B;EACN,OAAOZ,cAAc,CAACW,qBAAqB,CAACC,eAAe,CAAC;AAC9D;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAAA,EAAkC;EAClE,OAAOb,cAAc,CAACa,kBAAkB,CAAC,CAAC;AAC5C;;AAEA;AACA;AACA;AACO,SAASC,eAAeA,CAAA,EAAS;EACtC,OAAOd,cAAc,CAACc,e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C,gBAAgBA,CAACC,SAAiB,EAAEL,QAA6B,EAAc;EAC7F,IAAI,CAAC/B,YAAY,EAAE;IACjBE,OAAO,CAACC,IAAI,CAAC,qEAAqE,CAAC;IACnF,OAAO,MAAM,CAAC,CAAC;EACjB;EAEA,MAAM6B,YAAY,GAAGhC,YAAY,CAACiC,WAAW,CAACG,SAAS,EAAEL,QAAQ,CAAC;EAClE,OAAO,MAAMC,YAAY,CAACE,MAAM,CAAC,CAAC;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASD,WAAWA,CAACG,SAAiB,EAAQ;EACnD,OAAOzC,cAAc,CAACsC,WAAW,CAACG,SAAS,CAAC;AAC9C;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAACC,KAAa,EAAQ;EACnD,OAAO3C,cAAc,CAAC0C,eAAe,CAACC,KAAK,CAAC;AAC9C;;AAEA;AAUA;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GACe;EACb;EACArC,gBAAgB;EAChBK,eAAe;EACfH,qBAAqB;EACrBE,kBAAkB;EAClBE,WAAW;EACX;EACAE,kBAAkB;EAClBC,0BAA0B;EAC1BC,SAAS;EACTC,QAAQ;EACRC,OAAO;EACPE,UAAU;EACVC,gBAAgB;EAChBC,kBAAkB;EAClBG,mBAAmB;EACnBG,yBAAyB;EACzBC,6BAA6B;EAC7BC,mBAAmB;EACnBC,QAAQ;EACR;EACAC,sBAAsB;EACtBK,gBAAgB;EAChBF,WAAW;EACXI;AACF,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
4
5
|
const MunimBluetooth = NitroModules.createHybridObject('MunimBluetooth');
|
|
5
6
|
|
|
7
|
+
// Event Emitter for Bluetooth events
|
|
8
|
+
const {
|
|
9
|
+
MunimBluetoothEventEmitter
|
|
10
|
+
} = NativeModules;
|
|
11
|
+
let eventEmitter = null;
|
|
12
|
+
if (MunimBluetoothEventEmitter) {
|
|
13
|
+
eventEmitter = new NativeEventEmitter(MunimBluetoothEventEmitter);
|
|
14
|
+
} else {
|
|
15
|
+
console.warn('[munim-bluetooth] Event emitter not available - device discovery events will not work');
|
|
16
|
+
}
|
|
17
|
+
|
|
6
18
|
// ========== Peripheral Features ==========
|
|
7
19
|
|
|
8
20
|
/**
|
|
@@ -182,10 +194,41 @@ export function readRSSI(deviceId) {
|
|
|
182
194
|
|
|
183
195
|
// ========== Event Management ==========
|
|
184
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Add a device found event listener (for scanning).
|
|
199
|
+
*
|
|
200
|
+
* @param callback - Function to call when a device is found
|
|
201
|
+
* @returns A function to remove the listener
|
|
202
|
+
*/
|
|
203
|
+
export function addDeviceFoundListener(callback) {
|
|
204
|
+
if (!eventEmitter) {
|
|
205
|
+
console.warn('[munim-bluetooth] Cannot add listener - event emitter not available');
|
|
206
|
+
return () => {};
|
|
207
|
+
}
|
|
208
|
+
const subscription = eventEmitter.addListener('deviceFound', callback);
|
|
209
|
+
return () => subscription.remove();
|
|
210
|
+
}
|
|
211
|
+
|
|
185
212
|
/**
|
|
186
213
|
* Add an event listener.
|
|
187
214
|
*
|
|
188
215
|
* @param eventName - The name of the event to listen for.
|
|
216
|
+
* @param callback - The callback to invoke when the event occurs.
|
|
217
|
+
* @returns A function to remove the listener
|
|
218
|
+
*/
|
|
219
|
+
export function addEventListener(eventName, callback) {
|
|
220
|
+
if (!eventEmitter) {
|
|
221
|
+
console.warn('[munim-bluetooth] Cannot add listener - event emitter not available');
|
|
222
|
+
return () => {};
|
|
223
|
+
}
|
|
224
|
+
const subscription = eventEmitter.addListener(eventName, callback);
|
|
225
|
+
return () => subscription.remove();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Add an event listener (legacy method).
|
|
230
|
+
*
|
|
231
|
+
* @param eventName - The name of the event to listen for.
|
|
189
232
|
*/
|
|
190
233
|
export function addListener(eventName) {
|
|
191
234
|
return MunimBluetooth.addListener(eventName);
|
|
@@ -225,6 +268,8 @@ export default {
|
|
|
225
268
|
getConnectedDevices,
|
|
226
269
|
readRSSI,
|
|
227
270
|
// Events
|
|
271
|
+
addDeviceFoundListener,
|
|
272
|
+
addEventListener,
|
|
228
273
|
addListener,
|
|
229
274
|
removeListeners
|
|
230
275
|
};
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NitroModules","MunimBluetooth","createHybridObject","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","addListener","eventName","removeListeners","count"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;
|
|
1
|
+
{"version":3,"names":["NitroModules","NativeEventEmitter","NativeModules","MunimBluetooth","createHybridObject","MunimBluetoothEventEmitter","eventEmitter","console","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,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAUhE,MAAMC,cAAc,GAClBH,YA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,WAAW,CAACG,SAAS,CAAC;AAC9C;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACC,KAAa,EAAQ;EACnD,OAAOxC,cAAc,CAACuC,eAAe,CAACC,KAAK,CAAC;AAC9C;;AAEA;;AAUA;AACA,eAAe;EACb;EACAlC,gBAAgB;EAChBK,eAAe;EACfH,qBAAqB;EACrBE,kBAAkB;EAClBE,WAAW;EACX;EACAE,kBAAkB;EAClBC,0BAA0B;EAC1BC,SAAS;EACTC,QAAQ;EACRC,OAAO;EACPE,UAAU;EACVC,gBAAgB;EAChBC,kBAAkB;EAClBG,mBAAmB;EACnBG,yBAAyB;EACzBC,6BAA6B;EAC7BC,mBAAmB;EACnBC,QAAQ;EACR;EACAC,sBAAsB;EACtBK,gBAAgB;EAChBF,WAAW;EACXI;AACF,CAAC","ignoreList":[]}
|
|
@@ -123,10 +123,25 @@ 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
|
+
* Add a device found event listener (for scanning).
|
|
128
|
+
*
|
|
129
|
+
* @param callback - Function to call when a device is found
|
|
130
|
+
* @returns A function to remove the listener
|
|
131
|
+
*/
|
|
132
|
+
export declare function addDeviceFoundListener(callback: (device: BLEDevice) => void): () => void;
|
|
126
133
|
/**
|
|
127
134
|
* Add an event listener.
|
|
128
135
|
*
|
|
129
136
|
* @param eventName - The name of the event to listen for.
|
|
137
|
+
* @param callback - The callback to invoke when the event occurs.
|
|
138
|
+
* @returns A function to remove the listener
|
|
139
|
+
*/
|
|
140
|
+
export declare function addEventListener(eventName: string, callback: (data: any) => void): () => void;
|
|
141
|
+
/**
|
|
142
|
+
* Add an event listener (legacy method).
|
|
143
|
+
*
|
|
144
|
+
* @param eventName - The name of the event to listen for.
|
|
130
145
|
*/
|
|
131
146
|
export declare function addListener(eventName: string): void;
|
|
132
147
|
/**
|
|
@@ -155,6 +170,8 @@ declare const _default: {
|
|
|
155
170
|
unsubscribeFromCharacteristic: typeof unsubscribeFromCharacteristic;
|
|
156
171
|
getConnectedDevices: typeof getConnectedDevices;
|
|
157
172
|
readRSSI: typeof readRSSI;
|
|
173
|
+
addDeviceFoundListener: typeof addDeviceFoundListener;
|
|
174
|
+
addEventListener: typeof addEventListener;
|
|
158
175
|
addListener: typeof addListener;
|
|
159
176
|
removeListeners: typeof removeListeners;
|
|
160
177
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,WAAW,EACX,mBAAmB,EACpB,MAAM,+BAA+B,CAAA;AAiBtC;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC,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,0BAA0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,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE1D;AAID;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,CAQxF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,MAAM,IAAI,CAQ7F;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAEnD;AAID,YAAY,EACV,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,WAAW,EACX,mBAAmB,GACpB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;AAGD,wBA0BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "munim-bluetooth",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.15",
|
|
4
4
|
"description": "A comprehensive React Native library for all your Bluetooth Low Energy (BLE) needs, supporting both peripheral and central roles with Expo support",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
|
+
import { NativeEventEmitter, NativeModules } from 'react-native'
|
|
2
3
|
import type {
|
|
3
4
|
MunimBluetooth as MunimBluetoothSpec,
|
|
4
5
|
AdvertisingDataTypes,
|
|
@@ -11,6 +12,16 @@ import type {
|
|
|
11
12
|
const MunimBluetooth =
|
|
12
13
|
NitroModules.createHybridObject<MunimBluetoothSpec>('MunimBluetooth')
|
|
13
14
|
|
|
15
|
+
// Event Emitter for Bluetooth events
|
|
16
|
+
const { MunimBluetoothEventEmitter } = NativeModules
|
|
17
|
+
let eventEmitter: NativeEventEmitter | null = null
|
|
18
|
+
|
|
19
|
+
if (MunimBluetoothEventEmitter) {
|
|
20
|
+
eventEmitter = new NativeEventEmitter(MunimBluetoothEventEmitter)
|
|
21
|
+
} else {
|
|
22
|
+
console.warn('[munim-bluetooth] Event emitter not available - device discovery events will not work')
|
|
23
|
+
}
|
|
24
|
+
|
|
14
25
|
// ========== Peripheral Features ==========
|
|
15
26
|
|
|
16
27
|
/**
|
|
@@ -233,10 +244,43 @@ export function readRSSI(deviceId: string): Promise<number> {
|
|
|
233
244
|
|
|
234
245
|
// ========== Event Management ==========
|
|
235
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Add a device found event listener (for scanning).
|
|
249
|
+
*
|
|
250
|
+
* @param callback - Function to call when a device is found
|
|
251
|
+
* @returns A function to remove the listener
|
|
252
|
+
*/
|
|
253
|
+
export function addDeviceFoundListener(callback: (device: BLEDevice) => void): () => void {
|
|
254
|
+
if (!eventEmitter) {
|
|
255
|
+
console.warn('[munim-bluetooth] Cannot add listener - event emitter not available')
|
|
256
|
+
return () => {}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const subscription = eventEmitter.addListener('deviceFound', callback)
|
|
260
|
+
return () => subscription.remove()
|
|
261
|
+
}
|
|
262
|
+
|
|
236
263
|
/**
|
|
237
264
|
* Add an event listener.
|
|
238
265
|
*
|
|
239
266
|
* @param eventName - The name of the event to listen for.
|
|
267
|
+
* @param callback - The callback to invoke when the event occurs.
|
|
268
|
+
* @returns A function to remove the listener
|
|
269
|
+
*/
|
|
270
|
+
export function addEventListener(eventName: string, callback: (data: any) => void): () => void {
|
|
271
|
+
if (!eventEmitter) {
|
|
272
|
+
console.warn('[munim-bluetooth] Cannot add listener - event emitter not available')
|
|
273
|
+
return () => {}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const subscription = eventEmitter.addListener(eventName, callback)
|
|
277
|
+
return () => subscription.remove()
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Add an event listener (legacy method).
|
|
282
|
+
*
|
|
283
|
+
* @param eventName - The name of the event to listen for.
|
|
240
284
|
*/
|
|
241
285
|
export function addListener(eventName: string): void {
|
|
242
286
|
return MunimBluetooth.addListener(eventName)
|
|
@@ -284,6 +328,8 @@ export default {
|
|
|
284
328
|
getConnectedDevices,
|
|
285
329
|
readRSSI,
|
|
286
330
|
// Events
|
|
331
|
+
addDeviceFoundListener,
|
|
332
|
+
addEventListener,
|
|
287
333
|
addListener,
|
|
288
334
|
removeListeners,
|
|
289
335
|
}
|