react-native-bluebreeze 0.0.12 → 1.0.1
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 +97 -13
- package/android/build.gradle +9 -3
- package/android/generated/jni/CMakeLists.txt +1 -9
- package/android/generated/jni/RNBlueBreezeSpec-generated.cpp +1 -1
- package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI.h +234 -279
- package/android/src/main/java/com/bluebreeze/BlueBreezeModule.kt +140 -120
- package/ios/BlueBreezeImpl.swift +30 -24
- package/ios/Bluebreeze.h +1 -1
- package/ios/Bluebreeze.mm +2 -7
- package/ios/generated/{RNBlueBreezeSpecJSI.h → ReactCodegen/RNBlueBreezeSpecJSI.h} +234 -279
- package/lib/commonjs/implementation/bluebreeze_characteristic.js +42 -11
- package/lib/commonjs/implementation/bluebreeze_characteristic.js.map +1 -1
- package/lib/commonjs/implementation/bluebreeze_connection_status.js +2 -0
- package/lib/commonjs/implementation/bluebreeze_connection_status.js.map +1 -0
- package/lib/commonjs/implementation/bluebreeze_device.js +53 -13
- package/lib/commonjs/implementation/bluebreeze_device.js.map +1 -1
- package/lib/commonjs/implementation/bluebreeze_scan_result.js +19 -0
- package/lib/commonjs/implementation/bluebreeze_scan_result.js.map +1 -1
- package/lib/commonjs/implementation/bluebreeze_service.js +9 -0
- package/lib/commonjs/implementation/bluebreeze_service.js.map +1 -1
- package/lib/commonjs/implementation/native_bridge.js +108 -0
- package/lib/commonjs/implementation/native_bridge.js.map +1 -0
- package/lib/commonjs/index.js +29 -100
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/module/implementation/bluebreeze_characteristic.js +43 -10
- package/lib/module/implementation/bluebreeze_characteristic.js.map +1 -1
- package/lib/module/implementation/bluebreeze_connection_status.js +2 -0
- package/lib/module/implementation/bluebreeze_connection_status.js.map +1 -0
- package/lib/module/implementation/bluebreeze_device.js +54 -12
- package/lib/module/implementation/bluebreeze_device.js.map +1 -1
- package/lib/module/implementation/bluebreeze_scan_result.js +19 -0
- package/lib/module/implementation/bluebreeze_scan_result.js.map +1 -1
- package/lib/module/implementation/bluebreeze_service.js +9 -0
- package/lib/module/implementation/bluebreeze_service.js.map +1 -1
- package/lib/module/implementation/native_bridge.js +99 -0
- package/lib/module/implementation/native_bridge.js.map +1 -0
- package/lib/module/index.js +29 -100
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeBlueBreeze.d.ts +1 -1
- package/lib/typescript/commonjs/src/NativeBlueBreeze.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_authorization.d.ts +10 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_authorization.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts +29 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_characteristic.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_connection_status.d.ts +7 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_connection_status.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts +42 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_device.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_scan_result.d.ts +11 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_scan_result.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_service.d.ts +6 -0
- package/lib/typescript/commonjs/src/implementation/bluebreeze_service.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_state.d.ts +16 -1
- package/lib/typescript/commonjs/src/implementation/bluebreeze_state.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/implementation/native_bridge.d.ts +17 -0
- package/lib/typescript/commonjs/src/implementation/native_bridge.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +0 -13
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeBlueBreeze.d.ts +1 -1
- package/lib/typescript/module/src/NativeBlueBreeze.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_authorization.d.ts +10 -1
- package/lib/typescript/module/src/implementation/bluebreeze_authorization.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts +29 -0
- package/lib/typescript/module/src/implementation/bluebreeze_characteristic.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_connection_status.d.ts +7 -0
- package/lib/typescript/module/src/implementation/bluebreeze_connection_status.d.ts.map +1 -0
- package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts +43 -2
- package/lib/typescript/module/src/implementation/bluebreeze_device.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_scan_result.d.ts +12 -1
- package/lib/typescript/module/src/implementation/bluebreeze_scan_result.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_service.d.ts +7 -1
- package/lib/typescript/module/src/implementation/bluebreeze_service.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/bluebreeze_state.d.ts +16 -1
- package/lib/typescript/module/src/implementation/bluebreeze_state.d.ts.map +1 -1
- package/lib/typescript/module/src/implementation/native_bridge.d.ts +17 -0
- package/lib/typescript/module/src/implementation/native_bridge.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +6 -19
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/package.json +13 -23
- package/react-native-bluebreeze.podspec +1 -1
- package/src/NativeBlueBreeze.ts +1 -1
- package/src/implementation/bluebreeze_authorization.ts +10 -1
- package/src/implementation/bluebreeze_characteristic.ts +48 -10
- package/src/implementation/bluebreeze_connection_status.ts +6 -0
- package/src/implementation/bluebreeze_device.ts +62 -13
- package/src/implementation/bluebreeze_scan_result.ts +18 -0
- package/src/implementation/bluebreeze_service.ts +8 -0
- package/src/implementation/bluebreeze_state.ts +16 -1
- package/src/implementation/native_bridge.ts +196 -0
- package/src/index.tsx +24 -202
- package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI-generated.cpp +0 -179
- package/ios/generated/RNBlueBreezeSpecJSI-generated.cpp +0 -179
- /package/ios/generated/{RNBlueBreezeSpec → ReactCodegen/RNBlueBreezeSpec}/RNBlueBreezeSpec-generated.mm +0 -0
- /package/ios/generated/{RNBlueBreezeSpec → ReactCodegen/RNBlueBreezeSpec}/RNBlueBreezeSpec.h +0 -0
|
@@ -4,26 +4,57 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BBCharacteristic = void 0;
|
|
7
|
-
var
|
|
8
|
-
|
|
7
|
+
var _native_bridge = require("./native_bridge.js");
|
|
8
|
+
/**
|
|
9
|
+
* A GATT characteristic belonging to a {@link BBService}.
|
|
10
|
+
*
|
|
11
|
+
* Rediscovered (and replaced with a new instance) every time services are discovered.
|
|
12
|
+
* Do not hold onto a `BBCharacteristic` reference across a disconnect/reconnect cycle.
|
|
13
|
+
*/
|
|
9
14
|
class BBCharacteristic {
|
|
10
15
|
constructor(deviceId, serviceId, id, name, properties) {
|
|
11
16
|
this.id = id;
|
|
12
17
|
this.name = name;
|
|
13
18
|
this.properties = properties;
|
|
14
|
-
this.data =
|
|
15
|
-
this.notifyEnabled =
|
|
16
|
-
this.read = () =>
|
|
17
|
-
this.write = (data, withResponse) =>
|
|
18
|
-
this.subscribe = () =>
|
|
19
|
-
this.unsubscribe = () =>
|
|
19
|
+
this.data = (0, _native_bridge.deviceCharacteristicData)(deviceId, serviceId, id);
|
|
20
|
+
this.notifyEnabled = (0, _native_bridge.deviceCharacteristicNotifyEnabled)(deviceId, serviceId, id);
|
|
21
|
+
this.read = () => (0, _native_bridge.deviceCharacteristicRead)(deviceId, serviceId, id);
|
|
22
|
+
this.write = (data, withResponse) => (0, _native_bridge.deviceCharacteristicWrite)(deviceId, serviceId, id, data, withResponse);
|
|
23
|
+
this.subscribe = () => (0, _native_bridge.deviceCharacteristicSubscribe)(deviceId, serviceId, id);
|
|
24
|
+
this.unsubscribe = () => (0, _native_bridge.deviceCharacteristicUnsubscribe)(deviceId, serviceId, id);
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
/** The characteristic's UUID. */
|
|
23
28
|
|
|
24
|
-
|
|
29
|
+
/** A human-readable name for well-known (Bluetooth SIG assigned-number) characteristics, if recognized. */
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
/** The GATT properties this characteristic declares. */
|
|
32
|
+
|
|
33
|
+
/** The last value read or notified for this characteristic. Empty until first populated. */
|
|
34
|
+
|
|
35
|
+
/** Whether this app is currently subscribed to notifications for this characteristic. */
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Reads this characteristic's current value, also updating {@link data}.
|
|
39
|
+
* @throws if the read fails or times out.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Writes a value to this characteristic.
|
|
44
|
+
* @param data The bytes to write.
|
|
45
|
+
* @param withResponse Whether to wait for the peripheral's write acknowledgment.
|
|
46
|
+
* @throws if the write fails or times out.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Subscribes to notifications.
|
|
51
|
+
* @throws if the subscribe request fails or times out.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Unsubscribes from notifications.
|
|
56
|
+
* @throws if the unsubscribe request fails or times out.
|
|
57
|
+
*/
|
|
27
58
|
}
|
|
28
59
|
exports.BBCharacteristic = BBCharacteristic;
|
|
29
60
|
//# sourceMappingURL=bluebreeze_characteristic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_native_bridge","require","BBCharacteristic","constructor","deviceId","serviceId","id","name","properties","data","deviceCharacteristicData","notifyEnabled","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;IAC7D,IAAI,CAACK,aAAa,GAAG,IAAAC,gDAAiC,EAACR,QAAQ,EAAEC,SAAS,EAAEC,EAAE,CAAC;IAE/E,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;;EAGA;;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 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["implementation/bluebreeze_connection_status.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -4,28 +4,68 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BBDevice = void 0;
|
|
7
|
-
var
|
|
8
|
-
|
|
7
|
+
var _native_bridge = require("./native_bridge.js");
|
|
8
|
+
/**
|
|
9
|
+
* A Bluetooth Low Energy peripheral, either seen while scanning or already connected from a
|
|
10
|
+
* prior session. Obtained via `BlueBreeze.devices` -- never constructed directly.
|
|
11
|
+
*
|
|
12
|
+
* A `BBDevice` stays valid for the app's lifetime once created: it isn't recreated across a
|
|
13
|
+
* connect/disconnect cycle, so its {@link connectionStatus}, {@link mtu}, and object identity
|
|
14
|
+
* all stay stable. Its {@link services} list, however, is rebuilt from scratch on every
|
|
15
|
+
* {@link discoverServices} call -- including one after a reconnect -- so a {@link BBService} or
|
|
16
|
+
* its {@link BBCharacteristic}s should not be held onto across a disconnect/reconnect; re-read
|
|
17
|
+
* `services` instead.
|
|
18
|
+
*/
|
|
9
19
|
class BBDevice {
|
|
10
20
|
constructor(id, name) {
|
|
11
21
|
this.id = id;
|
|
12
22
|
this.name = name;
|
|
13
|
-
this.services =
|
|
14
|
-
this.connectionStatus =
|
|
15
|
-
this.mtu =
|
|
16
|
-
this.connect = () =>
|
|
17
|
-
this.disconnect = () =>
|
|
18
|
-
this.discoverServices = () =>
|
|
19
|
-
this.requestMTU = mtu =>
|
|
23
|
+
this.services = (0, _native_bridge.deviceServices)(id);
|
|
24
|
+
this.connectionStatus = (0, _native_bridge.deviceConnectionStatus)(id);
|
|
25
|
+
this.mtu = (0, _native_bridge.deviceMTU)(id);
|
|
26
|
+
this.connect = () => (0, _native_bridge.deviceConnect)(id);
|
|
27
|
+
this.disconnect = () => (0, _native_bridge.deviceDisconnect)(id);
|
|
28
|
+
this.discoverServices = () => (0, _native_bridge.deviceDiscoverServices)(id);
|
|
29
|
+
this.requestMTU = mtu => (0, _native_bridge.deviceRequestMTU)(id, mtu);
|
|
20
30
|
}
|
|
21
31
|
|
|
22
|
-
|
|
32
|
+
/** The device's unique identifier. */
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
/** The device's advertised name, if any. */
|
|
25
35
|
|
|
26
|
-
|
|
36
|
+
/** The device's services discovered so far. Empty until {@link discoverServices} has been called and completed. */
|
|
27
37
|
|
|
28
|
-
|
|
38
|
+
/** Current connection status of the device. */
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The negotiated ATT MTU in bytes. Stays at the platform default until {@link requestMTU}
|
|
42
|
+
* has been called and resolved.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Connects the device.
|
|
47
|
+
* @throws if the connection attempt fails or times out.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Disconnects the device.
|
|
52
|
+
* @throws if the disconnect attempt fails or times out.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Discovers all of the device's services and their characteristics, populating
|
|
57
|
+
* {@link services}. Requires an active connection.
|
|
58
|
+
* @throws if discovery fails or times out.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Requests a larger MTU, updating {@link mtu} with whatever size the device actually
|
|
63
|
+
* negotiates. Requires an active connection.
|
|
64
|
+
*
|
|
65
|
+
* @param mtu The desired MTU size in bytes.
|
|
66
|
+
* @returns The negotiated MTU size.
|
|
67
|
+
* @throws if the request fails or times out.
|
|
68
|
+
*/
|
|
29
69
|
}
|
|
30
70
|
exports.BBDevice = BBDevice;
|
|
31
71
|
//# sourceMappingURL=bluebreeze_device.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_native_bridge","require","BBDevice","constructor","id","name","services","deviceServices","connectionStatus","deviceConnectionStatus","mtu","deviceMTU","connect","deviceConnect","disconnect","deviceDisconnect","discoverServices","deviceDiscoverServices","requestMTU","deviceRequestMTU","exports"],"sourceRoot":"../../../src","sources":["implementation/bluebreeze_device.ts"],"mappings":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,QAAQ,CAAC;EAClBC,WAAWA,CACPC,EAAU,EACVC,IAAa,EACf;IACE,IAAI,CAACD,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACC,IAAI,GAAGA,IAAI;IAEhB,IAAI,CAACC,QAAQ,GAAG,IAAAC,6BAAc,EAACH,EAAE,CAAC;IAClC,IAAI,CAACI,gBAAgB,GAAG,IAAAC,qCAAsB,EAACL,EAAE,CAAC;IAClD,IAAI,CAACM,GAAG,GAAG,IAAAC,wBAAS,EAACP,EAAE,CAAC;IAExB,IAAI,CAACQ,OAAO,GAAG,MAAM,IAAAC,4BAAa,EAACT,EAAE,CAAC;IACtC,IAAI,CAACU,UAAU,GAAG,MAAM,IAAAC,+BAAgB,EAACX,EAAE,CAAC;IAC5C,IAAI,CAACY,gBAAgB,GAAG,MAAM,IAAAC,qCAAsB,EAACb,EAAE,CAAC;IACxD,IAAI,CAACc,UAAU,GAAIR,GAAW,IAAK,IAAAS,+BAAgB,EAACf,EAAE,EAAEM,GAAG,CAAC;EAChE;;EAEA;;EAGA;;EAGA;;EAGA;;EAGA;AACJ;AACA;AACA;;EAGI;AACJ;AACA;AACA;;EAGI;AACJ;AACA;AACA;;EAGI;AACJ;AACA;AACA;AACA;;EAGI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAACU,OAAA,CAAAlB,QAAA,GAAAA,QAAA","ignoreList":[]}
|
|
@@ -4,6 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BBScanResult = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* A single BLE advertisement seen while scanning.
|
|
9
|
+
*/
|
|
7
10
|
class BBScanResult {
|
|
8
11
|
constructor(device, name, rssi, connectable, advertisedServices, manufacturerId, manufacturerName, manufacturerData) {
|
|
9
12
|
this.device = device;
|
|
@@ -15,6 +18,22 @@ class BBScanResult {
|
|
|
15
18
|
this.manufacturerName = manufacturerName;
|
|
16
19
|
this.manufacturerData = manufacturerData;
|
|
17
20
|
}
|
|
21
|
+
|
|
22
|
+
/** The device that sent this advertisement. */
|
|
23
|
+
|
|
24
|
+
/** The advertised local name, if any. Falls back to {@link device}'s name. */
|
|
25
|
+
|
|
26
|
+
/** Received signal strength, in dBm. */
|
|
27
|
+
|
|
28
|
+
/** Whether this advertisement indicates the device currently accepts connections. */
|
|
29
|
+
|
|
30
|
+
/** Service UUIDs included in this advertisement. */
|
|
31
|
+
|
|
32
|
+
/** The Bluetooth SIG-assigned company identifier for manufacturer-specific data, if present. */
|
|
33
|
+
|
|
34
|
+
/** A human-readable name for {@link manufacturerId}, if recognized. */
|
|
35
|
+
|
|
36
|
+
/** Raw manufacturer-specific advertisement data, if present. */
|
|
18
37
|
}
|
|
19
38
|
exports.BBScanResult = BBScanResult;
|
|
20
39
|
//# sourceMappingURL=bluebreeze_scan_result.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BBScanResult","constructor","device","name","rssi","connectable","advertisedServices","manufacturerId","manufacturerName","manufacturerData","exports"],"sourceRoot":"../../../src","sources":["implementation/bluebreeze_scan_result.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"names":["BBScanResult","constructor","device","name","rssi","connectable","advertisedServices","manufacturerId","manufacturerName","manufacturerData","exports"],"sourceRoot":"../../../src","sources":["implementation/bluebreeze_scan_result.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACO,MAAMA,YAAY,CAAC;EACtBC,WAAWA,CACPC,MAAgB,EAChBC,IAAwB,EACxBC,IAAY,EACZC,WAAoB,EACpBC,kBAA4B,EAC5BC,cAAuB,EACvBC,gBAAyB,EACzBC,gBAA2B,EAC7B;IACE,IAAI,CAACP,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,WAAW,GAAGA,WAAW;IAC9B,IAAI,CAACC,kBAAkB,GAAGA,kBAAkB;IAC5C,IAAI,CAACC,cAAc,GAAGA,cAAc;IACpC,IAAI,CAACC,gBAAgB,GAAGA,gBAAgB;IACxC,IAAI,CAACC,gBAAgB,GAAGA,gBAAgB;EAC5C;;EAEA;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;AAEJ;AAACC,OAAA,CAAAV,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -4,12 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BBService = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* A GATT service belonging to a {@link BBDevice}.
|
|
9
|
+
*/
|
|
7
10
|
class BBService {
|
|
8
11
|
constructor(id, name, characteristics) {
|
|
9
12
|
this.id = id;
|
|
10
13
|
this.name = name;
|
|
11
14
|
this.characteristics = characteristics;
|
|
12
15
|
}
|
|
16
|
+
|
|
17
|
+
/** The service's UUID. */
|
|
18
|
+
|
|
19
|
+
/** A human-readable name for well-known (Bluetooth SIG assigned-number) services, if recognized. */
|
|
20
|
+
|
|
21
|
+
/** This service's characteristics. */
|
|
13
22
|
}
|
|
14
23
|
exports.BBService = BBService;
|
|
15
24
|
//# sourceMappingURL=bluebreeze_service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BBService","constructor","id","name","characteristics","exports"],"sourceRoot":"../../../src","sources":["implementation/bluebreeze_service.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"names":["BBService","constructor","id","name","characteristics","exports"],"sourceRoot":"../../../src","sources":["implementation/bluebreeze_service.ts"],"mappings":";;;;;;AAEA;AACA;AACA;AACO,MAAMA,SAAS,CAAC;EACnBC,WAAWA,CACPC,EAAU,EACVC,IAAwB,EACxBC,eAAmC,EACrC;IACE,IAAI,CAACF,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,eAAe,GAAGA,eAAe;EAC1C;;EAEA;;EAGA;;EAGA;AAEJ;AAACC,OAAA,CAAAL,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
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
|
+
var _NativeBlueBreeze = _interopRequireDefault(require("../NativeBlueBreeze.js"));
|
|
9
|
+
var _bluebreeze_characteristic = require("./bluebreeze_characteristic.js");
|
|
10
|
+
var _bluebreeze_service = require("./bluebreeze_service.js");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
/**
|
|
13
|
+
* Per-device/per-characteristic wiring between the native module and {@link BBDevice}/
|
|
14
|
+
* {@link BBCharacteristic}. Not part of the package's public API: everything here is consumed
|
|
15
|
+
* directly by those two classes' constructors and is intentionally not re-exported from the
|
|
16
|
+
* package entry point (`src/index.tsx`) -- callers use `BBDevice`/`BBCharacteristic` methods
|
|
17
|
+
* instead of these raw, ID-keyed functions.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function mapGetOrSet(map, key, defaultValue) {
|
|
21
|
+
if (map.get(key) == undefined) {
|
|
22
|
+
map.set(key, defaultValue());
|
|
23
|
+
}
|
|
24
|
+
return map.get(key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Device services
|
|
28
|
+
|
|
29
|
+
const _deviceServices = new Map();
|
|
30
|
+
const deviceServices = id => {
|
|
31
|
+
return mapGetOrSet(_deviceServices, id, () => new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.deviceServices(id).map(s => convertDeviceService(id, s))));
|
|
32
|
+
};
|
|
33
|
+
exports.deviceServices = deviceServices;
|
|
34
|
+
_NativeBlueBreeze.default.deviceServicesEmitter(value => {
|
|
35
|
+
deviceServices(value.id).add(value.value.map(s => convertDeviceService(value.id, s)));
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Device connection status
|
|
39
|
+
|
|
40
|
+
const _deviceConnectionStatus = new Map();
|
|
41
|
+
const deviceConnectionStatus = id => {
|
|
42
|
+
return mapGetOrSet(_deviceConnectionStatus, id, () => new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.deviceConnectionStatus(id)));
|
|
43
|
+
};
|
|
44
|
+
exports.deviceConnectionStatus = deviceConnectionStatus;
|
|
45
|
+
_NativeBlueBreeze.default.deviceConnectionStatusEmitter(value => {
|
|
46
|
+
deviceConnectionStatus(value.id).add(value.value);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Device MTU
|
|
50
|
+
|
|
51
|
+
const _deviceMTU = new Map();
|
|
52
|
+
const deviceMTU = id => {
|
|
53
|
+
return mapGetOrSet(_deviceMTU, id, () => new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.deviceMTU(id)));
|
|
54
|
+
};
|
|
55
|
+
exports.deviceMTU = deviceMTU;
|
|
56
|
+
_NativeBlueBreeze.default.deviceMTUEmitter(value => {
|
|
57
|
+
deviceMTU(value.id).add(value.value);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Device operations
|
|
61
|
+
|
|
62
|
+
const deviceConnect = exports.deviceConnect = _NativeBlueBreeze.default.deviceConnect;
|
|
63
|
+
const deviceDisconnect = exports.deviceDisconnect = _NativeBlueBreeze.default.deviceDisconnect;
|
|
64
|
+
const deviceDiscoverServices = exports.deviceDiscoverServices = _NativeBlueBreeze.default.deviceDiscoverServices;
|
|
65
|
+
const deviceRequestMTU = exports.deviceRequestMTU = _NativeBlueBreeze.default.deviceRequestMTU;
|
|
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
|
+
// Device characteristic data
|
|
81
|
+
|
|
82
|
+
const _deviceCharacteristicData = new Map();
|
|
83
|
+
const deviceCharacteristicData = (id, serviceId, characteristicId) => {
|
|
84
|
+
const deviceMap = mapGetOrSet(_deviceCharacteristicData, id, () => new Map());
|
|
85
|
+
const serviceMap = mapGetOrSet(deviceMap, serviceId, () => new Map());
|
|
86
|
+
return mapGetOrSet(serviceMap, characteristicId, () => new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.deviceCharacteristicData(id, serviceId, characteristicId)));
|
|
87
|
+
};
|
|
88
|
+
exports.deviceCharacteristicData = deviceCharacteristicData;
|
|
89
|
+
_NativeBlueBreeze.default.deviceCharacteristicDataEmitter(value => {
|
|
90
|
+
deviceCharacteristicData(value.id, value.serviceId, value.characteristicId).add(value.value);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Device characteristic operations
|
|
94
|
+
|
|
95
|
+
const deviceCharacteristicRead = exports.deviceCharacteristicRead = _NativeBlueBreeze.default.deviceCharacteristicRead;
|
|
96
|
+
const deviceCharacteristicWrite = exports.deviceCharacteristicWrite = _NativeBlueBreeze.default.deviceCharacteristicWrite;
|
|
97
|
+
const deviceCharacteristicSubscribe = exports.deviceCharacteristicSubscribe = _NativeBlueBreeze.default.deviceCharacteristicSubscribe;
|
|
98
|
+
const deviceCharacteristicUnsubscribe = exports.deviceCharacteristicUnsubscribe = _NativeBlueBreeze.default.deviceCharacteristicUnsubscribe;
|
|
99
|
+
|
|
100
|
+
// Object decoders
|
|
101
|
+
|
|
102
|
+
const convertDeviceService = (deviceId, service) => {
|
|
103
|
+
return new _bluebreeze_service.BBService(service.id, service.name, service.characteristics.map(c => convertDeviceCharacteristic(deviceId, service.id, c)));
|
|
104
|
+
};
|
|
105
|
+
const convertDeviceCharacteristic = (deviceId, serviceId, characteristic) => {
|
|
106
|
+
return new _bluebreeze_characteristic.BBCharacteristic(deviceId, serviceId, characteristic.id, characteristic.name, characteristic.properties);
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=native_bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNativeValueEmitter","require","_NativeBlueBreeze","_interopRequireDefault","_bluebreeze_characteristic","_bluebreeze_service","e","__esModule","default","mapGetOrSet","map","key","defaultValue","get","undefined","set","_deviceServices","Map","deviceServices","id","StateValueEmitter","NativeBlueBreeze","s","convertDeviceService","exports","deviceServicesEmitter","value","add","_deviceConnectionStatus","deviceConnectionStatus","deviceConnectionStatusEmitter","_deviceMTU","deviceMTU","deviceMTUEmitter","deviceConnect","deviceDisconnect","deviceDiscoverServices","deviceRequestMTU","_deviceCharacteristicNotifyEnabled","deviceCharacteristicNotifyEnabled","serviceId","characteristicId","deviceMap","serviceMap","deviceCharacteristicNotifyEnabledEmitter","_deviceCharacteristicData","deviceCharacteristicData","deviceCharacteristicDataEmitter","deviceCharacteristicRead","deviceCharacteristicWrite","deviceCharacteristicSubscribe","deviceCharacteristicUnsubscribe","deviceId","service","BBService","name","characteristics","c","convertDeviceCharacteristic","characteristic","BBCharacteristic","properties"],"sourceRoot":"../../../src","sources":["implementation/native_bridge.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,0BAAA,GAAAH,OAAA;AAEA,IAAAI,mBAAA,GAAAJ,OAAA;AAAgD,SAAAE,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASG,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,CAAyC,CAAC;AAElE,MAAMC,cAAc,GAAIC,EAAU,IAAqC;EAC1E,OAAOV,WAAW,CACdO,eAA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AgB,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
|
@@ -37,6 +37,7 @@ var _NativeBlueBreeze = _interopRequireDefault(require("./NativeBlueBreeze.js"))
|
|
|
37
37
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
38
38
|
// State
|
|
39
39
|
|
|
40
|
+
/** The power/availability state of the device's Bluetooth adapter. */
|
|
40
41
|
const state = new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.state());
|
|
41
42
|
_NativeBlueBreeze.default.stateEmitter(value => {
|
|
42
43
|
state.add(value);
|
|
@@ -44,114 +45,61 @@ _NativeBlueBreeze.default.stateEmitter(value => {
|
|
|
44
45
|
|
|
45
46
|
// Authorization to use BLE
|
|
46
47
|
|
|
48
|
+
/** Whether this app is currently allowed to use Bluetooth. */
|
|
47
49
|
const authorizationStatus = new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.authorizationStatus());
|
|
48
50
|
_NativeBlueBreeze.default.authorizationStatusEmitter(value => {
|
|
49
51
|
authorizationStatus.add(value);
|
|
50
52
|
});
|
|
53
|
+
|
|
54
|
+
/** Requests Bluetooth authorization from the user, if not already granted or permanently denied. */
|
|
51
55
|
const authorizationRequest = _NativeBlueBreeze.default.authorizationRequest;
|
|
56
|
+
|
|
57
|
+
/** Opens the OS settings screen for this app, for a user to grant Bluetooth authorization after denying it. */
|
|
52
58
|
const authorizationOpenSettings = _NativeBlueBreeze.default.authorizationOpenSettings;
|
|
53
59
|
|
|
54
60
|
// Scanning
|
|
55
61
|
|
|
62
|
+
/** Whether a BLE scan is currently running. */
|
|
56
63
|
const scanEnabled = new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.scanEnabled());
|
|
57
64
|
_NativeBlueBreeze.default.scanEnabledEmitter(value => {
|
|
58
65
|
scanEnabled.add(value);
|
|
59
66
|
});
|
|
67
|
+
|
|
68
|
+
/** Emits every advertisement seen while scanning, including repeat sightings of the same device. */
|
|
60
69
|
const scanResults = new _reactNativeValueEmitter.ValueEmitter();
|
|
61
70
|
_NativeBlueBreeze.default.scanResultEmitter(value => {
|
|
62
|
-
|
|
71
|
+
let device = devices.value?.get(value.id);
|
|
72
|
+
|
|
73
|
+
// The native "device discovered" and "scan result" events are emitted independently.
|
|
74
|
+
// We register a new device locally rather than dropping the result.
|
|
63
75
|
if (device == undefined) {
|
|
64
|
-
|
|
76
|
+
device = convertDevice(value);
|
|
77
|
+
devices.add(new Map(devices.value).set(value.id, device));
|
|
65
78
|
}
|
|
66
79
|
scanResults.add(convertScanResult(device, value));
|
|
67
80
|
});
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Starts a BLE scan.
|
|
84
|
+
* @param ids Service UUIDs to filter for. When omitted, every nearby advertisement is reported.
|
|
85
|
+
*/
|
|
68
86
|
const scanStart = (ids = undefined) => _NativeBlueBreeze.default.scanStart(ids);
|
|
87
|
+
|
|
88
|
+
/** Stops the current BLE scan. */
|
|
69
89
|
const scanStop = _NativeBlueBreeze.default.scanStop;
|
|
70
90
|
|
|
71
|
-
//
|
|
91
|
+
// Devices
|
|
72
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Every device seen so far, either via scanning or a prior connection this session, keyed by
|
|
95
|
+
* platform device ID. A device is added here the moment it's first seen in a scan result and
|
|
96
|
+
* stays here for the app's lifetime.
|
|
97
|
+
*/
|
|
73
98
|
const devices = new _reactNativeValueEmitter.StateValueEmitter(new Map(_NativeBlueBreeze.default.devices().map(d => [d.id, convertDevice(d)])));
|
|
74
99
|
_NativeBlueBreeze.default.devicesEmitter(value => {
|
|
75
100
|
devices.add(new Map(value.map(d => [d.id, devices.value?.get(d.id) ?? convertDevice(d)])));
|
|
76
101
|
});
|
|
77
102
|
|
|
78
|
-
// Device services
|
|
79
|
-
|
|
80
|
-
const _deviceServices = new Map();
|
|
81
|
-
const deviceServices = id => {
|
|
82
|
-
return mapGetOrSet(_deviceServices, id, () => new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.deviceServices(id).map(s => convertDeviceService(id, s))));
|
|
83
|
-
};
|
|
84
|
-
_NativeBlueBreeze.default.deviceServicesEmitter(value => {
|
|
85
|
-
deviceServices(value.id).add(value.value.map(s => convertDeviceService(value.id, s)));
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Device connection status
|
|
89
|
-
|
|
90
|
-
const _deviceConnectionStatus = new Map();
|
|
91
|
-
const deviceConnectionStatus = id => {
|
|
92
|
-
return mapGetOrSet(_deviceConnectionStatus, id, () => new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.deviceConnectionStatus(id)));
|
|
93
|
-
};
|
|
94
|
-
_NativeBlueBreeze.default.deviceConnectionStatusEmitter(value => {
|
|
95
|
-
deviceConnectionStatus(value.id).add(value.value);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// Device MTU
|
|
99
|
-
|
|
100
|
-
const _deviceMTU = new Map();
|
|
101
|
-
const deviceMTU = id => {
|
|
102
|
-
return mapGetOrSet(_deviceMTU, id, () => new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.deviceMTU(id)));
|
|
103
|
-
};
|
|
104
|
-
_NativeBlueBreeze.default.deviceMTUEmitter(value => {
|
|
105
|
-
deviceMTU(value.id).add(value.value);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// Device operation
|
|
109
|
-
|
|
110
|
-
const deviceConnect = _NativeBlueBreeze.default.deviceConnect;
|
|
111
|
-
const deviceDisconnect = _NativeBlueBreeze.default.deviceDisconnect;
|
|
112
|
-
const deviceDiscoverServices = _NativeBlueBreeze.default.deviceDiscoverServices;
|
|
113
|
-
const deviceRequestMTU = _NativeBlueBreeze.default.deviceRequestMTU;
|
|
114
|
-
|
|
115
|
-
// Device characteristic notify enabled
|
|
116
|
-
|
|
117
|
-
const _deviceCharacteristicNotifyEnabled = new Map();
|
|
118
|
-
const deviceCharacteristicNotifyEnabled = (id, serviceId, characteristicId) => {
|
|
119
|
-
const deviceMap = mapGetOrSet(_deviceCharacteristicNotifyEnabled, id, () => new Map());
|
|
120
|
-
const serviceMap = mapGetOrSet(deviceMap, serviceId, () => new Map());
|
|
121
|
-
return mapGetOrSet(serviceMap, characteristicId, () => new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.deviceCharacteristicNotifyEnabled(id, serviceId, characteristicId)));
|
|
122
|
-
};
|
|
123
|
-
_NativeBlueBreeze.default.deviceCharacteristicNotifyEnabledEmitter(value => {
|
|
124
|
-
deviceCharacteristicNotifyEnabled(value.id, value.serviceId, value.characteristicId).add(value.value);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Device characteristic data
|
|
128
|
-
|
|
129
|
-
const _deviceCharacteristicData = new Map();
|
|
130
|
-
const deviceCharacteristicData = (id, serviceId, characteristicId) => {
|
|
131
|
-
const deviceMap = mapGetOrSet(_deviceCharacteristicData, id, () => new Map());
|
|
132
|
-
const serviceMap = mapGetOrSet(deviceMap, serviceId, () => new Map());
|
|
133
|
-
return mapGetOrSet(serviceMap, characteristicId, () => new _reactNativeValueEmitter.StateValueEmitter(_NativeBlueBreeze.default.deviceCharacteristicData(id, serviceId, characteristicId)));
|
|
134
|
-
};
|
|
135
|
-
_NativeBlueBreeze.default.deviceCharacteristicDataEmitter(value => {
|
|
136
|
-
deviceCharacteristicData(value.id, value.serviceId, value.characteristicId).add(value.value);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// Device characteristic operations
|
|
140
|
-
|
|
141
|
-
const deviceCharacteristicRead = _NativeBlueBreeze.default.deviceCharacteristicRead;
|
|
142
|
-
const deviceCharacteristicWrite = _NativeBlueBreeze.default.deviceCharacteristicWrite;
|
|
143
|
-
const deviceCharacteristicSubscribe = _NativeBlueBreeze.default.deviceCharacteristicSubscribe;
|
|
144
|
-
const deviceCharacteristicUnsubscribe = _NativeBlueBreeze.default.deviceCharacteristicUnsubscribe;
|
|
145
|
-
|
|
146
|
-
// Map helper
|
|
147
|
-
|
|
148
|
-
function mapGetOrSet(map, key, defaultValue) {
|
|
149
|
-
if (map.get(key) == undefined) {
|
|
150
|
-
map.set(key, defaultValue());
|
|
151
|
-
}
|
|
152
|
-
return map.get(key);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
103
|
// Object decoders
|
|
156
104
|
|
|
157
105
|
const convertDevice = device => {
|
|
@@ -160,12 +108,6 @@ const convertDevice = device => {
|
|
|
160
108
|
const convertScanResult = (device, scanResult) => {
|
|
161
109
|
return new _bluebreeze_scan_result.BBScanResult(device, scanResult.name, scanResult.rssi, scanResult.connectable, scanResult.advertisedServices, scanResult.manufacturerId, scanResult.manufacturerName, scanResult.manufacturerData);
|
|
162
110
|
};
|
|
163
|
-
const convertDeviceService = (deviceId, service) => {
|
|
164
|
-
return new _bluebreeze_service.BBService(service.id, service.name, service.characteristics.map(c => convertDeviceCharacteristic(deviceId, service.id, c)));
|
|
165
|
-
};
|
|
166
|
-
const convertDeviceCharacteristic = (deviceId, serviceId, characteristic) => {
|
|
167
|
-
return new _bluebreeze_characteristic.BBCharacteristic(deviceId, serviceId, characteristic.id, characteristic.name, characteristic.properties);
|
|
168
|
-
};
|
|
169
111
|
|
|
170
112
|
// Export
|
|
171
113
|
var _default = exports.default = {
|
|
@@ -177,19 +119,6 @@ var _default = exports.default = {
|
|
|
177
119
|
scanResults,
|
|
178
120
|
scanStart,
|
|
179
121
|
scanStop,
|
|
180
|
-
devices
|
|
181
|
-
deviceServices,
|
|
182
|
-
deviceConnectionStatus,
|
|
183
|
-
deviceMTU,
|
|
184
|
-
deviceConnect,
|
|
185
|
-
deviceDisconnect,
|
|
186
|
-
deviceDiscoverServices,
|
|
187
|
-
deviceRequestMTU,
|
|
188
|
-
deviceCharacteristicNotifyEnabled,
|
|
189
|
-
deviceCharacteristicData,
|
|
190
|
-
deviceCharacteristicRead,
|
|
191
|
-
deviceCharacteristicWrite,
|
|
192
|
-
deviceCharacteristicSubscribe,
|
|
193
|
-
deviceCharacteristicUnsubscribe
|
|
122
|
+
devices
|
|
194
123
|
};
|
|
195
124
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeValueEmitter","require","_bluebreeze_characteristic","_bluebreeze_device","_bluebreeze_scan_result","_bluebreeze_service","_NativeBlueBreeze","_interopRequireDefault","e","__esModule","default","state","StateValueEmitter","NativeBlueBreeze","stateEmitter","value","add","authorizationStatus","authorizationStatusEmitter","authorizationRequest","authorizationOpenSettings","scanEnabled","scanEnabledEmitter","scanResults","ValueEmitter","scanResultEmitter","device","devices","get","id","undefined","
|
|
1
|
+
{"version":3,"names":["_reactNativeValueEmitter","require","_bluebreeze_characteristic","_bluebreeze_device","_bluebreeze_scan_result","_bluebreeze_service","_NativeBlueBreeze","_interopRequireDefault","e","__esModule","default","state","StateValueEmitter","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"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAEA,IAAAC,0BAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA;AACA,IAAAG,uBAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AAEA,IAAAK,iBAAA,GAAAC,sBAAA,CAAAN,OAAA;AAA2F,SAAAM,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE3F;;AAEA;AACA,MAAMG,KAAK,GAAG,IAAIC,0CAAiB,CAAUC,yBAAgB,CAACF,KAAK,CAAC,CAAY,CAAC;AAEjFE,yBAAgB,CAACC,YAAY,CAAEC,KAAK,IAAK;EACrCJ,KAAK,CAACK,GAAG,CAACD,KAAgB,CAAC;AAC/B,CAAC,CAAC;;AAEF;;AAEA;AACA,MAAME,mBAAmB,GAAG,IAAIL,0CAAiB,CAAkBC,yBAAgB,CAACI,mBAAmB,CAAC,CAAoB,CAAC;AAE7HJ,yBAAgB,CAACK,0BAA0B,CAAEH,KAAK,IAAK;EACnDE,mBAAmB,CAACD,GAAG,CAACD,KAAwB,CAAC;AACrD,CAAC,CAAC;;AAEF;AACA,MAAMI,oBAAoB,GAAGN,yBAAgB,CAACM,oBAAoB;;AAElE;AACA,MAAMC,yBAAyB,GAAGP,yBAAgB,CAACO,yBAAyB;;AAE5E;;AAEA;AACA,MAAMC,WAAW,GAAG,IAAIT,0CAAiB,CAAUC,yBAAgB,CAACQ,WAAW,CAAC,CAAC,CAAC;AAElFR,yBAAgB,CAACS,kBAAkB,CAAEP,KAAK,IAAK;EAC3CM,WAAW,CAACL,GAAG,CAACD,KAAK,CAAC;AAC1B,CAAC,CAAC;;AAEF;AACA,MAAMQ,WAAW,GAAG,IA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