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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { StateValueEmitter, ValueEmitter } from 'react-native-value-emitter';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An observable value, used for every piece of state BlueBreeze exposes (`BlueBreeze.state`,
|
|
7
|
+
* {@link BBDevice.connectionStatus}, {@link BBCharacteristic.data}, and so on).
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* characteristic.data.value // the current value
|
|
11
|
+
* characteristic.data.values.onValue((data) => {}) // the current value, then new values
|
|
12
|
+
* characteristic.data.updates.onValue((data) => {}) // only new values
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Streams work with `useValueEmitter` from `react-native-value-emitter`, which unsubscribes
|
|
16
|
+
* automatically when the component unmounts.
|
|
17
|
+
*/
|
|
18
|
+
export class BBObservable {
|
|
19
|
+
constructor(initialValue) {
|
|
20
|
+
this._values = new StateValueEmitter(initialValue);
|
|
21
|
+
}
|
|
22
|
+
_updates = new ValueEmitter();
|
|
23
|
+
|
|
24
|
+
/** The current value. */
|
|
25
|
+
get value() {
|
|
26
|
+
return this._values.value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A stream that calls each handler with the current {@link value} first, then with every new one. */
|
|
30
|
+
get values() {
|
|
31
|
+
return this._values;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A stream of only the values published from now on, without the current {@link value}. */
|
|
35
|
+
get updates() {
|
|
36
|
+
return this._updates;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Publishes a new value. Internal to BlueBreeze: called when the native module reports an
|
|
41
|
+
* update, not meant to be called by apps.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
add(value) {
|
|
45
|
+
this._values.add(value);
|
|
46
|
+
this._updates.add(value);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=bluebreeze_observable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["StateValueEmitter","ValueEmitter","BBObservable","constructor","initialValue","_values","_updates","value","values","updates","add"],"sourceRoot":"../../../src","sources":["implementation/bluebreeze_observable.ts"],"mappings":";;AAAA,SAASA,iBAAiB,EAAEC,YAAY,QAAQ,4BAA4B;;AAE5E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,CAAI;EACzBC,WAAWA,CAACC,YAAe,EAAE;IACzB,IAAI,CAACC,OAAO,GAAG,IAAIL,iBAAiB,CAAII,YAAY,CAAC;EACzD;EAGiBE,QAAQ,GAAG,IAAIL,YAAY,CAAI,CAAC;;EAEjD;EACA,IAAIM,KAAKA,CAAA,EAAM;IACX,OAAO,IAAI,CAACF,OAAO,CAACE,KAAK;EAC7B;;EAEA;EACA,IAAIC,MAAMA,CAAA,EAAoB;IAC1B,OAAO,IAAI,CAACH,OAAO;EACvB;;EAEA;EACA,IAAII,OAAOA,CAAA,EAAoB;IAC3B,OAAO,IAAI,CAACH,QAAQ;EACxB;;EAEA;AACJ;AACA;AACA;AACA;EACII,GAAGA,CAACH,KAAQ,EAAE;IACV,IAAI,CAACF,OAAO,CAACK,GAAG,CAACH,KAAK,CAAC;IACvB,IAAI,CAACD,QAAQ,CAACI,GAAG,CAACH,KAAK,CAAC;EAC5B;AACJ","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { StateValueEmitter } from 'react-native-value-emitter';
|
|
4
3
|
import NativeBlueBreeze from "../NativeBlueBreeze.js";
|
|
5
4
|
import { BBCharacteristic } from "./bluebreeze_characteristic.js";
|
|
5
|
+
import { BBObservable } from "./bluebreeze_observable.js";
|
|
6
6
|
import { BBService } from "./bluebreeze_service.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -24,7 +24,7 @@ function mapGetOrSet(map, key, defaultValue) {
|
|
|
24
24
|
|
|
25
25
|
const _deviceServices = new Map();
|
|
26
26
|
export const deviceServices = id => {
|
|
27
|
-
return mapGetOrSet(_deviceServices, id, () => new
|
|
27
|
+
return mapGetOrSet(_deviceServices, id, () => new BBObservable(NativeBlueBreeze.deviceServices(id).map(s => convertDeviceService(id, s))));
|
|
28
28
|
};
|
|
29
29
|
NativeBlueBreeze.deviceServicesEmitter(value => {
|
|
30
30
|
deviceServices(value.id).add(value.value.map(s => convertDeviceService(value.id, s)));
|
|
@@ -34,7 +34,7 @@ NativeBlueBreeze.deviceServicesEmitter(value => {
|
|
|
34
34
|
|
|
35
35
|
const _deviceConnectionStatus = new Map();
|
|
36
36
|
export const deviceConnectionStatus = id => {
|
|
37
|
-
return mapGetOrSet(_deviceConnectionStatus, id, () => new
|
|
37
|
+
return mapGetOrSet(_deviceConnectionStatus, id, () => new BBObservable(NativeBlueBreeze.deviceConnectionStatus(id)));
|
|
38
38
|
};
|
|
39
39
|
NativeBlueBreeze.deviceConnectionStatusEmitter(value => {
|
|
40
40
|
deviceConnectionStatus(value.id).add(value.value);
|
|
@@ -44,7 +44,7 @@ NativeBlueBreeze.deviceConnectionStatusEmitter(value => {
|
|
|
44
44
|
|
|
45
45
|
const _deviceMTU = new Map();
|
|
46
46
|
export const deviceMTU = id => {
|
|
47
|
-
return mapGetOrSet(_deviceMTU, id, () => new
|
|
47
|
+
return mapGetOrSet(_deviceMTU, id, () => new BBObservable(NativeBlueBreeze.deviceMTU(id)));
|
|
48
48
|
};
|
|
49
49
|
NativeBlueBreeze.deviceMTUEmitter(value => {
|
|
50
50
|
deviceMTU(value.id).add(value.value);
|
|
@@ -57,30 +57,30 @@ export const deviceDisconnect = NativeBlueBreeze.deviceDisconnect;
|
|
|
57
57
|
export const deviceDiscoverServices = NativeBlueBreeze.deviceDiscoverServices;
|
|
58
58
|
export const deviceRequestMTU = NativeBlueBreeze.deviceRequestMTU;
|
|
59
59
|
|
|
60
|
-
// Device characteristic notify enabled
|
|
61
|
-
|
|
62
|
-
const _deviceCharacteristicNotifyEnabled = new Map();
|
|
63
|
-
export const deviceCharacteristicNotifyEnabled = (id, serviceId, characteristicId) => {
|
|
64
|
-
const deviceMap = mapGetOrSet(_deviceCharacteristicNotifyEnabled, id, () => new Map());
|
|
65
|
-
const serviceMap = mapGetOrSet(deviceMap, serviceId, () => new Map());
|
|
66
|
-
return mapGetOrSet(serviceMap, characteristicId, () => new StateValueEmitter(NativeBlueBreeze.deviceCharacteristicNotifyEnabled(id, serviceId, characteristicId)));
|
|
67
|
-
};
|
|
68
|
-
NativeBlueBreeze.deviceCharacteristicNotifyEnabledEmitter(value => {
|
|
69
|
-
deviceCharacteristicNotifyEnabled(value.id, value.serviceId, value.characteristicId).add(value.value);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
60
|
// Device characteristic data
|
|
73
61
|
|
|
74
62
|
const _deviceCharacteristicData = new Map();
|
|
75
63
|
export const deviceCharacteristicData = (id, serviceId, characteristicId) => {
|
|
76
64
|
const deviceMap = mapGetOrSet(_deviceCharacteristicData, id, () => new Map());
|
|
77
65
|
const serviceMap = mapGetOrSet(deviceMap, serviceId, () => new Map());
|
|
78
|
-
return mapGetOrSet(serviceMap, characteristicId, () => new
|
|
66
|
+
return mapGetOrSet(serviceMap, characteristicId, () => new BBObservable(NativeBlueBreeze.deviceCharacteristicData(id, serviceId, characteristicId)));
|
|
79
67
|
};
|
|
80
68
|
NativeBlueBreeze.deviceCharacteristicDataEmitter(value => {
|
|
81
69
|
deviceCharacteristicData(value.id, value.serviceId, value.characteristicId).add(value.value);
|
|
82
70
|
});
|
|
83
71
|
|
|
72
|
+
// Device characteristic notify enabled
|
|
73
|
+
|
|
74
|
+
const _deviceCharacteristicNotifyEnabled = new Map();
|
|
75
|
+
export const deviceCharacteristicNotifyEnabled = (id, serviceId, characteristicId) => {
|
|
76
|
+
const deviceMap = mapGetOrSet(_deviceCharacteristicNotifyEnabled, id, () => new Map());
|
|
77
|
+
const serviceMap = mapGetOrSet(deviceMap, serviceId, () => new Map());
|
|
78
|
+
return mapGetOrSet(serviceMap, characteristicId, () => new BBObservable(NativeBlueBreeze.deviceCharacteristicNotifyEnabled(id, serviceId, characteristicId)));
|
|
79
|
+
};
|
|
80
|
+
NativeBlueBreeze.deviceCharacteristicNotifyEnabledEmitter(value => {
|
|
81
|
+
deviceCharacteristicNotifyEnabled(value.id, value.serviceId, value.characteristicId).add(value.value);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
84
|
// Device characteristic operations
|
|
85
85
|
|
|
86
86
|
export const deviceCharacteristicRead = NativeBlueBreeze.deviceCharacteristicRead;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["NativeBlueBreeze","BBCharacteristic","BBObservable","BBService","mapGetOrSet","map","key","defaultValue","get","undefined","set","_deviceServices","Map","deviceServices","id","s","convertDeviceService","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","name","characteristics","c","convertDeviceCharacteristic","characteristic","properties"],"sourceRoot":"../../../src","sources":["implementation/native_bridge.ts"],"mappings":";;AAAA,OAAOA,gBAAgB,MAAiE,wBAAqB;AAC7G,SAASC,gBAAgB,QAAQ,gCAA6B;AAC9D,SAASC,YAAY,QAAQ,4BAAyB;AAEtD,SAASC,SAAS,QAAQ,yBAAsB;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASC,WAAWA,CAAIC,GAAmB,EAAEC,GAAW,EAAEC,YAAqB,EAAK;EAChF,IAAIF,GAAG,CAACG,GAAG,CAACF,GAAG,CAAC,IAAIG,SAAS,EAAE;IAC3BJ,GAAG,CAACK,GAAG,CAACJ,GAAG,EAAEC,YAAY,CAAC,CAAC,CAAC;EAChC;EAEA,OAAOF,GAAG,CAACG,GAAG,CAACF,GAAG,CAAC;AACvB;;AAEA;;AAEA,MAAMK,eAAe,GAAG,IAAIC,GAAG,CAAoC,CAAC;AAEpE,OAAO,MAAMC,cAAc,GAAIC,EAAU,IAAgC;EACrE,OAAOV,WAAW,CACdO,eAAe,EACfG,EAAE,EACF,MAAM,IAAIZ,YAAY,CAClBF,gBAAgB,CAACa,cAAc,CAACC,EAAE,CAAC,CAACT,GAAG,CAClCU,CAAC,IAAKC,oBAAoB,CAACF,EAAE,EAAEC,CAAC,CACrC,CACJ,CACJ,CAAC;AACL,CAAC;AAEDf,gBAAgB,CAACiB,qBAAqB,CAAEC,KAAK,IAAK;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|
3
|
+
import { ValueEmitter } from 'react-native-value-emitter';
|
|
4
4
|
import { BBCharacteristic } from "./implementation/bluebreeze_characteristic.js";
|
|
5
5
|
import { BBDevice } from "./implementation/bluebreeze_device.js";
|
|
6
|
+
import { BBObservable } from "./implementation/bluebreeze_observable.js";
|
|
6
7
|
import { BBScanResult } from "./implementation/bluebreeze_scan_result.js";
|
|
7
8
|
import { BBService } from "./implementation/bluebreeze_service.js";
|
|
8
9
|
import NativeBlueBreeze from "./NativeBlueBreeze.js";
|
|
@@ -10,7 +11,7 @@ import NativeBlueBreeze from "./NativeBlueBreeze.js";
|
|
|
10
11
|
// State
|
|
11
12
|
|
|
12
13
|
/** The power/availability state of the device's Bluetooth adapter. */
|
|
13
|
-
const state = new
|
|
14
|
+
const state = new BBObservable(NativeBlueBreeze.state());
|
|
14
15
|
NativeBlueBreeze.stateEmitter(value => {
|
|
15
16
|
state.add(value);
|
|
16
17
|
});
|
|
@@ -18,7 +19,7 @@ NativeBlueBreeze.stateEmitter(value => {
|
|
|
18
19
|
// Authorization to use BLE
|
|
19
20
|
|
|
20
21
|
/** Whether this app is currently allowed to use Bluetooth. */
|
|
21
|
-
const authorizationStatus = new
|
|
22
|
+
const authorizationStatus = new BBObservable(NativeBlueBreeze.authorizationStatus());
|
|
22
23
|
NativeBlueBreeze.authorizationStatusEmitter(value => {
|
|
23
24
|
authorizationStatus.add(value);
|
|
24
25
|
});
|
|
@@ -32,7 +33,7 @@ const authorizationOpenSettings = NativeBlueBreeze.authorizationOpenSettings;
|
|
|
32
33
|
// Scanning
|
|
33
34
|
|
|
34
35
|
/** Whether a BLE scan is currently running. */
|
|
35
|
-
const scanEnabled = new
|
|
36
|
+
const scanEnabled = new BBObservable(NativeBlueBreeze.scanEnabled());
|
|
36
37
|
NativeBlueBreeze.scanEnabledEmitter(value => {
|
|
37
38
|
scanEnabled.add(value);
|
|
38
39
|
});
|
|
@@ -67,7 +68,7 @@ const scanStop = NativeBlueBreeze.scanStop;
|
|
|
67
68
|
* platform device ID. A device is added here the moment it's first seen in a scan result and
|
|
68
69
|
* stays here for the app's lifetime.
|
|
69
70
|
*/
|
|
70
|
-
const devices = new
|
|
71
|
+
const devices = new BBObservable(new Map(NativeBlueBreeze.devices().map(d => [d.id, convertDevice(d)])));
|
|
71
72
|
NativeBlueBreeze.devicesEmitter(value => {
|
|
72
73
|
devices.add(new Map(value.map(d => [d.id, devices.value?.get(d.id) ?? convertDevice(d)])));
|
|
73
74
|
});
|
|
@@ -94,5 +95,5 @@ export default {
|
|
|
94
95
|
scanStop,
|
|
95
96
|
devices
|
|
96
97
|
};
|
|
97
|
-
export { BBCharacteristic, BBDevice, BBScanResult, BBService };
|
|
98
|
+
export { BBCharacteristic, BBDevice, BBObservable, BBScanResult, BBService };
|
|
98
99
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["ValueEmitter","BBCharacteristic","BBDevice","BBObservable","BBScanResult","BBService","NativeBlueBreeze","state","stateEmitter","value","add","authorizationStatus","authorizationStatusEmitter","authorizationRequest","authorizationOpenSettings","scanEnabled","scanEnabledEmitter","scanResults","scanResultEmitter","device","devices","get","id","undefined","convertDevice","Map","set","convertScanResult","scanStart","ids","scanStop","map","d","devicesEmitter","name","scanResult","rssi","connectable","advertisedServices","manufacturerId","manufacturerName","manufacturerData"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAEzD,SAASC,gBAAgB,QAAQ,+CAA4C;AAC7E,SAASC,QAAQ,QAAQ,uCAAoC;AAC7D,SAASC,YAAY,QAAQ,2CAAwC;AACrE,SAASC,YAAY,QAAQ,4CAAyC;AACtE,SAASC,SAAS,QAAQ,wCAAqC;AAE/D,OAAOC,gBAAgB,MAAgD,uBAAoB;;AAE3F;;AAEA;AACA,MAAMC,KAAK,GAAG,IAAIJ,YAAY,CAAUG,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AAoB;EACpBC,yBAAyB;EACzBC,WAAW;EACXE,WAAW;EACXW,SAAS;EACTE,QAAQ;EACRV;AACJ,CAAC;AAED,SACInB,gBAAgB,EAChBC,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZC,SAAS","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BBObservable } from "./bluebreeze_observable";
|
|
2
2
|
/**
|
|
3
3
|
* A GATT characteristic belonging to a {@link BBService}.
|
|
4
4
|
*
|
|
@@ -13,10 +13,13 @@ export declare class BBCharacteristic {
|
|
|
13
13
|
name?: string;
|
|
14
14
|
/** The GATT properties this characteristic declares. */
|
|
15
15
|
properties: string[];
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The last value read or notified for this characteristic. Empty until first populated.
|
|
18
|
+
* Use `data.updates` to receive only the values that arrive from now on.
|
|
19
|
+
*/
|
|
20
|
+
data: BBObservable<number[]>;
|
|
18
21
|
/** Whether this app is currently subscribed to notifications for this characteristic. */
|
|
19
|
-
|
|
22
|
+
isNotifying: BBObservable<boolean>;
|
|
20
23
|
/**
|
|
21
24
|
* Reads this characteristic's current value, also updating {@link data}.
|
|
22
25
|
* @throws if the read fails or times out.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bluebreeze_characteristic.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/bluebreeze_characteristic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"bluebreeze_characteristic.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/bluebreeze_characteristic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAU3D;;;;;GAKG;AACH,qBAAa,gBAAgB;gBAErB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,UAAU,EAAE,MAAM,EAAE;IAgBxB,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAA;IAEV,2GAA2G;IAC3G,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,wDAAwD;IACxD,UAAU,EAAE,MAAM,EAAE,CAAA;IAEpB;;;OAGG;IACH,IAAI,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,CAAA;IAE5B,yFAAyF;IACzF,WAAW,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;IAElC;;;OAGG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAE7B;;;;;OAKG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAE/D;;;OAGG;IACH,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAE9B;;;OAGG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACnC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BBObservable } from "./bluebreeze_observable";
|
|
2
2
|
import type { BBDeviceConnectionStatus } from "./bluebreeze_connection_status";
|
|
3
3
|
import type { BBService } from "./bluebreeze_service";
|
|
4
4
|
/**
|
|
@@ -19,14 +19,14 @@ export declare class BBDevice {
|
|
|
19
19
|
/** The device's advertised name, if any. */
|
|
20
20
|
name?: string;
|
|
21
21
|
/** The device's services discovered so far. Empty until {@link discoverServices} has been called and completed. */
|
|
22
|
-
services:
|
|
22
|
+
services: BBObservable<BBService[]>;
|
|
23
23
|
/** Current connection status of the device. */
|
|
24
|
-
connectionStatus:
|
|
24
|
+
connectionStatus: BBObservable<BBDeviceConnectionStatus>;
|
|
25
25
|
/**
|
|
26
26
|
* The negotiated ATT MTU in bytes. Stays at the platform default until {@link requestMTU}
|
|
27
27
|
* has been called and resolved.
|
|
28
28
|
*/
|
|
29
|
-
mtu:
|
|
29
|
+
mtu: BBObservable<number>;
|
|
30
30
|
/**
|
|
31
31
|
* Connects the device.
|
|
32
32
|
* @throws if the connection attempt fails or times out.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bluebreeze_device.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/bluebreeze_device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"bluebreeze_device.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/bluebreeze_device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAA;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAWrD;;;;;;;;;;GAUG;AACH,qBAAa,QAAQ;gBAEb,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE,MAAM;IAejB,sCAAsC;IACtC,EAAE,EAAE,MAAM,CAAA;IAEV,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,mHAAmH;IACnH,QAAQ,EAAE,YAAY,CAAC,SAAS,EAAE,CAAC,CAAA;IAEnC,+CAA+C;IAC/C,gBAAgB,EAAE,YAAY,CAAC,wBAAwB,CAAC,CAAA;IAExD;;;OAGG;IACH,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;IAEzB;;;OAGG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAE5B;;;OAGG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAE/B;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAErC;;;;;;;OAOG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAC/C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ValueEmitter } from 'react-native-value-emitter';
|
|
2
|
+
/**
|
|
3
|
+
* An observable value, used for every piece of state BlueBreeze exposes (`BlueBreeze.state`,
|
|
4
|
+
* {@link BBDevice.connectionStatus}, {@link BBCharacteristic.data}, and so on).
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* characteristic.data.value // the current value
|
|
8
|
+
* characteristic.data.values.onValue((data) => {}) // the current value, then new values
|
|
9
|
+
* characteristic.data.updates.onValue((data) => {}) // only new values
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Streams work with `useValueEmitter` from `react-native-value-emitter`, which unsubscribes
|
|
13
|
+
* automatically when the component unmounts.
|
|
14
|
+
*/
|
|
15
|
+
export declare class BBObservable<T> {
|
|
16
|
+
constructor(initialValue: T);
|
|
17
|
+
private readonly _values;
|
|
18
|
+
private readonly _updates;
|
|
19
|
+
/** The current value. */
|
|
20
|
+
get value(): T;
|
|
21
|
+
/** A stream that calls each handler with the current {@link value} first, then with every new one. */
|
|
22
|
+
get values(): ValueEmitter<T>;
|
|
23
|
+
/** A stream of only the values published from now on, without the current {@link value}. */
|
|
24
|
+
get updates(): ValueEmitter<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Publishes a new value. Internal to BlueBreeze: called when the native module reports an
|
|
27
|
+
* update, not meant to be called by apps.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
add(value: T): void;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=bluebreeze_observable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bluebreeze_observable.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/bluebreeze_observable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE5E;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAY,CAAC,CAAC;gBACX,YAAY,EAAE,CAAC;IAI3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IAEjD,yBAAyB;IACzB,IAAI,KAAK,IAAI,CAAC,CAEb;IAED,sGAAsG;IACtG,IAAI,MAAM,IAAI,YAAY,CAAC,CAAC,CAAC,CAE5B;IAED,4FAA4F;IAC5F,IAAI,OAAO,IAAI,YAAY,CAAC,CAAC,CAAC,CAE7B;IAED;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC;CAIf"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BBObservable } from './bluebreeze_observable';
|
|
2
2
|
import type { BBDeviceConnectionStatus } from './bluebreeze_connection_status';
|
|
3
3
|
import { BBService } from './bluebreeze_service';
|
|
4
|
-
export declare const deviceServices: (id: string) =>
|
|
5
|
-
export declare const deviceConnectionStatus: (id: string) =>
|
|
6
|
-
export declare const deviceMTU: (id: string) =>
|
|
4
|
+
export declare const deviceServices: (id: string) => BBObservable<BBService[]>;
|
|
5
|
+
export declare const deviceConnectionStatus: (id: string) => BBObservable<BBDeviceConnectionStatus>;
|
|
6
|
+
export declare const deviceMTU: (id: string) => BBObservable<number>;
|
|
7
7
|
export declare const deviceConnect: (id: string) => Promise<void>;
|
|
8
8
|
export declare const deviceDisconnect: (id: string) => Promise<void>;
|
|
9
9
|
export declare const deviceDiscoverServices: (id: string) => Promise<void>;
|
|
10
10
|
export declare const deviceRequestMTU: (id: string, mtu: number) => Promise<number>;
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
11
|
+
export declare const deviceCharacteristicData: (id: string, serviceId: string, characteristicId: string) => BBObservable<number[]>;
|
|
12
|
+
export declare const deviceCharacteristicNotifyEnabled: (id: string, serviceId: string, characteristicId: string) => BBObservable<boolean>;
|
|
13
13
|
export declare const deviceCharacteristicRead: (id: string, serviceId: string, characteristicId: string) => Promise<number[]>;
|
|
14
14
|
export declare const deviceCharacteristicWrite: (id: string, serviceId: string, characteristicId: string, data: number[], withResponse: boolean) => Promise<void>;
|
|
15
15
|
export declare const deviceCharacteristicSubscribe: (id: string, serviceId: string, characteristicId: string) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native_bridge.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/native_bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"native_bridge.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/native_bridge.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAA;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAsBhD,eAAO,MAAM,cAAc,OAAQ,MAAM,KAAG,YAAY,CAAC,SAAS,EAAE,CAUnE,CAAA;AAYD,eAAO,MAAM,sBAAsB,OAAQ,MAAM,KAAG,YAAY,CAAC,wBAAwB,CAQxF,CAAA;AAUD,eAAO,MAAM,SAAS,OAAQ,MAAM,KAAG,YAAY,CAAC,MAAM,CAQzD,CAAA;AAQD,eAAO,MAAM,aAAa,+BAAiC,CAAA;AAE3D,eAAO,MAAM,gBAAgB,+BAAoC,CAAA;AAEjE,eAAO,MAAM,sBAAsB,+BAA0C,CAAA;AAE7E,eAAO,MAAM,gBAAgB,8CAAoC,CAAA;AAMjE,eAAO,MAAM,wBAAwB,OAC7B,MAAM,aACC,MAAM,oBACC,MAAM,KACzB,YAAY,CAAC,MAAM,EAAE,CAoBvB,CAAA;AAUD,eAAO,MAAM,iCAAiC,OACtC,MAAM,aACC,MAAM,oBACC,MAAM,KACzB,YAAY,CAAC,OAAO,CAoBtB,CAAA;AAQD,eAAO,MAAM,wBAAwB,gFAA4C,CAAA;AAEjF,eAAO,MAAM,yBAAyB,mHAA6C,CAAA;AAEnF,eAAO,MAAM,6BAA6B,4EAAiD,CAAA;AAE3F,eAAO,MAAM,+BAA+B,4EAAmD,CAAA"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ValueEmitter } from 'react-native-value-emitter';
|
|
2
2
|
import type { BBAuthorization } from './implementation/bluebreeze_authorization';
|
|
3
3
|
import { BBCharacteristic } from './implementation/bluebreeze_characteristic';
|
|
4
4
|
import { BBDevice } from './implementation/bluebreeze_device';
|
|
5
|
+
import { BBObservable } from './implementation/bluebreeze_observable';
|
|
5
6
|
import { BBScanResult } from './implementation/bluebreeze_scan_result';
|
|
6
7
|
import { BBService } from './implementation/bluebreeze_service';
|
|
7
8
|
import type { BBState } from './implementation/bluebreeze_state';
|
|
8
9
|
declare const _default: {
|
|
9
|
-
state:
|
|
10
|
-
authorizationStatus:
|
|
10
|
+
state: BBObservable<BBState>;
|
|
11
|
+
authorizationStatus: BBObservable<BBAuthorization>;
|
|
11
12
|
authorizationRequest: () => void;
|
|
12
13
|
authorizationOpenSettings: () => void;
|
|
13
|
-
scanEnabled:
|
|
14
|
+
scanEnabled: BBObservable<boolean>;
|
|
14
15
|
scanResults: ValueEmitter<BBScanResult>;
|
|
15
16
|
scanStart: (ids?: string[] | undefined) => void;
|
|
16
17
|
scanStop: () => void;
|
|
17
|
-
devices:
|
|
18
|
+
devices: BBObservable<Map<string, BBDevice>>;
|
|
18
19
|
};
|
|
19
20
|
export default _default;
|
|
20
|
-
export { BBCharacteristic, BBDevice, BBScanResult, BBService, type BBAuthorization, type BBState };
|
|
21
|
+
export { BBCharacteristic, BBDevice, BBObservable, BBScanResult, BBService, type BBAuthorization, type BBState };
|
|
21
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;;;;;;;;sBAwDxC,MAAM,EAAE,GAAG,SAAS;;;;AA2D5C,wBAUC;AAED,OAAO,EACH,gBAAgB,EAChB,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,KAAK,eAAe,EACpB,KAAK,OAAO,EACf,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BBObservable } from "./bluebreeze_observable.js";
|
|
2
2
|
/**
|
|
3
3
|
* A GATT characteristic belonging to a {@link BBService}.
|
|
4
4
|
*
|
|
@@ -13,10 +13,13 @@ export declare class BBCharacteristic {
|
|
|
13
13
|
name?: string;
|
|
14
14
|
/** The GATT properties this characteristic declares. */
|
|
15
15
|
properties: string[];
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The last value read or notified for this characteristic. Empty until first populated.
|
|
18
|
+
* Use `data.updates` to receive only the values that arrive from now on.
|
|
19
|
+
*/
|
|
20
|
+
data: BBObservable<number[]>;
|
|
18
21
|
/** Whether this app is currently subscribed to notifications for this characteristic. */
|
|
19
|
-
|
|
22
|
+
isNotifying: BBObservable<boolean>;
|
|
20
23
|
/**
|
|
21
24
|
* Reads this characteristic's current value, also updating {@link data}.
|
|
22
25
|
* @throws if the read fails or times out.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bluebreeze_characteristic.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/bluebreeze_characteristic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"bluebreeze_characteristic.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/bluebreeze_characteristic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAAyB,CAAA;AAU3D;;;;;GAKG;AACH,qBAAa,gBAAgB;gBAErB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,UAAU,EAAE,MAAM,EAAE;IAgBxB,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAA;IAEV,2GAA2G;IAC3G,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,wDAAwD;IACxD,UAAU,EAAE,MAAM,EAAE,CAAA;IAEpB;;;OAGG;IACH,IAAI,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,CAAA;IAE5B,yFAAyF;IACzF,WAAW,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;IAElC;;;OAGG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAE7B;;;;;OAKG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAE/D;;;OAGG;IACH,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAE9B;;;OAGG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACnC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BBObservable } from "./bluebreeze_observable.js";
|
|
2
2
|
import type { BBDeviceConnectionStatus } from "./bluebreeze_connection_status.js";
|
|
3
3
|
import type { BBService } from "./bluebreeze_service.js";
|
|
4
4
|
/**
|
|
@@ -19,14 +19,14 @@ export declare class BBDevice {
|
|
|
19
19
|
/** The device's advertised name, if any. */
|
|
20
20
|
name?: string;
|
|
21
21
|
/** The device's services discovered so far. Empty until {@link discoverServices} has been called and completed. */
|
|
22
|
-
services:
|
|
22
|
+
services: BBObservable<BBService[]>;
|
|
23
23
|
/** Current connection status of the device. */
|
|
24
|
-
connectionStatus:
|
|
24
|
+
connectionStatus: BBObservable<BBDeviceConnectionStatus>;
|
|
25
25
|
/**
|
|
26
26
|
* The negotiated ATT MTU in bytes. Stays at the platform default until {@link requestMTU}
|
|
27
27
|
* has been called and resolved.
|
|
28
28
|
*/
|
|
29
|
-
mtu:
|
|
29
|
+
mtu: BBObservable<number>;
|
|
30
30
|
/**
|
|
31
31
|
* Connects the device.
|
|
32
32
|
* @throws if the connection attempt fails or times out.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bluebreeze_device.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/bluebreeze_device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"bluebreeze_device.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/bluebreeze_device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAgC,CAAA;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAsB,CAAA;AAWrD;;;;;;;;;;GAUG;AACH,qBAAa,QAAQ;gBAEb,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE,MAAM;IAejB,sCAAsC;IACtC,EAAE,EAAE,MAAM,CAAA;IAEV,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,mHAAmH;IACnH,QAAQ,EAAE,YAAY,CAAC,SAAS,EAAE,CAAC,CAAA;IAEnC,+CAA+C;IAC/C,gBAAgB,EAAE,YAAY,CAAC,wBAAwB,CAAC,CAAA;IAExD;;;OAGG;IACH,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;IAEzB;;;OAGG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAE5B;;;OAGG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAE/B;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAErC;;;;;;;OAOG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAC/C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ValueEmitter } from 'react-native-value-emitter';
|
|
2
|
+
/**
|
|
3
|
+
* An observable value, used for every piece of state BlueBreeze exposes (`BlueBreeze.state`,
|
|
4
|
+
* {@link BBDevice.connectionStatus}, {@link BBCharacteristic.data}, and so on).
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* characteristic.data.value // the current value
|
|
8
|
+
* characteristic.data.values.onValue((data) => {}) // the current value, then new values
|
|
9
|
+
* characteristic.data.updates.onValue((data) => {}) // only new values
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Streams work with `useValueEmitter` from `react-native-value-emitter`, which unsubscribes
|
|
13
|
+
* automatically when the component unmounts.
|
|
14
|
+
*/
|
|
15
|
+
export declare class BBObservable<T> {
|
|
16
|
+
constructor(initialValue: T);
|
|
17
|
+
private readonly _values;
|
|
18
|
+
private readonly _updates;
|
|
19
|
+
/** The current value. */
|
|
20
|
+
get value(): T;
|
|
21
|
+
/** A stream that calls each handler with the current {@link value} first, then with every new one. */
|
|
22
|
+
get values(): ValueEmitter<T>;
|
|
23
|
+
/** A stream of only the values published from now on, without the current {@link value}. */
|
|
24
|
+
get updates(): ValueEmitter<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Publishes a new value. Internal to BlueBreeze: called when the native module reports an
|
|
27
|
+
* update, not meant to be called by apps.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
add(value: T): void;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=bluebreeze_observable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bluebreeze_observable.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/bluebreeze_observable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE5E;;;;;;;;;;;;GAYG;AACH,qBAAa,YAAY,CAAC,CAAC;gBACX,YAAY,EAAE,CAAC;IAI3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAsB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IAEjD,yBAAyB;IACzB,IAAI,KAAK,IAAI,CAAC,CAEb;IAED,sGAAsG;IACtG,IAAI,MAAM,IAAI,YAAY,CAAC,CAAC,CAAC,CAE5B;IAED,4FAA4F;IAC5F,IAAI,OAAO,IAAI,YAAY,CAAC,CAAC,CAAC,CAE7B;IAED;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC;CAIf"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BBObservable } from './bluebreeze_observable.js';
|
|
2
2
|
import type { BBDeviceConnectionStatus } from './bluebreeze_connection_status.js';
|
|
3
3
|
import { BBService } from './bluebreeze_service.js';
|
|
4
|
-
export declare const deviceServices: (id: string) =>
|
|
5
|
-
export declare const deviceConnectionStatus: (id: string) =>
|
|
6
|
-
export declare const deviceMTU: (id: string) =>
|
|
4
|
+
export declare const deviceServices: (id: string) => BBObservable<BBService[]>;
|
|
5
|
+
export declare const deviceConnectionStatus: (id: string) => BBObservable<BBDeviceConnectionStatus>;
|
|
6
|
+
export declare const deviceMTU: (id: string) => BBObservable<number>;
|
|
7
7
|
export declare const deviceConnect: (id: string) => Promise<void>;
|
|
8
8
|
export declare const deviceDisconnect: (id: string) => Promise<void>;
|
|
9
9
|
export declare const deviceDiscoverServices: (id: string) => Promise<void>;
|
|
10
10
|
export declare const deviceRequestMTU: (id: string, mtu: number) => Promise<number>;
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
11
|
+
export declare const deviceCharacteristicData: (id: string, serviceId: string, characteristicId: string) => BBObservable<number[]>;
|
|
12
|
+
export declare const deviceCharacteristicNotifyEnabled: (id: string, serviceId: string, characteristicId: string) => BBObservable<boolean>;
|
|
13
13
|
export declare const deviceCharacteristicRead: (id: string, serviceId: string, characteristicId: string) => Promise<number[]>;
|
|
14
14
|
export declare const deviceCharacteristicWrite: (id: string, serviceId: string, characteristicId: string, data: number[], withResponse: boolean) => Promise<void>;
|
|
15
15
|
export declare const deviceCharacteristicSubscribe: (id: string, serviceId: string, characteristicId: string) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native_bridge.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/native_bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"native_bridge.d.ts","sourceRoot":"","sources":["../../../../../src/implementation/native_bridge.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAAyB,CAAA;AACtD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAgC,CAAA;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAsB,CAAA;AAsBhD,eAAO,MAAM,cAAc,OAAQ,MAAM,KAAG,YAAY,CAAC,SAAS,EAAE,CAUnE,CAAA;AAYD,eAAO,MAAM,sBAAsB,OAAQ,MAAM,KAAG,YAAY,CAAC,wBAAwB,CAQxF,CAAA;AAUD,eAAO,MAAM,SAAS,OAAQ,MAAM,KAAG,YAAY,CAAC,MAAM,CAQzD,CAAA;AAQD,eAAO,MAAM,aAAa,+BAAiC,CAAA;AAE3D,eAAO,MAAM,gBAAgB,+BAAoC,CAAA;AAEjE,eAAO,MAAM,sBAAsB,+BAA0C,CAAA;AAE7E,eAAO,MAAM,gBAAgB,8CAAoC,CAAA;AAMjE,eAAO,MAAM,wBAAwB,OAC7B,MAAM,aACC,MAAM,oBACC,MAAM,KACzB,YAAY,CAAC,MAAM,EAAE,CAoBvB,CAAA;AAUD,eAAO,MAAM,iCAAiC,OACtC,MAAM,aACC,MAAM,oBACC,MAAM,KACzB,YAAY,CAAC,OAAO,CAoBtB,CAAA;AAQD,eAAO,MAAM,wBAAwB,gFAA4C,CAAA;AAEjF,eAAO,MAAM,yBAAyB,mHAA6C,CAAA;AAEnF,eAAO,MAAM,6BAA6B,4EAAiD,CAAA;AAE3F,eAAO,MAAM,+BAA+B,4EAAmD,CAAA"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ValueEmitter } from 'react-native-value-emitter';
|
|
2
2
|
import type { BBAuthorization } from './implementation/bluebreeze_authorization.js';
|
|
3
3
|
import { BBCharacteristic } from './implementation/bluebreeze_characteristic.js';
|
|
4
4
|
import { BBDevice } from './implementation/bluebreeze_device.js';
|
|
5
|
+
import { BBObservable } from './implementation/bluebreeze_observable.js';
|
|
5
6
|
import { BBScanResult } from './implementation/bluebreeze_scan_result.js';
|
|
6
7
|
import { BBService } from './implementation/bluebreeze_service.js';
|
|
7
8
|
import type { BBState } from './implementation/bluebreeze_state.js';
|
|
8
9
|
declare const _default: {
|
|
9
|
-
state:
|
|
10
|
-
authorizationStatus:
|
|
10
|
+
state: BBObservable<BBState>;
|
|
11
|
+
authorizationStatus: BBObservable<BBAuthorization>;
|
|
11
12
|
authorizationRequest: () => void;
|
|
12
13
|
authorizationOpenSettings: () => void;
|
|
13
|
-
scanEnabled:
|
|
14
|
+
scanEnabled: BBObservable<boolean>;
|
|
14
15
|
scanResults: ValueEmitter<BBScanResult>;
|
|
15
16
|
scanStart: (ids?: string[] | undefined) => void;
|
|
16
17
|
scanStop: () => void;
|
|
17
|
-
devices:
|
|
18
|
+
devices: BBObservable<Map<string, BBDevice>>;
|
|
18
19
|
};
|
|
19
20
|
export default _default;
|
|
20
|
-
export { BBCharacteristic, BBDevice, BBScanResult, BBService, type BBAuthorization, type BBState };
|
|
21
|
+
export { BBCharacteristic, BBDevice, BBObservable, BBScanResult, BBService, type BBAuthorization, type BBState };
|
|
21
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8CAA2C,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,+CAA4C,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAoC,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,2CAAwC,CAAA;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,4CAAyC,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAqC,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAmC,CAAA;;;;;;;;sBAwDxC,MAAM,EAAE,GAAG,SAAS;;;;AA2D5C,wBAUC;AAED,OAAO,EACH,gBAAgB,EAChB,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,KAAK,eAAe,EACpB,KAAK,OAAO,EACf,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-bluebreeze",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "BlueBreeze bindings for React Native. A modern Bluetooth LE library.",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "./lib/commonjs/index.js",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"typecheck": "tsc",
|
|
43
43
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
44
44
|
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
45
|
-
"prepare": "bob build"
|
|
45
|
+
"prepare": "bob build",
|
|
46
|
+
"codegen": "bob build --target codegen"
|
|
46
47
|
},
|
|
47
48
|
"keywords": [
|
|
48
49
|
"react-native",
|
|
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
|
|
|
17
17
|
s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
|
|
18
18
|
s.private_header_files = "ios/**/*.h"
|
|
19
19
|
|
|
20
|
-
s.dependency "BlueBreeze", "1.0
|
|
20
|
+
s.dependency "BlueBreeze", "1.1.0"
|
|
21
21
|
|
|
22
22
|
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
23
23
|
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|