react-native-bluebreeze 1.0.1 → 1.1.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.
- package/README.md +31 -4
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/bluebreeze/BlueBreezeModule.kt +15 -14
- package/ios/BlueBreezeImpl.swift +14 -14
- package/lib/commonjs/implementation/bluebreeze_characteristic.js +5 -2
- package/lib/commonjs/implementation/bluebreeze_characteristic.js.map +1 -1
- package/lib/commonjs/implementation/bluebreeze_observable.js +53 -0
- package/lib/commonjs/implementation/bluebreeze_observable.js.map +1 -0
- package/lib/commonjs/implementation/native_bridge.js +18 -18
- package/lib/commonjs/implementation/native_bridge.js.map +1 -1
- package/lib/commonjs/index.js +11 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/implementation/bluebreeze_characteristic.js +5 -2
- package/lib/module/implementation/bluebreeze_characteristic.js.map +1 -1
- package/lib/module/implementation/bluebreeze_observable.js +49 -0
- package/lib/module/implementation/bluebreeze_observable.js.map +1 -0
- package/lib/module/implementation/native_bridge.js +17 -17
- package/lib/module/implementation/native_bridge.js.map +1 -1
- package/lib/module/index.js +7 -6
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts +7 -4
- package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts +4 -4
- package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_observable.d.ts +32 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_observable.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/implementation/native_bridge.d.ts +6 -6
- package/lib/typescript/commonjs/src/implementation/native_bridge.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +7 -6
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts +7 -4
- package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts +4 -4
- package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_observable.d.ts +32 -0
- package/lib/typescript/module/src/implementation/bluebreeze_observable.d.ts.map +1 -0
- package/lib/typescript/module/src/implementation/native_bridge.d.ts +6 -6
- package/lib/typescript/module/src/implementation/native_bridge.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +7 -6
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/react-native-bluebreeze.podspec +1 -1
- package/src/implementation/bluebreeze_characteristic.ts +9 -5
- package/src/implementation/bluebreeze_device.ts +4 -4
- package/src/implementation/bluebreeze_observable.ts +48 -0
- package/src/implementation/native_bridge.ts +32 -32
- package/src/index.tsx +7 -5
package/README.md
CHANGED
|
@@ -12,9 +12,11 @@ correlation, per-device request queuing -- happens natively; from JS you just ob
|
|
|
12
12
|
`await` operations.
|
|
13
13
|
|
|
14
14
|
- **Reactive state** -- adapter power, authorization, discovered devices, connection status,
|
|
15
|
-
services, and characteristic data are all exposed as
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
services, and characteristic data are all exposed as `BBObservable`s: read the current
|
|
16
|
+
`.value` synchronously, subscribe to `.values` (the current value, then new ones), or only to
|
|
17
|
+
`.updates`. Streams are
|
|
18
|
+
[`react-native-value-emitter`](https://github.com/like-magic-dev/react-native-value-emitter)
|
|
19
|
+
emitters you subscribe to with `.onValue(...)`.
|
|
18
20
|
- **Promise-based operations** -- connect, discover services, read, write, and
|
|
19
21
|
subscribe/unsubscribe are all `async` calls with a built-in timeout on both platforms; no
|
|
20
22
|
native callbacks to correlate yourself.
|
|
@@ -73,7 +75,7 @@ if (BlueBreeze.authorizationStatus.value !== 'authorized') {
|
|
|
73
75
|
BlueBreeze.authorizationRequest()
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
BlueBreeze.state.onValue((state) => {
|
|
78
|
+
BlueBreeze.state.values.onValue((state) => {
|
|
77
79
|
if (state === 'poweredOn') {
|
|
78
80
|
BlueBreeze.scanStart()
|
|
79
81
|
}
|
|
@@ -105,6 +107,31 @@ async function connectToFirstDevice() {
|
|
|
105
107
|
}
|
|
106
108
|
```
|
|
107
109
|
|
|
110
|
+
### Observing state
|
|
111
|
+
|
|
112
|
+
Every piece of state is a `BBObservable`, which you can query in three ways:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
characteristic.data.value // the current value
|
|
116
|
+
characteristic.data.values.onValue((data) => {}) // the current value, then new values
|
|
117
|
+
characteristic.data.updates.onValue((data) => {}) // only values that arrive from now on
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
For example, to receive notifications:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const subscription = characteristic.data.updates.onValue((data) => {
|
|
124
|
+
console.log(characteristic.id, data)
|
|
125
|
+
})
|
|
126
|
+
await characteristic.subscribe()
|
|
127
|
+
|
|
128
|
+
// Later
|
|
129
|
+
subscription.remove()
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
In React components, `useValueEmitter(handler, observable.values)` from
|
|
133
|
+
`react-native-value-emitter` removes the subscription automatically on unmount.
|
|
134
|
+
|
|
108
135
|
See [`example`](example) for a full app built on top of BlueBreeze.
|
|
109
136
|
|
|
110
137
|
## Documentation
|
package/android/build.gradle
CHANGED
|
@@ -107,7 +107,7 @@ dependencies {
|
|
|
107
107
|
implementation "com.facebook.react:react-android"
|
|
108
108
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
109
109
|
|
|
110
|
-
implementation "dev.likemagic:bluebreeze:1.0
|
|
110
|
+
implementation "dev.likemagic:bluebreeze:1.1.0"
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
if (isNewArchitectureEnabled()) {
|
|
@@ -23,8 +23,8 @@ import kotlinx.coroutines.Dispatchers
|
|
|
23
23
|
import kotlinx.coroutines.Job
|
|
24
24
|
import kotlinx.coroutines.SupervisorJob
|
|
25
25
|
import kotlinx.coroutines.cancel
|
|
26
|
+
import kotlinx.coroutines.flow.Flow
|
|
26
27
|
import kotlinx.coroutines.flow.FlowCollector
|
|
27
|
-
import kotlinx.coroutines.flow.SharedFlow
|
|
28
28
|
import kotlinx.coroutines.launch
|
|
29
29
|
|
|
30
30
|
@ReactModule(name = BlueBreezeModule.NAME)
|
|
@@ -42,14 +42,14 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
42
42
|
|
|
43
43
|
// Per characteristic data and notification state subscriptions
|
|
44
44
|
val characteristicDataJobs = mutableMapOf<String, Job>()
|
|
45
|
-
val
|
|
45
|
+
val characteristicIsNotifyingJobs = mutableMapOf<String, Job>()
|
|
46
46
|
|
|
47
47
|
fun cancelCharacteristics() {
|
|
48
48
|
characteristicDataJobs.values.forEach { it.cancel() }
|
|
49
49
|
characteristicDataJobs.clear()
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
characteristicIsNotifyingJobs.values.forEach { it.cancel() }
|
|
52
|
+
characteristicIsNotifyingJobs.clear()
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
fun cancelAll() {
|
|
@@ -69,7 +69,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
69
69
|
|
|
70
70
|
// State
|
|
71
71
|
|
|
72
|
-
manager.state.collectAsync {
|
|
72
|
+
manager.state.values.collectAsync {
|
|
73
73
|
safeEmit {
|
|
74
74
|
emitStateEmitter(it.name)
|
|
75
75
|
}
|
|
@@ -77,7 +77,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
77
77
|
|
|
78
78
|
// Authorization
|
|
79
79
|
|
|
80
|
-
manager.authorizationStatus.collectAsync {
|
|
80
|
+
manager.authorizationStatus.values.collectAsync {
|
|
81
81
|
safeEmit {
|
|
82
82
|
emitAuthorizationStatusEmitter(it.toJs)
|
|
83
83
|
}
|
|
@@ -85,7 +85,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
85
85
|
|
|
86
86
|
// Scanning
|
|
87
87
|
|
|
88
|
-
manager.scanEnabled.collectAsync {
|
|
88
|
+
manager.scanEnabled.values.collectAsync {
|
|
89
89
|
safeEmit {
|
|
90
90
|
emitScanEnabledEmitter(it)
|
|
91
91
|
}
|
|
@@ -99,7 +99,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
99
99
|
|
|
100
100
|
// Devices
|
|
101
101
|
|
|
102
|
-
manager.devices.collectAsync { devices ->
|
|
102
|
+
manager.devices.values.collectAsync { devices ->
|
|
103
103
|
safeEmit {
|
|
104
104
|
emitDevicesEmitter(
|
|
105
105
|
devices.map { it.value.toJs }.writableArray
|
|
@@ -123,7 +123,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
123
123
|
private fun setupDeviceTracking(deviceId: String, device: BBDevice, tracking: DeviceTracking) {
|
|
124
124
|
if (tracking.deviceJobs.isNotEmpty()) return
|
|
125
125
|
|
|
126
|
-
tracking.deviceJobs += device.services.collectAsync { services ->
|
|
126
|
+
tracking.deviceJobs += device.services.values.collectAsync { services ->
|
|
127
127
|
safeEmit {
|
|
128
128
|
emitDeviceServicesEmitter(
|
|
129
129
|
writableMapOf(
|
|
@@ -136,7 +136,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
136
136
|
setupDeviceCharacteristics(deviceId, services, tracking)
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
tracking.deviceJobs += device.connectionStatus.collectAsync { value ->
|
|
139
|
+
tracking.deviceJobs += device.connectionStatus.values.collectAsync { value ->
|
|
140
140
|
safeEmit {
|
|
141
141
|
emitDeviceConnectionStatusEmitter(
|
|
142
142
|
writableMapOf(
|
|
@@ -147,7 +147,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
tracking.deviceJobs += device.mtu.collectAsync { value ->
|
|
150
|
+
tracking.deviceJobs += device.mtu.values.collectAsync { value ->
|
|
151
151
|
safeEmit {
|
|
152
152
|
emitDeviceMTUEmitter(
|
|
153
153
|
writableMapOf(
|
|
@@ -170,7 +170,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
170
170
|
val characteristicId = characteristic.uuid
|
|
171
171
|
val trackingKey = "${serviceId}:${characteristicId}"
|
|
172
172
|
|
|
173
|
-
tracking.characteristicDataJobs[trackingKey] = characteristic.data.collectAsync { value ->
|
|
173
|
+
tracking.characteristicDataJobs[trackingKey] = characteristic.data.values.collectAsync { value ->
|
|
174
174
|
safeEmit {
|
|
175
175
|
emitDeviceCharacteristicDataEmitter(
|
|
176
176
|
writableMapOf(
|
|
@@ -183,7 +183,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
tracking.
|
|
186
|
+
tracking.characteristicIsNotifyingJobs[trackingKey] = characteristic.isNotifying.values.collectAsync { value ->
|
|
187
187
|
safeEmit {
|
|
188
188
|
emitDeviceCharacteristicNotifyEnabledEmitter(
|
|
189
189
|
writableMapOf(
|
|
@@ -526,7 +526,7 @@ class BlueBreezeModule(reactContext: ReactApplicationContext) : NativeBlueBreeze
|
|
|
526
526
|
block: suspend CoroutineScope.() -> Unit,
|
|
527
527
|
): Job = moduleScope.launch(block = block)
|
|
528
528
|
|
|
529
|
-
private fun <T>
|
|
529
|
+
private fun <T> Flow<T>.collectAsync(
|
|
530
530
|
collector: FlowCollector<T>,
|
|
531
531
|
): Job = moduleScope.launch { collect(collector) }
|
|
532
532
|
|
|
@@ -569,6 +569,7 @@ val BBCharacteristicProperty.toJs: String
|
|
|
569
569
|
val BBScanResult.toJs: WritableMap
|
|
570
570
|
get() = writableMapOf(
|
|
571
571
|
"id" to device.address,
|
|
572
|
+
"name" to name,
|
|
572
573
|
"rssi" to rssi,
|
|
573
574
|
"connectable" to connectable,
|
|
574
575
|
"advertisedServices" to advertisedServices.map { it.toJs },
|
package/ios/BlueBreezeImpl.swift
CHANGED
|
@@ -30,7 +30,7 @@ struct BlueBreezeError : Error {
|
|
|
30
30
|
var deviceMTUObserve: ((String, Int) -> Void)?
|
|
31
31
|
var deviceCharacteristicDataObserve: ((String, String, String, Array<UInt8>) -> Void)?
|
|
32
32
|
var deviceCharacteristicNotifyEnabledObserve: ((String, String, String, Bool) -> Void)?
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
@objc public func subscribe(
|
|
35
35
|
stateObserve: (@escaping (String) -> Void),
|
|
36
36
|
authorizationObserve: (@escaping (String) -> Void),
|
|
@@ -54,17 +54,17 @@ struct BlueBreezeError : Error {
|
|
|
54
54
|
self.deviceCharacteristicDataObserve = deviceCharacteristicDataObserve
|
|
55
55
|
self.deviceCharacteristicNotifyEnabledObserve = deviceCharacteristicNotifyEnabledObserve
|
|
56
56
|
|
|
57
|
-
manager.state
|
|
57
|
+
manager.state.values
|
|
58
58
|
.receive(on: DispatchQueue.main)
|
|
59
59
|
.sink { self.stateObserve?($0.toJs) }
|
|
60
60
|
.store(in: &disposeBag)
|
|
61
61
|
|
|
62
|
-
manager.authorizationStatus
|
|
62
|
+
manager.authorizationStatus.values
|
|
63
63
|
.receive(on: DispatchQueue.main)
|
|
64
64
|
.sink { self.authorizationObserve?($0.toJs) }
|
|
65
65
|
.store(in: &disposeBag)
|
|
66
66
|
|
|
67
|
-
manager.scanEnabled
|
|
67
|
+
manager.scanEnabled.values
|
|
68
68
|
.receive(on: DispatchQueue.main)
|
|
69
69
|
.sink { self.scanEnabledObserve?($0) }
|
|
70
70
|
.store(in: &disposeBag)
|
|
@@ -74,7 +74,7 @@ struct BlueBreezeError : Error {
|
|
|
74
74
|
.sink { self.scanResultsObserve?($0.toJs) }
|
|
75
75
|
.store(in: &disposeBag)
|
|
76
76
|
|
|
77
|
-
manager.devices
|
|
77
|
+
manager.devices.values
|
|
78
78
|
.receive(on: DispatchQueue.main)
|
|
79
79
|
.sink {
|
|
80
80
|
$0.forEach { (id, device) in
|
|
@@ -92,12 +92,12 @@ struct BlueBreezeError : Error {
|
|
|
92
92
|
|
|
93
93
|
disposeBagDevices[device.id] = []
|
|
94
94
|
|
|
95
|
-
device.connectionStatus
|
|
95
|
+
device.connectionStatus.values
|
|
96
96
|
.receive(on: DispatchQueue.main)
|
|
97
97
|
.sink { self.deviceConnectionStatusObserve?(device.id.toJs, $0.toJs) }
|
|
98
98
|
.store(in: &disposeBagDevices[device.id]!)
|
|
99
99
|
|
|
100
|
-
device.services
|
|
100
|
+
device.services.values
|
|
101
101
|
.receive(on: DispatchQueue.main)
|
|
102
102
|
.sink {
|
|
103
103
|
self.subscribeServices(device, $0)
|
|
@@ -105,7 +105,7 @@ struct BlueBreezeError : Error {
|
|
|
105
105
|
}
|
|
106
106
|
.store(in: &disposeBagDevices[device.id]!)
|
|
107
107
|
|
|
108
|
-
device.mtu
|
|
108
|
+
device.mtu.values
|
|
109
109
|
.receive(on: DispatchQueue.main)
|
|
110
110
|
.sink { self.deviceMTUObserve?(device.id.toJs, $0) }
|
|
111
111
|
.store(in: &disposeBagDevices[device.id]!)
|
|
@@ -136,26 +136,26 @@ struct BlueBreezeError : Error {
|
|
|
136
136
|
|
|
137
137
|
disposeBagServices[device.id]![serviceId]![characteristic.uuid] = []
|
|
138
138
|
|
|
139
|
-
characteristic.
|
|
139
|
+
characteristic.data.values
|
|
140
140
|
.receive(on: DispatchQueue.main)
|
|
141
141
|
.sink {
|
|
142
|
-
self.
|
|
142
|
+
self.deviceCharacteristicDataObserve?(
|
|
143
143
|
device.id.toJs,
|
|
144
144
|
serviceId.toJs,
|
|
145
145
|
characteristic.uuid.toJs,
|
|
146
|
-
$0
|
|
146
|
+
$0?.toJs ?? []
|
|
147
147
|
)
|
|
148
148
|
}
|
|
149
149
|
.store(in: &disposeBagServices[device.id]![serviceId]![characteristic.uuid]!)
|
|
150
150
|
|
|
151
|
-
characteristic.
|
|
151
|
+
characteristic.isNotifying.values
|
|
152
152
|
.receive(on: DispatchQueue.main)
|
|
153
153
|
.sink {
|
|
154
|
-
self.
|
|
154
|
+
self.deviceCharacteristicNotifyEnabledObserve?(
|
|
155
155
|
device.id.toJs,
|
|
156
156
|
serviceId.toJs,
|
|
157
157
|
characteristic.uuid.toJs,
|
|
158
|
-
$0
|
|
158
|
+
$0
|
|
159
159
|
)
|
|
160
160
|
}
|
|
161
161
|
.store(in: &disposeBagServices[device.id]![serviceId]![characteristic.uuid]!)
|
|
@@ -17,7 +17,7 @@ class BBCharacteristic {
|
|
|
17
17
|
this.name = name;
|
|
18
18
|
this.properties = properties;
|
|
19
19
|
this.data = (0, _native_bridge.deviceCharacteristicData)(deviceId, serviceId, id);
|
|
20
|
-
this.
|
|
20
|
+
this.isNotifying = (0, _native_bridge.deviceCharacteristicNotifyEnabled)(deviceId, serviceId, id);
|
|
21
21
|
this.read = () => (0, _native_bridge.deviceCharacteristicRead)(deviceId, serviceId, id);
|
|
22
22
|
this.write = (data, withResponse) => (0, _native_bridge.deviceCharacteristicWrite)(deviceId, serviceId, id, data, withResponse);
|
|
23
23
|
this.subscribe = () => (0, _native_bridge.deviceCharacteristicSubscribe)(deviceId, serviceId, id);
|
|
@@ -30,7 +30,10 @@ class BBCharacteristic {
|
|
|
30
30
|
|
|
31
31
|
/** The GATT properties this characteristic declares. */
|
|
32
32
|
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* The last value read or notified for this characteristic. Empty until first populated.
|
|
35
|
+
* Use `data.updates` to receive only the values that arrive from now on.
|
|
36
|
+
*/
|
|
34
37
|
|
|
35
38
|
/** Whether this app is currently subscribed to notifications for this characteristic. */
|
|
36
39
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_native_bridge","require","BBCharacteristic","constructor","deviceId","serviceId","id","name","properties","data","deviceCharacteristicData","
|
|
1
|
+
{"version":3,"names":["_native_bridge","require","BBCharacteristic","constructor","deviceId","serviceId","id","name","properties","data","deviceCharacteristicData","isNotifying","deviceCharacteristicNotifyEnabled","read","deviceCharacteristicRead","write","withResponse","deviceCharacteristicWrite","subscribe","deviceCharacteristicSubscribe","unsubscribe","deviceCharacteristicUnsubscribe","exports"],"sourceRoot":"../../../src","sources":["implementation/bluebreeze_characteristic.ts"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AASA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CACPC,QAAgB,EAChBC,SAAiB,EACjBC,EAAU,EACVC,IAAwB,EACxBC,UAAoB,EACtB;IACE,IAAI,CAACF,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,UAAU,GAAGA,UAAU;IAE5B,IAAI,CAACC,IAAI,GAAG,IAAAC,uCAAwB,EAACN,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;IAE7D,IAAI,CAACK,WAAW,GAAG,IAAAC,gDAAiC,EAACR,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;IAE7E,IAAI,CAACO,IAAI,GAAG,MAAM,IAAAC,uCAAwB,EAACV,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;IACnE,IAAI,CAACS,KAAK,GAAG,CAACN,IAAc,EAAEO,YAAqB,KAAK,IAAAC,wCAAyB,EAACb,QAAQ,EAAEC,SAAS,EAAEC,EAAE,EAAEG,IAAI,EAAEO,YAAY,CAAC;IAC9H,IAAI,CAACE,SAAS,GAAG,MAAM,IAAAC,4CAA6B,EAACf,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;IAC7E,IAAI,CAACc,WAAW,GAAG,MAAM,IAAAC,8CAA+B,EAACjB,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;EACrF;;EAEA;;EAGA;;EAGA;;EAGA;AACJ;AACA;AACA;;EAGI;;EAGA;AACJ;AACA;AACA;;EAGI;AACJ;AACA;AACA;AACA;AACA;;EAGI;AACJ;AACA;AACA;;EAGI;AACJ;AACA;AACA;AAEA;AAACgB,OAAA,CAAApB,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BBObservable = void 0;
|
|
7
|
+
var _reactNativeValueEmitter = require("react-native-value-emitter");
|
|
8
|
+
/**
|
|
9
|
+
* An observable value, used for every piece of state BlueBreeze exposes (`BlueBreeze.state`,
|
|
10
|
+
* {@link BBDevice.connectionStatus}, {@link BBCharacteristic.data}, and so on).
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* characteristic.data.value // the current value
|
|
14
|
+
* characteristic.data.values.onValue((data) => {}) // the current value, then new values
|
|
15
|
+
* characteristic.data.updates.onValue((data) => {}) // only new values
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Streams work with `useValueEmitter` from `react-native-value-emitter`, which unsubscribes
|
|
19
|
+
* automatically when the component unmounts.
|
|
20
|
+
*/
|
|
21
|
+
class BBObservable {
|
|
22
|
+
constructor(initialValue) {
|
|
23
|
+
this._values = new _reactNativeValueEmitter.StateValueEmitter(initialValue);
|
|
24
|
+
}
|
|
25
|
+
_updates = new _reactNativeValueEmitter.ValueEmitter();
|
|
26
|
+
|
|
27
|
+
/** The current value. */
|
|
28
|
+
get value() {
|
|
29
|
+
return this._values.value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A stream that calls each handler with the current {@link value} first, then with every new one. */
|
|
33
|
+
get values() {
|
|
34
|
+
return this._values;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A stream of only the values published from now on, without the current {@link value}. */
|
|
38
|
+
get updates() {
|
|
39
|
+
return this._updates;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Publishes a new value. Internal to BlueBreeze: called when the native module reports an
|
|
44
|
+
* update, not meant to be called by apps.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
add(value) {
|
|
48
|
+
this._values.add(value);
|
|
49
|
+
this._updates.add(value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.BBObservable = BBObservable;
|
|
53
|
+
//# sourceMappingURL=bluebreeze_observable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNativeValueEmitter","require","BBObservable","constructor","initialValue","_values","StateValueEmitter","_updates","ValueEmitter","value","values","updates","add","exports"],"sourceRoot":"../../../src","sources":["implementation/bluebreeze_observable.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,YAAY,CAAI;EACzBC,WAAWA,CAACC,YAAe,EAAE;IACzB,IAAI,CAACC,OAAO,GAAG,IAAIC,0CAAiB,CAAIF,YAAY,CAAC;EACzD;EAGiBG,QAAQ,GAAG,IAAIC,qCAAY,CAAI,CAAC;;EAEjD;EACA,IAAIC,KAAKA,CAAA,EAAM;IACX,OAAO,IAAI,CAACJ,OAAO,CAACI,KAAK;EAC7B;;EAEA;EACA,IAAIC,MAAMA,CAAA,EAAoB;IAC1B,OAAO,IAAI,CAACL,OAAO;EACvB;;EAEA;EACA,IAAIM,OAAOA,CAAA,EAAoB;IAC3B,OAAO,IAAI,CAACJ,QAAQ;EACxB;;EAEA;AACJ;AACA;AACA;AACA;EACIK,GAAGA,CAACH,KAAQ,EAAE;IACV,IAAI,CAACJ,OAAO,CAACO,GAAG,CAACH,KAAK,CAAC;IACvB,IAAI,CAACF,QAAQ,CAACK,GAAG,CAACH,KAAK,CAAC;EAC5B;AACJ;AAACI,OAAA,CAAAX,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.deviceServices = exports.deviceRequestMTU = exports.deviceMTU = exports.deviceDiscoverServices = exports.deviceDisconnect = exports.deviceConnectionStatus = exports.deviceConnect = exports.deviceCharacteristicWrite = exports.deviceCharacteristicUnsubscribe = exports.deviceCharacteristicSubscribe = exports.deviceCharacteristicRead = exports.deviceCharacteristicNotifyEnabled = exports.deviceCharacteristicData = void 0;
|
|
7
|
-
var _reactNativeValueEmitter = require("react-native-value-emitter");
|
|
8
7
|
var _NativeBlueBreeze = _interopRequireDefault(require("../NativeBlueBreeze.js"));
|
|
9
8
|
var _bluebreeze_characteristic = require("./bluebreeze_characteristic.js");
|
|
9
|
+
var _bluebreeze_observable = require("./bluebreeze_observable.js");
|
|
10
10
|
var _bluebreeze_service = require("./bluebreeze_service.js");
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
/**
|
|
@@ -28,7 +28,7 @@ function mapGetOrSet(map, key, defaultValue) {
|
|
|
28
28
|
|
|
29
29
|
const _deviceServices = new Map();
|
|
30
30
|
const deviceServices = id => {
|
|
31
|
-
return mapGetOrSet(_deviceServices, id, () => new
|
|
31
|
+
return mapGetOrSet(_deviceServices, id, () => new _bluebreeze_observable.BBObservable(_NativeBlueBreeze.default.deviceServices(id).map(s => convertDeviceService(id, s))));
|
|
32
32
|
};
|
|
33
33
|
exports.deviceServices = deviceServices;
|
|
34
34
|
_NativeBlueBreeze.default.deviceServicesEmitter(value => {
|
|
@@ -39,7 +39,7 @@ _NativeBlueBreeze.default.deviceServicesEmitter(value => {
|
|
|
39
39
|
|
|
40
40
|
const _deviceConnectionStatus = new Map();
|
|
41
41
|
const deviceConnectionStatus = id => {
|
|
42
|
-
return mapGetOrSet(_deviceConnectionStatus, id, () => new
|
|
42
|
+
return mapGetOrSet(_deviceConnectionStatus, id, () => new _bluebreeze_observable.BBObservable(_NativeBlueBreeze.default.deviceConnectionStatus(id)));
|
|
43
43
|
};
|
|
44
44
|
exports.deviceConnectionStatus = deviceConnectionStatus;
|
|
45
45
|
_NativeBlueBreeze.default.deviceConnectionStatusEmitter(value => {
|
|
@@ -50,7 +50,7 @@ _NativeBlueBreeze.default.deviceConnectionStatusEmitter(value => {
|
|
|
50
50
|
|
|
51
51
|
const _deviceMTU = new Map();
|
|
52
52
|
const deviceMTU = id => {
|
|
53
|
-
return mapGetOrSet(_deviceMTU, id, () => new
|
|
53
|
+
return mapGetOrSet(_deviceMTU, id, () => new _bluebreeze_observable.BBObservable(_NativeBlueBreeze.default.deviceMTU(id)));
|
|
54
54
|
};
|
|
55
55
|
exports.deviceMTU = deviceMTU;
|
|
56
56
|
_NativeBlueBreeze.default.deviceMTUEmitter(value => {
|
|
@@ -64,32 +64,32 @@ const deviceDisconnect = exports.deviceDisconnect = _NativeBlueBreeze.default.de
|
|
|
64
64
|
const deviceDiscoverServices = exports.deviceDiscoverServices = _NativeBlueBreeze.default.deviceDiscoverServices;
|
|
65
65
|
const deviceRequestMTU = exports.deviceRequestMTU = _NativeBlueBreeze.default.deviceRequestMTU;
|
|
66
66
|
|
|
67
|
-
// Device characteristic notify enabled
|
|
68
|
-
|
|
69
|
-
const _deviceCharacteristicNotifyEnabled = new Map();
|
|
70
|
-
const deviceCharacteristicNotifyEnabled = (id, serviceId, characteristicId) => {
|
|
71
|
-
const deviceMap = mapGetOrSet(_deviceCharacteristicNotifyEnabled, id, () => new Map());
|
|
72
|
-
const serviceMap = mapGetOrSet(deviceMap, serviceId, () => new Map());
|
|
73
|
-
return mapGetOrSet(serviceMap, characteristicId, () => new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.deviceCharacteristicNotifyEnabled(id, serviceId, characteristicId)));
|
|
74
|
-
};
|
|
75
|
-
exports.deviceCharacteristicNotifyEnabled = deviceCharacteristicNotifyEnabled;
|
|
76
|
-
_NativeBlueBreeze.default.deviceCharacteristicNotifyEnabledEmitter(value => {
|
|
77
|
-
deviceCharacteristicNotifyEnabled(value.id, value.serviceId, value.characteristicId).add(value.value);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
67
|
// Device characteristic data
|
|
81
68
|
|
|
82
69
|
const _deviceCharacteristicData = new Map();
|
|
83
70
|
const deviceCharacteristicData = (id, serviceId, characteristicId) => {
|
|
84
71
|
const deviceMap = mapGetOrSet(_deviceCharacteristicData, id, () => new Map());
|
|
85
72
|
const serviceMap = mapGetOrSet(deviceMap, serviceId, () => new Map());
|
|
86
|
-
return mapGetOrSet(serviceMap, characteristicId, () => new
|
|
73
|
+
return mapGetOrSet(serviceMap, characteristicId, () => new _bluebreeze_observable.BBObservable(_NativeBlueBreeze.default.deviceCharacteristicData(id, serviceId, characteristicId)));
|
|
87
74
|
};
|
|
88
75
|
exports.deviceCharacteristicData = deviceCharacteristicData;
|
|
89
76
|
_NativeBlueBreeze.default.deviceCharacteristicDataEmitter(value => {
|
|
90
77
|
deviceCharacteristicData(value.id, value.serviceId, value.characteristicId).add(value.value);
|
|
91
78
|
});
|
|
92
79
|
|
|
80
|
+
// Device characteristic notify enabled
|
|
81
|
+
|
|
82
|
+
const _deviceCharacteristicNotifyEnabled = new Map();
|
|
83
|
+
const deviceCharacteristicNotifyEnabled = (id, serviceId, characteristicId) => {
|
|
84
|
+
const deviceMap = mapGetOrSet(_deviceCharacteristicNotifyEnabled, id, () => new Map());
|
|
85
|
+
const serviceMap = mapGetOrSet(deviceMap, serviceId, () => new Map());
|
|
86
|
+
return mapGetOrSet(serviceMap, characteristicId, () => new _bluebreeze_observable.BBObservable(_NativeBlueBreeze.default.deviceCharacteristicNotifyEnabled(id, serviceId, characteristicId)));
|
|
87
|
+
};
|
|
88
|
+
exports.deviceCharacteristicNotifyEnabled = deviceCharacteristicNotifyEnabled;
|
|
89
|
+
_NativeBlueBreeze.default.deviceCharacteristicNotifyEnabledEmitter(value => {
|
|
90
|
+
deviceCharacteristicNotifyEnabled(value.id, value.serviceId, value.characteristicId).add(value.value);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
93
|
// Device characteristic operations
|
|
94
94
|
|
|
95
95
|
const deviceCharacteristicRead = exports.deviceCharacteristicRead = _NativeBlueBreeze.default.deviceCharacteristicRead;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_NativeBlueBreeze","_interopRequireDefault","require","_bluebreeze_characteristic","_bluebreeze_observable","_bluebreeze_service","e","__esModule","default","mapGetOrSet","map","key","defaultValue","get","undefined","set","_deviceServices","Map","deviceServices","id","BBObservable","NativeBlueBreeze","s","convertDeviceService","exports","deviceServicesEmitter","value","add","_deviceConnectionStatus","deviceConnectionStatus","deviceConnectionStatusEmitter","_deviceMTU","deviceMTU","deviceMTUEmitter","deviceConnect","deviceDisconnect","deviceDiscoverServices","deviceRequestMTU","_deviceCharacteristicData","deviceCharacteristicData","serviceId","characteristicId","deviceMap","serviceMap","deviceCharacteristicDataEmitter","_deviceCharacteristicNotifyEnabled","deviceCharacteristicNotifyEnabled","deviceCharacteristicNotifyEnabledEmitter","deviceCharacteristicRead","deviceCharacteristicWrite","deviceCharacteristicSubscribe","deviceCharacteristicUnsubscribe","deviceId","service","BBService","name","characteristics","c","convertDeviceCharacteristic","characteristic","BBCharacteristic","properties"],"sourceRoot":"../../../src","sources":["implementation/native_bridge.ts"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,0BAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAA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KAAK,CAACP,EAAE,EAAEO,KAAK,CAACc,SAAS,EAAEd,KAAK,CAACe,gBAAgB,CAAC,CAACd,GAAG,CAACD,KAAK,CAACA,KAAK,CAAC;AACzG,CAAC,CAAC;;AAEF;;AAEO,MAAMsB,wBAAwB,GAAAxB,OAAA,CAAAwB,wBAAA,GAAG3B,yBAAgB,CAAC2B,wBAAwB;AAE1E,MAAMC,yBAAyB,GAAAzB,OAAA,CAAAyB,yBAAA,GAAG5B,yBAAgB,CAAC4B,yBAAyB;AAE5E,MAAMC,6BAA6B,GAAA1B,OAAA,CAAA0B,6BAAA,GAAG7B,yBAAgB,CAAC6B,6BAA6B;AAEpF,MAAMC,+BAA+B,GAAA3B,OAAA,CAAA2B,+BAAA,GAAG9B,yBAAgB,CAAC8B,+BAA+B;;AAE/F;;AAEA,MAAM5B,oBAAoB,GAAGA,CACzB6B,QAAgB,EAChBC,OAA0B,KACd;EACZ,OAAO,IAAIC,6BAAS,CAChBD,OAAO,CAAClC,EAAE,EACVkC,OAAO,CAACE,IAAI,EACZF,OAAO,CAACG,eAAe,CAAC9C,GAAG,CACtB+C,CAAC,IAAKC,2BAA2B,CAACN,QAAQ,EAAEC,OAAO,CAAClC,EAAE,EAAEsC,CAAC,CAC9D,CACJ,CAAC;AACL,CAAC;AAED,MAAMC,2BAA2B,GAAGA,CAChCN,QAAgB,EAChBZ,SAAiB,EACjBmB,cAAwC,KACrB;EACnB,OAAO,IAAIC,2CAAgB,CACvBR,QAAQ,EACRZ,SAAS,EACTmB,cAAc,CAACxC,EAAE,EACjBwC,cAAc,CAACJ,IAAI,EACnBI,cAAc,CAACE,UACnB,CAAC;AACL,CAAC","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "BBDevice", {
|
|
|
15
15
|
return _bluebreeze_device.BBDevice;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "BBObservable", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _bluebreeze_observable.BBObservable;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "BBScanResult", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function () {
|
|
@@ -31,6 +37,7 @@ exports.default = void 0;
|
|
|
31
37
|
var _reactNativeValueEmitter = require("react-native-value-emitter");
|
|
32
38
|
var _bluebreeze_characteristic = require("./implementation/bluebreeze_characteristic.js");
|
|
33
39
|
var _bluebreeze_device = require("./implementation/bluebreeze_device.js");
|
|
40
|
+
var _bluebreeze_observable = require("./implementation/bluebreeze_observable.js");
|
|
34
41
|
var _bluebreeze_scan_result = require("./implementation/bluebreeze_scan_result.js");
|
|
35
42
|
var _bluebreeze_service = require("./implementation/bluebreeze_service.js");
|
|
36
43
|
var _NativeBlueBreeze = _interopRequireDefault(require("./NativeBlueBreeze.js"));
|
|
@@ -38,7 +45,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
38
45
|
// State
|
|
39
46
|
|
|
40
47
|
/** The power/availability state of the device's Bluetooth adapter. */
|
|
41
|
-
const state = new
|
|
48
|
+
const state = new _bluebreeze_observable.BBObservable(_NativeBlueBreeze.default.state());
|
|
42
49
|
_NativeBlueBreeze.default.stateEmitter(value => {
|
|
43
50
|
state.add(value);
|
|
44
51
|
});
|
|
@@ -46,7 +53,7 @@ _NativeBlueBreeze.default.stateEmitter(value => {
|
|
|
46
53
|
// Authorization to use BLE
|
|
47
54
|
|
|
48
55
|
/** Whether this app is currently allowed to use Bluetooth. */
|
|
49
|
-
const authorizationStatus = new
|
|
56
|
+
const authorizationStatus = new _bluebreeze_observable.BBObservable(_NativeBlueBreeze.default.authorizationStatus());
|
|
50
57
|
_NativeBlueBreeze.default.authorizationStatusEmitter(value => {
|
|
51
58
|
authorizationStatus.add(value);
|
|
52
59
|
});
|
|
@@ -60,7 +67,7 @@ const authorizationOpenSettings = _NativeBlueBreeze.default.authorizationOpenSet
|
|
|
60
67
|
// Scanning
|
|
61
68
|
|
|
62
69
|
/** Whether a BLE scan is currently running. */
|
|
63
|
-
const scanEnabled = new
|
|
70
|
+
const scanEnabled = new _bluebreeze_observable.BBObservable(_NativeBlueBreeze.default.scanEnabled());
|
|
64
71
|
_NativeBlueBreeze.default.scanEnabledEmitter(value => {
|
|
65
72
|
scanEnabled.add(value);
|
|
66
73
|
});
|
|
@@ -95,7 +102,7 @@ const scanStop = _NativeBlueBreeze.default.scanStop;
|
|
|
95
102
|
* platform device ID. A device is added here the moment it's first seen in a scan result and
|
|
96
103
|
* stays here for the app's lifetime.
|
|
97
104
|
*/
|
|
98
|
-
const devices = new
|
|
105
|
+
const devices = new _bluebreeze_observable.BBObservable(new Map(_NativeBlueBreeze.default.devices().map(d => [d.id, convertDevice(d)])));
|
|
99
106
|
_NativeBlueBreeze.default.devicesEmitter(value => {
|
|
100
107
|
devices.add(new Map(value.map(d => [d.id, devices.value?.get(d.id) ?? convertDevice(d)])));
|
|
101
108
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeValueEmitter","require","_bluebreeze_characteristic","_bluebreeze_device","_bluebreeze_scan_result","_bluebreeze_service","_NativeBlueBreeze","_interopRequireDefault","e","__esModule","default","state","
|
|
1
|
+
{"version":3,"names":["_reactNativeValueEmitter","require","_bluebreeze_characteristic","_bluebreeze_device","_bluebreeze_observable","_bluebreeze_scan_result","_bluebreeze_service","_NativeBlueBreeze","_interopRequireDefault","e","__esModule","default","state","BBObservable","NativeBlueBreeze","stateEmitter","value","add","authorizationStatus","authorizationStatusEmitter","authorizationRequest","authorizationOpenSettings","scanEnabled","scanEnabledEmitter","scanResults","ValueEmitter","scanResultEmitter","device","devices","get","id","undefined","convertDevice","Map","set","convertScanResult","scanStart","ids","scanStop","map","d","devicesEmitter","BBDevice","name","scanResult","BBScanResult","rssi","connectable","advertisedServices","manufacturerId","manufacturerName","manufacturerData","_default","exports"],"sourceRo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;AAEF;;AAEA,MAAMR,aAAa,GAAIL,MAAkB,IAAe;EACpD,OAAO,IAAIe,2BAAQ,CACff,MAAM,CAACG,EAAE,EACTH,MAAM,CAACgB,IACX,CAAC;AACL,CAAC;AAED,MAAMR,iBAAiB,GAAGA,CACtBR,MAAgB,EAChBiB,UAA0B,KACX;EACf,OAAO,IAAIC,oCAAY,CACnBlB,MAAM,EACNiB,UAAU,CAACD,IAAI,EACfC,UAAU,CAACE,IAAI,EACfF,UAAU,CAACG,WAAW,EACtBH,UAAU,CAACI,kBAAkB,EAC7BJ,UAAU,CAACK,cAAc,EACzBL,UAAU,CAACM,gBAAgB,EAC3BN,UAAU,CAACO,gBACf,CAAC;AACL,CAAC;;AAED;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAA1C,OAAA,GAEe;EACXC,KAAK;EACLM,mBAAmB;EACnBE,oBAAoB;EACpBC,yBAAyB;EACzBC,WAAW;EACXE,WAAW;EACXY,SAAS;EACTE,QAAQ;EACRV;AACJ,CAAC","ignoreList":[]}
|
|
@@ -14,7 +14,7 @@ export class BBCharacteristic {
|
|
|
14
14
|
this.name = name;
|
|
15
15
|
this.properties = properties;
|
|
16
16
|
this.data = deviceCharacteristicData(deviceId, serviceId, id);
|
|
17
|
-
this.
|
|
17
|
+
this.isNotifying = deviceCharacteristicNotifyEnabled(deviceId, serviceId, id);
|
|
18
18
|
this.read = () => deviceCharacteristicRead(deviceId, serviceId, id);
|
|
19
19
|
this.write = (data, withResponse) => deviceCharacteristicWrite(deviceId, serviceId, id, data, withResponse);
|
|
20
20
|
this.subscribe = () => deviceCharacteristicSubscribe(deviceId, serviceId, id);
|
|
@@ -27,7 +27,10 @@ export class BBCharacteristic {
|
|
|
27
27
|
|
|
28
28
|
/** The GATT properties this characteristic declares. */
|
|
29
29
|
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* The last value read or notified for this characteristic. Empty until first populated.
|
|
32
|
+
* Use `data.updates` to receive only the values that arrive from now on.
|
|
33
|
+
*/
|
|
31
34
|
|
|
32
35
|
/** Whether this app is currently subscribed to notifications for this characteristic. */
|
|
33
36
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["deviceCharacteristicData","deviceCharacteristicNotifyEnabled","deviceCharacteristicRead","deviceCharacteristicSubscribe","deviceCharacteristicUnsubscribe","deviceCharacteristicWrite","BBCharacteristic","constructor","deviceId","serviceId","id","name","properties","data","
|
|
1
|
+
{"version":3,"names":["deviceCharacteristicData","deviceCharacteristicNotifyEnabled","deviceCharacteristicRead","deviceCharacteristicSubscribe","deviceCharacteristicUnsubscribe","deviceCharacteristicWrite","BBCharacteristic","constructor","deviceId","serviceId","id","name","properties","data","isNotifying","read","write","withResponse","subscribe","unsubscribe"],"sourceRoot":"../../../src","sources":["implementation/bluebreeze_characteristic.ts"],"mappings":";;AACA,SACIA,wBAAwB,EACxBC,iCAAiC,EACjCC,wBAAwB,EACxBC,6BAA6B,EAC7BC,+BAA+B,EAC/BC,yBAAyB,QACtB,oBAAiB;;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CACPC,QAAgB,EAChBC,SAAiB,EACjBC,EAAU,EACVC,IAAwB,EACxBC,UAAoB,EACtB;IACE,IAAI,CAACF,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,UAAU,GAAGA,UAAU;IAE5B,IAAI,CAACC,IAAI,GAAGb,wBAAwB,CAACQ,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;IAE7D,IAAI,CAACI,WAAW,GAAGb,iCAAiC,CAACO,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;IAE7E,IAAI,CAACK,IAAI,GAAG,MAAMb,wBAAwB,CAACM,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;IACnE,IAAI,CAACM,KAAK,GAAG,CAACH,IAAc,EAAEI,YAAqB,KAAKZ,yBAAyB,CAACG,QAAQ,EAAEC,SAAS,EAAEC,EAAE,EAAEG,IAAI,EAAEI,YAAY,CAAC;IAC9H,IAAI,CAACC,SAAS,GAAG,MAAMf,6BAA6B,CAACK,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;IAC7E,IAAI,CAACS,WAAW,GAAG,MAAMf,+BAA+B,CAACI,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;EACrF;;EAEA;;EAGA;;EAGA;;EAGA;AACJ;AACA;AACA;;EAGI;;EAGA;AACJ;AACA;AACA;;EAGI;AACJ;AACA;AACA;AACA;AACA;;EAGI;AACJ;AACA;AACA;;EAGI;AACJ;AACA;AACA;AAEA","ignoreList":[]}
|