@psdk/device-ble-taro 0.2.57 → 0.2.59
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/connected.d.ts +2 -0
- package/build/connected.d.ts.map +1 -1
- package/build/connected.js +20 -12
- package/build/provider.d.ts.map +1 -1
- package/build/provider.js +23 -14
- package/package.json +4 -4
package/build/connected.d.ts
CHANGED
|
@@ -5,10 +5,12 @@ export declare class TaroBleConnectedDevice implements ConnectedDevice {
|
|
|
5
5
|
private scpair;
|
|
6
6
|
private _connectionState;
|
|
7
7
|
private dataOfRead;
|
|
8
|
+
private notifyCallback?;
|
|
8
9
|
constructor(options: {
|
|
9
10
|
device: Taro.onBluetoothDeviceFound.CallbackResultBlueToothDevice;
|
|
10
11
|
scpair: ServiceCharacteristicPair;
|
|
11
12
|
});
|
|
13
|
+
notify(callback: (value: Taro.onBLECharacteristicValueChange.CallbackResult) => Promise<void>): void;
|
|
12
14
|
private doListen;
|
|
13
15
|
private realRead;
|
|
14
16
|
connectionState(): ConnectionState;
|
package/build/connected.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connected.d.ts","sourceRoot":"","sources":["../src/connected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,eAAe,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAEjF,OAAO,IAAI,MAAM,cAAc,CAAC;AAEhC,qBAAa,sBAAuB,YAAW,eAAe;IAC5D,OAAO,CAAC,MAAM,CAA4D;IAC1E,OAAO,CAAC,MAAM,CAA4B;IAE1C,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,UAAU,CAA4D;
|
|
1
|
+
{"version":3,"file":"connected.d.ts","sourceRoot":"","sources":["../src/connected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,eAAe,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAEjF,OAAO,IAAI,MAAM,cAAc,CAAC;AAEhC,qBAAa,sBAAuB,YAAW,eAAe;IAC5D,OAAO,CAAC,MAAM,CAA4D;IAC1E,OAAO,CAAC,MAAM,CAA4B;IAE1C,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,UAAU,CAA4D;IAC9E,OAAO,CAAC,cAAc,CAAC,CAA+E;gBAEnF,OAAO,EAAE;QAC1B,MAAM,EAAE,IAAI,CAAC,sBAAsB,CAAC,6BAA6B,CAAC;QAClE,MAAM,EAAE,yBAAyB,CAAC;KACnC;IAQD,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,8BAA8B,CAAC,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAIpG,OAAO,CAAC,QAAQ;YAsBF,QAAQ;IAuBtB,eAAe,IAAI,eAAe;IAIlC,UAAU,IAAI,MAAM;IAId,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAejC,OAAO,IAAI,OAAO;IAIZ,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAsBhD,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB5C,KAAK,IAAI,IAAI;CAId;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC;IAC9C,KAAK,EAAE,IAAI,CAAC,2BAA2B,CAAC,iBAAiB,CAAC;IAC1D,IAAI,CAAC,EAAE,IAAI,CAAC,2BAA2B,CAAC,iBAAiB,CAAC;CAC3D"}
|
package/build/connected.js
CHANGED
|
@@ -24,22 +24,30 @@ class TaroBleConnectedDevice {
|
|
|
24
24
|
this.dataOfRead = [];
|
|
25
25
|
this.doListen();
|
|
26
26
|
}
|
|
27
|
+
notify(callback) {
|
|
28
|
+
this.notifyCallback = callback;
|
|
29
|
+
}
|
|
27
30
|
doListen() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
if (this.scpair.read == null)
|
|
32
|
+
return;
|
|
33
|
+
taro_1.default.onBLECharacteristicValueChange((value) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
// this.dataOfRead.push(value)
|
|
35
|
+
if (this.notifyCallback) {
|
|
36
|
+
yield this.notifyCallback(value);
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
31
39
|
taro_1.default.onBLEConnectionStateChange(value => {
|
|
32
40
|
this._connectionState = value.connected ? frame_father_1.ConnectionState.CONNECTED : frame_father_1.ConnectionState.DISCONNECTED;
|
|
33
41
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
taro_1.default.notifyBLECharacteristicValueChange({
|
|
43
|
+
deviceId: this.device.deviceId,
|
|
44
|
+
serviceId: this.scpair.service.uuid,
|
|
45
|
+
characteristicId: this.scpair.read.uuid,
|
|
46
|
+
state: true,
|
|
47
|
+
success: result => console.log(result),
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
fail: (e) => console.error(e),
|
|
50
|
+
});
|
|
43
51
|
}
|
|
44
52
|
realRead() {
|
|
45
53
|
return __awaiter(this, void 0, void 0, function* () {
|
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,EACd,SAAS,EACT,eAAe,EACf,eAAe,EAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAC,eAAe,EAAkB,MAAM,oBAAoB,CAAC;AAGpE,OAAO,IAAI,MAAM,cAAc,CAAC;AAEhC,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,IAAI,CAAC,sBAAsB,CAAC,6BAA6B,CAAC;IAExG,OAAO,C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C,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;IA2B3B,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;YA0BhB,mBAAmB;YAYnB,oBAAoB;YAkBpB,2BAA2B;YAmB3B,eAAe;YAgBf,UAAU;CAkHzB"}
|
package/build/provider.js
CHANGED
|
@@ -239,7 +239,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
|
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
241
|
findSCPair(options) {
|
|
242
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
242
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
243
243
|
return __awaiter(this, void 0, void 0, function* () {
|
|
244
244
|
// fill data
|
|
245
245
|
const _characteristicsMap = new Map();
|
|
@@ -251,27 +251,36 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
|
|
|
251
251
|
_characteristicsMap.set(service.uuid, characteristics);
|
|
252
252
|
}
|
|
253
253
|
// use special first
|
|
254
|
-
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.
|
|
254
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowedWriteCharacteristic) && ((_b = this.options) === null || _b === void 0 ? void 0 : _b.allowedReadCharacteristic)) {
|
|
255
255
|
for (const service of options.services) {
|
|
256
|
-
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (
|
|
256
|
+
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_c = this.options) === null || _c === void 0 ? void 0 : _c.allowServices)) {
|
|
257
257
|
continue;
|
|
258
258
|
}
|
|
259
259
|
const characteristics = _characteristicsMap.get(service.uuid);
|
|
260
|
+
let writeCharacteristic = null;
|
|
261
|
+
let readCharacteristic = null;
|
|
260
262
|
for (const characteristic of characteristics) {
|
|
261
|
-
if (((
|
|
262
|
-
|
|
263
|
-
|
|
263
|
+
if (((_d = this.options) === null || _d === void 0 ? void 0 : _d.allowedWriteCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
|
|
264
|
+
writeCharacteristic = characteristic;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
for (const characteristic of characteristics) {
|
|
268
|
+
if (((_e = this.options) === null || _e === void 0 ? void 0 : _e.allowedReadCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
|
|
269
|
+
readCharacteristic = characteristic;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (writeCharacteristic != null && readCharacteristic != null) {
|
|
264
273
|
return {
|
|
265
274
|
service,
|
|
266
|
-
write:
|
|
267
|
-
read:
|
|
275
|
+
write: writeCharacteristic,
|
|
276
|
+
read: readCharacteristic,
|
|
268
277
|
};
|
|
269
278
|
}
|
|
270
279
|
}
|
|
271
280
|
}
|
|
272
281
|
// choose best characteristic
|
|
273
282
|
for (const service of options.services) {
|
|
274
|
-
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (
|
|
283
|
+
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_f = this.options) === null || _f === void 0 ? void 0 : _f.allowServices)) {
|
|
275
284
|
continue;
|
|
276
285
|
}
|
|
277
286
|
const characteristics = _characteristicsMap.get(service.uuid);
|
|
@@ -280,7 +289,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
|
|
|
280
289
|
const pickedCharacteristic = characteristics.find(characteristic => {
|
|
281
290
|
const properties = characteristic.properties;
|
|
282
291
|
// @ts-ignore
|
|
283
|
-
return properties.write && (properties.
|
|
292
|
+
return properties.write && (properties.notify);
|
|
284
293
|
});
|
|
285
294
|
if (pickedCharacteristic) {
|
|
286
295
|
return {
|
|
@@ -290,10 +299,10 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
|
|
|
290
299
|
};
|
|
291
300
|
}
|
|
292
301
|
}
|
|
293
|
-
if ((
|
|
302
|
+
if ((_h = (_g = this.options) === null || _g === void 0 ? void 0 : _g.allowDetectDifferentCharacteristic) !== null && _h !== void 0 ? _h : true) {
|
|
294
303
|
// choose different characteristic with write and read properties
|
|
295
304
|
for (const service of options.services) {
|
|
296
|
-
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (
|
|
305
|
+
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_j = this.options) === null || _j === void 0 ? void 0 : _j.allowServices)) {
|
|
297
306
|
continue;
|
|
298
307
|
}
|
|
299
308
|
const characteristics = _characteristicsMap.get(service.uuid);
|
|
@@ -304,7 +313,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
|
|
|
304
313
|
});
|
|
305
314
|
const readCharacteristic = characteristics.find(characteristic => {
|
|
306
315
|
const properties = characteristic.properties;
|
|
307
|
-
return (properties.
|
|
316
|
+
return (properties.notify);
|
|
308
317
|
});
|
|
309
318
|
if (writeCharacteristic && readCharacteristic) {
|
|
310
319
|
return {
|
|
@@ -318,7 +327,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
|
|
|
318
327
|
else {
|
|
319
328
|
// only write
|
|
320
329
|
for (const service of options.services) {
|
|
321
|
-
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (
|
|
330
|
+
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_k = this.options) === null || _k === void 0 ? void 0 : _k.allowServices)) {
|
|
322
331
|
continue;
|
|
323
332
|
}
|
|
324
333
|
const characteristics = _characteristicsMap.get(service.uuid);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@psdk/device-ble-taro",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.59",
|
|
4
4
|
"description": "psdk",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"webpack-cli": "^4.9.2"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@psdk/device-bluetooth-traits": "0.2.
|
|
50
|
-
"@psdk/frame-father": "0.2.
|
|
49
|
+
"@psdk/device-bluetooth-traits": "0.2.59",
|
|
50
|
+
"@psdk/frame-father": "0.2.59",
|
|
51
51
|
"await-timeout": "^1.1.1"
|
|
52
52
|
},
|
|
53
53
|
"files": [
|
|
54
54
|
"build",
|
|
55
55
|
"!build/browser/psdk*"
|
|
56
56
|
],
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "5f2a48ddd7c5a15ec63854fa5dc086b60617e972"
|
|
58
58
|
}
|