@psdk/device-ble-taro 0.7.16 → 0.7.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/provider.d.ts +1 -0
- package/build/provider.d.ts.map +1 -1
- package/build/provider.js +31 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +3 -3
- package/package.json +4 -4
package/build/provider.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare class TaroBleBluetooth extends Jluetooth<Taro.onBluetoothDeviceFo
|
|
|
18
18
|
private extractMacFromAdvertisData;
|
|
19
19
|
private formatMacAddress;
|
|
20
20
|
private createBLEConnection;
|
|
21
|
+
private setBLEMTU;
|
|
21
22
|
private getBLEDeviceServices;
|
|
22
23
|
private getBLEDeviceCharacteristics;
|
|
23
24
|
private requestLocation;
|
package/build/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,cAAc,EAEd,SAAS,EACT,eAAe,EACf,eAAe,EAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAC,eAAe,EAAkB,MAAM,oBAAoB,CAAC;AAGpE,OAAO,IAAI,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,cAAc,EAEd,SAAS,EACT,eAAe,EACf,eAAe,EAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAC,eAAe,EAAkB,MAAM,oBAAoB,CAAC;AAGpE,OAAO,IAAI,MAAM,cAAc,CAAC;AAIhC,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,6BAA6B,CAAC;IAExG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAkB;IAG3C,OAAO,CAAC,kBAAkB,CAAC,CAAgH;IAC3I,OAAO,CAAC,eAAe,CAAC,CAAyB;gBAErC,OAAO,CAAC,EAAE,eAAe;IAMrC,WAAW,IAAI,OAAO;IAMhB,qBAAqB,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAUvD,OAAO,CACX,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,sBAAsB,CAAC,6BAA6B,CAAC,EAClF,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,eAAe,CAAC;IAmC3B,UAAU,CACR,QAAQ,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,sBAAsB,CAAC,6BAA6B,CAAC,CAAC,KAChG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAIrB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B/B,aAAa,IAAI,OAAO,CAAC,YAAY,CAAC;YAY9B,oBAAoB;YAgBpB,qBAAqB;IAgBnC,OAAO,CAAC,sBAAsB;IAqC9B,OAAO,CAAC,0BAA0B;IAalC,OAAO,CAAC,gBAAgB;YAQV,mBAAmB;YAYnB,SAAS;YA0BT,oBAAoB;YAkBpB,2BAA2B;YAmB3B,eAAe;YAgBf,UAAU;CA6HzB"}
|
package/build/provider.js
CHANGED
|
@@ -9,6 +9,7 @@ const frame_father_1 = require("@psdk/frame-father");
|
|
|
9
9
|
const await_timeout_1 = __importDefault(require("await-timeout"));
|
|
10
10
|
const connected_1 = require("./connected");
|
|
11
11
|
const taro_1 = __importDefault(require("@tarojs/taro"));
|
|
12
|
+
const ANDROID_BLE_MTU = 247;
|
|
12
13
|
class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
|
|
13
14
|
options;
|
|
14
15
|
discoveredCallback;
|
|
@@ -42,6 +43,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
|
|
|
42
43
|
const origin = device.origin;
|
|
43
44
|
await this.createBLEConnection({ deviceId: origin.deviceId, timeout: options?.timeout, });
|
|
44
45
|
await await_timeout_1.default.set(500);
|
|
46
|
+
const negotiatedMtu = await this.setBLEMTU(origin.deviceId);
|
|
45
47
|
const services = await this.getBLEDeviceServices({ deviceId: origin.deviceId });
|
|
46
48
|
const scpair = await this.findSCPair({
|
|
47
49
|
deviceId: origin.deviceId,
|
|
@@ -50,10 +52,14 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
|
|
|
50
52
|
if (!scpair) {
|
|
51
53
|
return Promise.reject(`Can not get write characteristic by device: ${device.name}`);
|
|
52
54
|
}
|
|
55
|
+
let flowControl = this.options?.flowControl;
|
|
56
|
+
if (flowControl?.enabled && negotiatedMtu > 0) {
|
|
57
|
+
flowControl = { ...flowControl, initialMtu: negotiatedMtu };
|
|
58
|
+
}
|
|
53
59
|
this.connectedDevice = new connected_1.TaroBleConnectedDevice({
|
|
54
60
|
device: origin,
|
|
55
61
|
scpair,
|
|
56
|
-
flowControl
|
|
62
|
+
flowControl,
|
|
57
63
|
});
|
|
58
64
|
await this.stopDiscovery();
|
|
59
65
|
return Promise.resolve(this.connectedDevice);
|
|
@@ -190,6 +196,30 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
|
|
|
190
196
|
});
|
|
191
197
|
});
|
|
192
198
|
}
|
|
199
|
+
async setBLEMTU(deviceId) {
|
|
200
|
+
try {
|
|
201
|
+
if (String(taro_1.default.getSystemInfoSync().platform).toLowerCase() !== 'android') {
|
|
202
|
+
return 0;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return 0;
|
|
207
|
+
}
|
|
208
|
+
if (typeof taro_1.default.setBLEMTU !== 'function') {
|
|
209
|
+
return 0;
|
|
210
|
+
}
|
|
211
|
+
return new Promise((resolve) => {
|
|
212
|
+
taro_1.default.setBLEMTU({
|
|
213
|
+
deviceId,
|
|
214
|
+
mtu: ANDROID_BLE_MTU,
|
|
215
|
+
success: () => resolve(ANDROID_BLE_MTU),
|
|
216
|
+
fail: (error) => {
|
|
217
|
+
console.warn('[BLE] setBLEMTU failed; using default MTU', error);
|
|
218
|
+
resolve(0);
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
}
|
|
193
223
|
async getBLEDeviceServices(options) {
|
|
194
224
|
return new Promise((resolve, reject) => {
|
|
195
225
|
taro_1.default.getBLEDeviceServices({
|