react-native-bluebreeze 0.0.1 → 0.0.3
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/android/build.gradle +8 -17
- package/android/generated/java/com/bluebreeze/NativeBlueBreezeSpec.java +17 -9
- package/android/generated/jni/RNBlueBreezeSpec-generated.cpp +21 -14
- package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI-generated.cpp +19 -12
- package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI.h +279 -53
- package/android/gradle.properties +5 -5
- package/android/src/main/java/com/bluebreeze/BlueBreezeModule.kt +632 -16
- package/android/src/main/java/com/bluebreeze/BlueBreezePackage.kt +0 -1
- package/ios/BlueBreezeImpl.swift +92 -84
- package/ios/Bluebreeze.mm +52 -25
- package/ios/generated/RNBlueBreezeSpec/RNBlueBreezeSpec-generated.mm +30 -18
- package/ios/generated/RNBlueBreezeSpec/RNBlueBreezeSpec.h +12 -7
- package/ios/generated/RNBlueBreezeSpecJSI-generated.cpp +19 -12
- package/ios/generated/RNBlueBreezeSpecJSI.h +279 -53
- package/lib/commonjs/NativeBlueBreeze.js +11 -0
- package/lib/commonjs/NativeBlueBreeze.js.map +1 -0
- package/lib/commonjs/implementation/bluebreeze_characteristic.js +29 -0
- package/lib/commonjs/implementation/bluebreeze_characteristic.js.map +1 -0
- package/lib/commonjs/implementation/bluebreeze_device.js +31 -0
- package/lib/commonjs/implementation/bluebreeze_device.js.map +1 -0
- package/lib/commonjs/implementation/bluebreeze_scan_result.js +20 -0
- package/lib/commonjs/implementation/bluebreeze_scan_result.js.map +1 -0
- package/lib/commonjs/implementation/bluebreeze_service.js +15 -0
- package/lib/commonjs/implementation/bluebreeze_service.js.map +1 -0
- package/lib/commonjs/implementation/emitters.js +32 -0
- package/lib/commonjs/implementation/emitters.js.map +1 -0
- package/lib/commonjs/index.js +171 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/NativeBlueBreeze.js +10 -0
- package/lib/module/NativeBlueBreeze.js.map +1 -0
- package/lib/module/implementation/bluebreeze_characteristic.js +23 -0
- package/lib/module/implementation/bluebreeze_characteristic.js.map +1 -0
- package/lib/module/implementation/bluebreeze_device.js +25 -0
- package/lib/module/implementation/bluebreeze_device.js.map +1 -0
- package/lib/module/implementation/bluebreeze_scan_result.js +15 -0
- package/lib/module/implementation/bluebreeze_scan_result.js.map +1 -0
- package/lib/module/implementation/bluebreeze_service.js +10 -0
- package/lib/module/implementation/bluebreeze_service.js.map +1 -0
- package/lib/module/implementation/emitters.js +25 -0
- package/lib/module/implementation/emitters.js.map +1 -0
- package/lib/module/index.js +168 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeBlueBreeze.d.ts +86 -0
- package/lib/typescript/commonjs/src/NativeBlueBreeze.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts +14 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts +15 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_scan_result.d.ts +13 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_scan_result.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_service.d.ts +8 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_service.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/implementation/emitters.d.ts +12 -0
- package/lib/typescript/commonjs/src/implementation/emitters.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +30 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/NativeBlueBreeze.d.ts +86 -0
- package/lib/typescript/module/src/NativeBlueBreeze.d.ts.map +1 -0
- package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts +14 -0
- package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts.map +1 -0
- package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts +15 -0
- package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts.map +1 -0
- package/lib/typescript/module/src/implementation/bluebreeze_scan_result.d.ts +13 -0
- package/lib/typescript/module/src/implementation/bluebreeze_scan_result.d.ts.map +1 -0
- package/lib/typescript/module/src/implementation/bluebreeze_service.d.ts +8 -0
- package/lib/typescript/module/src/implementation/bluebreeze_service.d.ts.map +1 -0
- package/lib/typescript/module/src/implementation/emitters.d.ts +12 -0
- package/lib/typescript/module/src/implementation/emitters.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +30 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +25 -21
- package/react-native-bluebreeze.podspec +1 -1
- package/src/NativeBlueBreeze.ts +83 -104
- package/src/implementation/bluebreeze_characteristic.ts +40 -0
- package/src/implementation/bluebreeze_device.ts +40 -0
- package/src/implementation/bluebreeze_scan_result.ts +32 -0
- package/src/implementation/bluebreeze_service.ts +17 -0
- package/src/implementation/emitters.ts +28 -0
- package/src/index.tsx +289 -81
package/src/index.tsx
CHANGED
|
@@ -1,99 +1,307 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { BBCharacteristic } from './implementation/bluebreeze_characteristic'
|
|
2
|
+
import { BBDevice } from './implementation/bluebreeze_device'
|
|
3
|
+
import { BBScanResult } from './implementation/bluebreeze_scan_result'
|
|
4
|
+
import { BBService } from './implementation/bluebreeze_service'
|
|
5
|
+
import { EventEmitter, StateEventEmitter } from './implementation/emitters'
|
|
6
|
+
import NativeBlueBreeze, { type SpecDevice, type SpecDeviceCharacteristic, type SpecDeviceService, type SpecScanResult } from './NativeBlueBreeze'
|
|
3
7
|
|
|
4
|
-
//
|
|
8
|
+
// State
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
const state = new StateEventEmitter<string>(NativeBlueBreeze.state())
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
NativeBlueBreeze.stateEmitter((value) => {
|
|
13
|
+
state.add(value)
|
|
14
|
+
})
|
|
9
15
|
|
|
10
|
-
|
|
16
|
+
// Authorization to use BLE
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
const authorizationStatus = new StateEventEmitter<string>(NativeBlueBreeze.authorizationStatus())
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
NativeBlueBreeze.authorizationStatusEmitter((value) => {
|
|
21
|
+
authorizationStatus.add(value)
|
|
22
|
+
})
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
const authorizationRequest = NativeBlueBreeze.authorizationRequest
|
|
25
|
+
|
|
26
|
+
const authorizationOpenSettings = NativeBlueBreeze.authorizationOpenSettings
|
|
17
27
|
|
|
18
28
|
// Scanning
|
|
19
29
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
const scanEnabled = new StateEventEmitter<boolean>(NativeBlueBreeze.scanEnabled())
|
|
31
|
+
|
|
32
|
+
NativeBlueBreeze.scanEnabledEmitter((value) => {
|
|
33
|
+
scanEnabled.add(value)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const scanResults = new EventEmitter<BBScanResult>()
|
|
37
|
+
|
|
38
|
+
NativeBlueBreeze.scanResultEmitter((value) => {
|
|
39
|
+
const device = devices.value?.get(value.id)
|
|
40
|
+
if (device == undefined) {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
scanResults.add(convertScanResult(device, value))
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const scanStart = NativeBlueBreeze.scanStart
|
|
48
|
+
|
|
49
|
+
const scanStop = NativeBlueBreeze.scanStop
|
|
50
|
+
|
|
51
|
+
// Device
|
|
52
|
+
|
|
53
|
+
const devices = new StateEventEmitter<Map<string, BBDevice>>(
|
|
54
|
+
new Map(
|
|
55
|
+
NativeBlueBreeze.devices().map((d) => [
|
|
56
|
+
d.id,
|
|
57
|
+
convertDevice(d)
|
|
58
|
+
])
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
NativeBlueBreeze.devicesEmitter((value) => {
|
|
63
|
+
devices.add(
|
|
64
|
+
new Map(
|
|
65
|
+
value.map((d) => [
|
|
66
|
+
d.id,
|
|
67
|
+
devices.value?.get(d.id) ?? convertDevice(d)
|
|
68
|
+
])
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
// Device services
|
|
74
|
+
|
|
75
|
+
const _deviceServices = new Map<string, StateEventEmitter<BBService[]>>()
|
|
76
|
+
|
|
77
|
+
const deviceServices = (id: string): StateEventEmitter<BBService[]> => {
|
|
78
|
+
return mapGetOrSet(
|
|
79
|
+
_deviceServices,
|
|
80
|
+
id,
|
|
81
|
+
() => new StateEventEmitter<BBService[]>(
|
|
82
|
+
NativeBlueBreeze.deviceServices(id).map(
|
|
83
|
+
(s) => convertDeviceService(id, s)
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
NativeBlueBreeze.deviceServicesEmitter((value) => {
|
|
90
|
+
deviceServices(value.id).add(
|
|
91
|
+
value.value.map((s) => convertDeviceService(value.id, s))
|
|
92
|
+
)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
// Device connection status
|
|
96
|
+
|
|
97
|
+
const _deviceConnectionStatus = new Map<string, StateEventEmitter<string>>()
|
|
98
|
+
|
|
99
|
+
const deviceConnectionStatus = (id: string): StateEventEmitter<string> => {
|
|
100
|
+
return mapGetOrSet(
|
|
101
|
+
_deviceConnectionStatus,
|
|
102
|
+
id,
|
|
103
|
+
() => new StateEventEmitter<string>(
|
|
104
|
+
NativeBlueBreeze.deviceConnectionStatus(id)
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
NativeBlueBreeze.deviceConnectionStatusEmitter((value) => {
|
|
110
|
+
deviceConnectionStatus(value.id).add(value.value)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
// Device MTU
|
|
114
|
+
|
|
115
|
+
const _deviceMTU = new Map<string, StateEventEmitter<number>>()
|
|
116
|
+
|
|
117
|
+
const deviceMTU = (id: string): StateEventEmitter<number> => {
|
|
118
|
+
return mapGetOrSet(
|
|
119
|
+
_deviceMTU,
|
|
120
|
+
id,
|
|
121
|
+
() => new StateEventEmitter<number>(
|
|
122
|
+
NativeBlueBreeze.deviceMTU(id)
|
|
123
|
+
)
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
NativeBlueBreeze.deviceMTUEmitter((value) => {
|
|
128
|
+
deviceMTU(value.id).add(value.value)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
// Device operation
|
|
132
|
+
|
|
133
|
+
const deviceConnect = NativeBlueBreeze.deviceConnect
|
|
134
|
+
|
|
135
|
+
const deviceDisconnect = NativeBlueBreeze.deviceDisconnect
|
|
136
|
+
|
|
137
|
+
const deviceDiscoverServices = NativeBlueBreeze.deviceDiscoverServices
|
|
138
|
+
|
|
139
|
+
const deviceRequestMTU = NativeBlueBreeze.deviceRequestMTU
|
|
140
|
+
|
|
141
|
+
// Device characteristic notify enabled
|
|
142
|
+
|
|
143
|
+
const _deviceCharacteristicNotifyEnabled = new Map<string, Map<string, Map<string, StateEventEmitter<boolean>>>>()
|
|
144
|
+
|
|
145
|
+
const deviceCharacteristicNotifyEnabled = (
|
|
146
|
+
id: string,
|
|
147
|
+
serviceId: string,
|
|
148
|
+
characteristicId: string
|
|
149
|
+
): StateEventEmitter<boolean> => {
|
|
150
|
+
const deviceMap = mapGetOrSet(
|
|
151
|
+
_deviceCharacteristicNotifyEnabled,
|
|
152
|
+
id,
|
|
153
|
+
() => new Map<string, Map<string, StateEventEmitter<boolean>>>()
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
const serviceMap = mapGetOrSet(
|
|
157
|
+
deviceMap,
|
|
158
|
+
serviceId,
|
|
159
|
+
() => new Map<string, StateEventEmitter<boolean>>()
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
return mapGetOrSet(
|
|
163
|
+
serviceMap,
|
|
164
|
+
characteristicId,
|
|
165
|
+
() => new StateEventEmitter<boolean>(
|
|
166
|
+
NativeBlueBreeze.deviceCharacteristicNotifyEnabled(id, serviceId, characteristicId)
|
|
167
|
+
)
|
|
168
|
+
)
|
|
54
169
|
}
|
|
55
170
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
171
|
+
NativeBlueBreeze.deviceCharacteristicNotifyEnabledEmitter((value) => {
|
|
172
|
+
deviceCharacteristicNotifyEnabled(value.id, value.serviceId, value.characteristicId).add(value.value)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
// Device characteristic data
|
|
176
|
+
|
|
177
|
+
const _deviceCharacteristicData = new Map<string, Map<string, Map<string, StateEventEmitter<number[]>>>>()
|
|
178
|
+
|
|
179
|
+
const deviceCharacteristicData = (
|
|
180
|
+
id: string,
|
|
181
|
+
serviceId: string,
|
|
182
|
+
characteristicId: string
|
|
183
|
+
): StateEventEmitter<number[]> => {
|
|
184
|
+
const deviceMap = mapGetOrSet(
|
|
185
|
+
_deviceCharacteristicData,
|
|
186
|
+
id,
|
|
187
|
+
() => new Map<string, Map<string, StateEventEmitter<number[]>>>()
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
const serviceMap = mapGetOrSet(
|
|
191
|
+
deviceMap,
|
|
192
|
+
serviceId,
|
|
193
|
+
() => new Map<string, StateEventEmitter<number[]>>()
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
return mapGetOrSet(
|
|
197
|
+
serviceMap,
|
|
198
|
+
characteristicId,
|
|
199
|
+
() => new StateEventEmitter<number[]>(
|
|
200
|
+
NativeBlueBreeze.deviceCharacteristicData(id, serviceId, characteristicId)
|
|
201
|
+
)
|
|
202
|
+
)
|
|
61
203
|
}
|
|
62
204
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
205
|
+
NativeBlueBreeze.deviceCharacteristicDataEmitter((value) => {
|
|
206
|
+
deviceCharacteristicData(value.id, value.serviceId, value.characteristicId).add(value.value)
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
// Device characteristic operations
|
|
210
|
+
|
|
211
|
+
const deviceCharacteristicRead = NativeBlueBreeze.deviceCharacteristicRead
|
|
212
|
+
|
|
213
|
+
const deviceCharacteristicWrite = NativeBlueBreeze.deviceCharacteristicWrite
|
|
214
|
+
|
|
215
|
+
const deviceCharacteristicSubscribe = NativeBlueBreeze.deviceCharacteristicSubscribe
|
|
216
|
+
|
|
217
|
+
const deviceCharacteristicUnsubscribe = NativeBlueBreeze.deviceCharacteristicUnsubscribe
|
|
218
|
+
|
|
219
|
+
// Map helper
|
|
220
|
+
|
|
221
|
+
function mapGetOrSet<T>(map: Map<string, T>, key: string, defaultValue: () => T): T {
|
|
222
|
+
if (map.get(key) == undefined) {
|
|
223
|
+
map.set(key, defaultValue())
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return map.get(key)!
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Object decoders
|
|
230
|
+
|
|
231
|
+
const convertDevice = (device: SpecDevice): BBDevice => {
|
|
232
|
+
return new BBDevice(
|
|
233
|
+
device.id,
|
|
234
|
+
device.name
|
|
235
|
+
)
|
|
88
236
|
}
|
|
89
237
|
|
|
90
|
-
|
|
91
|
-
|
|
238
|
+
const convertScanResult = (
|
|
239
|
+
device: BBDevice,
|
|
240
|
+
scanResult: SpecScanResult,
|
|
241
|
+
): BBScanResult => {
|
|
242
|
+
return new BBScanResult(
|
|
243
|
+
device,
|
|
244
|
+
scanResult.name,
|
|
245
|
+
scanResult.rssi,
|
|
246
|
+
scanResult.connectable,
|
|
247
|
+
scanResult.advertisedServices,
|
|
248
|
+
scanResult.manufacturerId,
|
|
249
|
+
scanResult.manufacturerName,
|
|
250
|
+
scanResult.manufacturerData,
|
|
251
|
+
)
|
|
92
252
|
}
|
|
93
253
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
254
|
+
const convertDeviceService = (
|
|
255
|
+
deviceId: string,
|
|
256
|
+
service: SpecDeviceService
|
|
257
|
+
): BBService => {
|
|
258
|
+
return new BBService(
|
|
259
|
+
service.id,
|
|
260
|
+
service.name,
|
|
261
|
+
service.characteristics.map(
|
|
262
|
+
(c) => convertDeviceCharacteristic(deviceId, service.id, c)
|
|
263
|
+
)
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const convertDeviceCharacteristic = (
|
|
268
|
+
deviceId: string,
|
|
269
|
+
serviceId: string,
|
|
270
|
+
characteristic: SpecDeviceCharacteristic
|
|
271
|
+
): BBCharacteristic => {
|
|
272
|
+
return new BBCharacteristic(
|
|
273
|
+
deviceId,
|
|
274
|
+
serviceId,
|
|
275
|
+
characteristic.id,
|
|
276
|
+
characteristic.name,
|
|
277
|
+
characteristic.properties,
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Export
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
export default {
|
|
285
|
+
state,
|
|
286
|
+
authorizationStatus,
|
|
287
|
+
authorizationRequest,
|
|
288
|
+
authorizationOpenSettings,
|
|
289
|
+
scanEnabled,
|
|
290
|
+
scanResults,
|
|
291
|
+
scanStart,
|
|
292
|
+
scanStop,
|
|
293
|
+
devices,
|
|
294
|
+
deviceServices,
|
|
295
|
+
deviceConnectionStatus,
|
|
296
|
+
deviceMTU,
|
|
297
|
+
deviceConnect,
|
|
298
|
+
deviceDisconnect,
|
|
299
|
+
deviceDiscoverServices,
|
|
300
|
+
deviceRequestMTU,
|
|
301
|
+
deviceCharacteristicNotifyEnabled,
|
|
302
|
+
deviceCharacteristicData,
|
|
303
|
+
deviceCharacteristicRead,
|
|
304
|
+
deviceCharacteristicWrite,
|
|
305
|
+
deviceCharacteristicSubscribe,
|
|
306
|
+
deviceCharacteristicUnsubscribe,
|
|
307
|
+
}
|