munim-bluetooth 0.3.16 → 0.3.18
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.
|
@@ -79,9 +79,18 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
79
79
|
// MARK: - Peripheral Features
|
|
80
80
|
|
|
81
81
|
func startAdvertising(options: AdvertisingOptions) throws {
|
|
82
|
-
guard let peripheralManager = peripheralManager
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
guard let peripheralManager = peripheralManager else {
|
|
83
|
+
throw NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Peripheral manager not initialized"])
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
guard peripheralManager.state == .poweredOn else {
|
|
87
|
+
throw NSError(domain: "MunimBluetooth", code: 2, userInfo: [NSLocalizedDescriptionKey: "Bluetooth is not powered on. Current state: \(peripheralManager.state.rawValue)"])
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Stop any existing advertising first
|
|
91
|
+
if peripheralManager.isAdvertising {
|
|
92
|
+
NSLog("[MunimBluetooth] Stopping existing advertising")
|
|
93
|
+
peripheralManager.stopAdvertising()
|
|
85
94
|
}
|
|
86
95
|
|
|
87
96
|
var advertisingData: [String: Any] = [:]
|
|
@@ -90,17 +99,20 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
90
99
|
if !options.serviceUUIDs.isEmpty {
|
|
91
100
|
let uuids = options.serviceUUIDs.compactMap { CBUUID(string: $0) }
|
|
92
101
|
advertisingData[CBAdvertisementDataServiceUUIDsKey] = uuids
|
|
102
|
+
NSLog("[MunimBluetooth] Advertising service UUIDs: %@", options.serviceUUIDs)
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
// Local name
|
|
96
106
|
if let localName = options.localName {
|
|
97
107
|
advertisingData[CBAdvertisementDataLocalNameKey] = localName
|
|
108
|
+
NSLog("[MunimBluetooth] Advertising local name: %@", localName)
|
|
98
109
|
}
|
|
99
110
|
|
|
100
111
|
// Manufacturer data
|
|
101
112
|
if let manufacturerData = options.manufacturerData,
|
|
102
113
|
let data = hexStringToData(manufacturerData) {
|
|
103
114
|
advertisingData[CBAdvertisementDataManufacturerDataKey] = data
|
|
115
|
+
NSLog("[MunimBluetooth] Advertising manufacturer data: %@ bytes", String(data.count))
|
|
104
116
|
}
|
|
105
117
|
|
|
106
118
|
// Advertising data
|
|
@@ -109,7 +121,9 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
109
121
|
}
|
|
110
122
|
|
|
111
123
|
currentAdvertisingData = options.advertisingData
|
|
112
|
-
|
|
124
|
+
|
|
125
|
+
NSLog("[MunimBluetooth] Starting advertising with data: %@", advertisingData)
|
|
126
|
+
peripheralManager.startAdvertising(advertisingData)
|
|
113
127
|
}
|
|
114
128
|
|
|
115
129
|
func updateAdvertisingData(advertisingData: AdvertisingDataTypes) throws {
|
|
@@ -139,14 +153,28 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
139
153
|
}
|
|
140
154
|
|
|
141
155
|
func setServices(services: [GATTService]) throws {
|
|
156
|
+
guard let peripheralManager = peripheralManager else {
|
|
157
|
+
throw NSError(domain: "MunimBluetooth", code: 1, userInfo: [NSLocalizedDescriptionKey: "Peripheral manager not initialized"])
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
guard peripheralManager.state == .poweredOn else {
|
|
161
|
+
throw NSError(domain: "MunimBluetooth", code: 2, userInfo: [NSLocalizedDescriptionKey: "Bluetooth is not powered on. Current state: \(peripheralManager.state.rawValue)"])
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Remove existing services first
|
|
165
|
+
peripheralManager.removeAllServices()
|
|
142
166
|
peripheralServices.removeAll()
|
|
143
167
|
|
|
168
|
+
NSLog("[MunimBluetooth] Setting up %d services", services.count)
|
|
169
|
+
|
|
144
170
|
for service in services {
|
|
145
171
|
let serviceUUID = CBUUID(string: service.uuid)
|
|
146
172
|
let mutableService = CBMutableService(type: serviceUUID, primary: true)
|
|
147
173
|
|
|
148
174
|
var characteristics: [CBMutableCharacteristic] = []
|
|
149
175
|
|
|
176
|
+
NSLog("[MunimBluetooth] Service %@: %d characteristics", service.uuid, service.characteristics.count)
|
|
177
|
+
|
|
150
178
|
for characteristic in service.characteristics {
|
|
151
179
|
let charUUID = CBUUID(string: characteristic.uuid)
|
|
152
180
|
|
|
@@ -168,15 +196,32 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
168
196
|
}
|
|
169
197
|
}
|
|
170
198
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
199
|
+
// Important: In CoreBluetooth, if you provide a 'value' parameter,
|
|
200
|
+
// the characteristic becomes cached and read-only.
|
|
201
|
+
// For writable characteristics, the value MUST be nil.
|
|
202
|
+
var value: Data? = nil
|
|
203
|
+
let hasWriteProperty = properties.contains(.write) || properties.contains(.writeWithoutResponse)
|
|
204
|
+
|
|
205
|
+
if !hasWriteProperty {
|
|
206
|
+
// Only set a static value for read-only characteristics
|
|
207
|
+
if let valueString = characteristic.value {
|
|
208
|
+
value = hexStringToData(valueString)
|
|
176
209
|
}
|
|
177
210
|
}
|
|
178
211
|
|
|
179
|
-
|
|
212
|
+
// Always ensure read is present if we have a value
|
|
213
|
+
if value != nil && !properties.contains(.read) {
|
|
214
|
+
properties.insert(.read)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Set permissions based on properties
|
|
218
|
+
var permissions: CBAttributePermissions = []
|
|
219
|
+
if properties.contains(.read) {
|
|
220
|
+
permissions.insert(.readable)
|
|
221
|
+
}
|
|
222
|
+
if hasWriteProperty {
|
|
223
|
+
permissions.insert(.writeable)
|
|
224
|
+
}
|
|
180
225
|
|
|
181
226
|
let mutableChar = CBMutableCharacteristic(
|
|
182
227
|
type: charUUID,
|
|
@@ -186,15 +231,18 @@ class HybridMunimBluetooth: HybridMunimBluetoothSpec {
|
|
|
186
231
|
)
|
|
187
232
|
|
|
188
233
|
characteristics.append(mutableChar)
|
|
234
|
+
NSLog("[MunimBluetooth] Characteristic added: %@ with properties: %lu, hasValue: %@",
|
|
235
|
+
characteristic.uuid, properties.rawValue, value != nil ? "YES" : "NO")
|
|
189
236
|
}
|
|
190
237
|
|
|
191
238
|
mutableService.characteristics = characteristics
|
|
192
239
|
peripheralServices.append(mutableService)
|
|
240
|
+
|
|
241
|
+
NSLog("[MunimBluetooth] Adding service to peripheral manager: %@", service.uuid)
|
|
242
|
+
peripheralManager.add(mutableService)
|
|
193
243
|
}
|
|
194
244
|
|
|
195
|
-
|
|
196
|
-
peripheralManager?.add(service)
|
|
197
|
-
}
|
|
245
|
+
NSLog("[MunimBluetooth] All services added successfully")
|
|
198
246
|
}
|
|
199
247
|
|
|
200
248
|
// MARK: - Central/Manager Features
|
package/lib/commonjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeNitroModules","require","_reactNative","MunimBluetooth","NitroModules","createHybridObject","MunimBluetoothEventEmitter","NativeModules","console","log","Object","keys","filter","key","includes","eventEmitter","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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;AAEpDC,OAAO,CAACC,GAAG,
|
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","_reactNative","MunimBluetooth","NitroModules","createHybridObject","MunimBluetoothEventEmitter","NativeModules","console","log","Object","keys","filter","key","includes","eventEmitter","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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;AAEpDC,OAAO,CAACC,GAAG,CACT,iDAAiD,EACjDH,0BAA0B,GAAG,OAAO,GAAG,WACzC,CAAC;AACDE,OAAO,CAACC,GAAG,CACT,4CAA4C,EAC5CC,MAAM,CAACC,IAAI,CAACJ,0BAAa,CAAC,CAACK,MAAM,CAC9BC,GAAG,IAAKA,GAAG,CAACC,QAAQ,CAAC,WAAW,CAAC,IAAID,GAAG,CAACC,QAAQ,CAAC,OAAO,CAC5D,CACF,CAAC;AAED,IAAIC,YAAuC,GAAG,IAAI;AAElD,IAAIT,0BAA0B,EAAE;EAC9B,IAAI;IACFS,YAAY,GAAG,IAAIC,+BAAkB,CAACV,0BAA0B,CAAC;IACjEE,OAAO,CAACC,GAAG,CAAC,0DAA0D,CAAC;EACzE,C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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
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NitroModules","NativeEventEmitter","NativeModules","MunimBluetooth","createHybridObject","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,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAUhE,MAAMC,cAAc,GAClBH,YAAY,CAACI,kBAAkB,CAAqB,gBAAgB,CAAC;;AAEvE;AACA,MAAM;EAAEC;AAA2B,CAAC,GAAGH,aAAa;AAEpDI,OAAO,CAACC,GAAG,
|
|
1
|
+
{"version":3,"names":["NitroModules","NativeEventEmitter","NativeModules","MunimBluetooth","createHybridObject","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,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAUhE,MAAMC,cAAc,GAClBH,YAAY,CAACI,kBAAkB,CAAqB,gBAAgB,CAAC;;AAEvE;AACA,MAAM;EAAEC;AAA2B,CAAC,GAAGH,aAAa;AAEpDI,OAAO,CAACC,GAAG,CACT,iDAAiD,EACjDF,0BAA0B,GAAG,OAAO,GAAG,WACzC,CAAC;AACDC,OAAO,CAACC,GAAG,CACT,4CAA4C,EAC5CC,MAAM,CAACC,IAAI,CAACP,aAAa,CAAC,CAACQ,MAAM,CAC9BC,GAAG,IAAKA,GAAG,CAACC,QAAQ,CAAC,WAAW,CAAC,IAAID,GAAG,CAACC,QAAQ,CAAC,OAAO,CAC5D,CACF,CAAC;AAED,IAAIC,YAAuC,GAAG,IAAI;AAElD,IAAIR,0BAA0B,EAAE;EAC9B,IAAI;IACFQ,YAAY,GAAG,IAAIZ,kBAAkB,CAACI,0BAA0B,CAAC;IACjEC,OAAO,CAACC,GAAG,CAAC,0DAA0D,CAAC;EACzE,CAAC,CAAC,OAAOO,KAAK,EAAE;IACdR,OAAO,CAACQ,KAAK,CACX,uDAAuD,EACvDA,KACF,CAAC;EACH;AACF,CAAC,MAAM;EACLR,OAAO,CAACS,IAAI,CACV,2GACF,CAAC;EACDT,OAAO,CAACS,IAAI,CACV,mGACF,CAAC;AACH;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAACC,O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;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":[]}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AA0CtC;;;;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,OA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C,MAAM,CAAC,CAE1D;AAID;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,GACpC,MAAM,IAAI,CAUZ;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAC5B,MAAM,IAAI,CAUZ;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.18",
|
|
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
|
@@ -15,8 +15,16 @@ const MunimBluetooth =
|
|
|
15
15
|
// Event Emitter for Bluetooth events
|
|
16
16
|
const { MunimBluetoothEventEmitter } = NativeModules
|
|
17
17
|
|
|
18
|
-
console.log(
|
|
19
|
-
|
|
18
|
+
console.log(
|
|
19
|
+
'[munim-bluetooth] Checking for event emitter...',
|
|
20
|
+
MunimBluetoothEventEmitter ? 'FOUND' : 'NOT FOUND'
|
|
21
|
+
)
|
|
22
|
+
console.log(
|
|
23
|
+
'[munim-bluetooth] Available NativeModules:',
|
|
24
|
+
Object.keys(NativeModules).filter(
|
|
25
|
+
(key) => key.includes('Bluetooth') || key.includes('Munim')
|
|
26
|
+
)
|
|
27
|
+
)
|
|
20
28
|
|
|
21
29
|
let eventEmitter: NativeEventEmitter | null = null
|
|
22
30
|
|
|
@@ -25,11 +33,18 @@ if (MunimBluetoothEventEmitter) {
|
|
|
25
33
|
eventEmitter = new NativeEventEmitter(MunimBluetoothEventEmitter)
|
|
26
34
|
console.log('[munim-bluetooth] Event emitter initialized successfully')
|
|
27
35
|
} catch (error) {
|
|
28
|
-
console.error(
|
|
36
|
+
console.error(
|
|
37
|
+
'[munim-bluetooth] Failed to initialize event emitter:',
|
|
38
|
+
error
|
|
39
|
+
)
|
|
29
40
|
}
|
|
30
41
|
} else {
|
|
31
|
-
console.warn(
|
|
32
|
-
|
|
42
|
+
console.warn(
|
|
43
|
+
'[munim-bluetooth] Event emitter module not found in NativeModules - device discovery events will not work'
|
|
44
|
+
)
|
|
45
|
+
console.warn(
|
|
46
|
+
'[munim-bluetooth] This usually means the native module was not linked properly or needs a rebuild'
|
|
47
|
+
)
|
|
33
48
|
}
|
|
34
49
|
|
|
35
50
|
// ========== Peripheral Features ==========
|
|
@@ -40,10 +55,10 @@ if (MunimBluetoothEventEmitter) {
|
|
|
40
55
|
* @param options - An object with serviceUUIDs (string[]) and supported advertising data types.
|
|
41
56
|
*/
|
|
42
57
|
export function startAdvertising(options: {
|
|
43
|
-
serviceUUIDs: string[]
|
|
44
|
-
localName?: string
|
|
45
|
-
manufacturerData?: string
|
|
46
|
-
advertisingData?: AdvertisingDataTypes
|
|
58
|
+
serviceUUIDs: string[]
|
|
59
|
+
localName?: string
|
|
60
|
+
manufacturerData?: string
|
|
61
|
+
advertisingData?: AdvertisingDataTypes
|
|
47
62
|
}): void {
|
|
48
63
|
return MunimBluetooth.startAdvertising(options)
|
|
49
64
|
}
|
|
@@ -256,16 +271,20 @@ export function readRSSI(deviceId: string): Promise<number> {
|
|
|
256
271
|
|
|
257
272
|
/**
|
|
258
273
|
* Add a device found event listener (for scanning).
|
|
259
|
-
*
|
|
274
|
+
*
|
|
260
275
|
* @param callback - Function to call when a device is found
|
|
261
276
|
* @returns A function to remove the listener
|
|
262
277
|
*/
|
|
263
|
-
export function addDeviceFoundListener(
|
|
278
|
+
export function addDeviceFoundListener(
|
|
279
|
+
callback: (device: BLEDevice) => void
|
|
280
|
+
): () => void {
|
|
264
281
|
if (!eventEmitter) {
|
|
265
|
-
console.warn(
|
|
282
|
+
console.warn(
|
|
283
|
+
'[munim-bluetooth] Cannot add listener - event emitter not available'
|
|
284
|
+
)
|
|
266
285
|
return () => {}
|
|
267
286
|
}
|
|
268
|
-
|
|
287
|
+
|
|
269
288
|
const subscription = eventEmitter.addListener('deviceFound', callback)
|
|
270
289
|
return () => subscription.remove()
|
|
271
290
|
}
|
|
@@ -277,12 +296,17 @@ export function addDeviceFoundListener(callback: (device: BLEDevice) => void): (
|
|
|
277
296
|
* @param callback - The callback to invoke when the event occurs.
|
|
278
297
|
* @returns A function to remove the listener
|
|
279
298
|
*/
|
|
280
|
-
export function addEventListener(
|
|
299
|
+
export function addEventListener(
|
|
300
|
+
eventName: string,
|
|
301
|
+
callback: (data: any) => void
|
|
302
|
+
): () => void {
|
|
281
303
|
if (!eventEmitter) {
|
|
282
|
-
console.warn(
|
|
304
|
+
console.warn(
|
|
305
|
+
'[munim-bluetooth] Cannot add listener - event emitter not available'
|
|
306
|
+
)
|
|
283
307
|
return () => {}
|
|
284
308
|
}
|
|
285
|
-
|
|
309
|
+
|
|
286
310
|
const subscription = eventEmitter.addListener(eventName, callback)
|
|
287
311
|
return () => subscription.remove()
|
|
288
312
|
}
|