@psdk/device-ble-taro 0.5.11 → 0.5.13

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.
@@ -8,11 +8,6 @@ const frame_father_1 = require("@psdk/frame-father");
8
8
  const await_timeout_1 = __importDefault(require("await-timeout"));
9
9
  const taro_1 = __importDefault(require("@tarojs/taro"));
10
10
  class TaroBleConnectedDevice {
11
- device;
12
- scpair;
13
- _connectionState;
14
- dataOfRead;
15
- notifyCallback;
16
11
  constructor(options) {
17
12
  this.device = options.device;
18
13
  this.scpair = options.scpair;
@@ -94,11 +89,12 @@ class TaroBleConnectedDevice {
94
89
  return this.scpair.read != null;
95
90
  }
96
91
  async read(options) {
92
+ var _a;
97
93
  if (this.dataOfRead.length > 0) {
98
94
  this.dataOfRead.splice(0, this.dataOfRead.length);
99
95
  }
100
96
  await this.realRead();
101
- const timeout = (options?.timeout ?? 5000);
97
+ const timeout = ((_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 5000);
102
98
  const startTime = +new Date();
103
99
  while (true) {
104
100
  const now = +new Date();
package/build/provider.js CHANGED
@@ -10,9 +10,6 @@ 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
12
  class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
13
- options;
14
- discoveredCallback;
15
- connectedDevice;
16
13
  constructor(options) {
17
14
  super();
18
15
  this.options = options;
@@ -33,14 +30,15 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
33
30
  });
34
31
  }
35
32
  async connect(device, options) {
33
+ var _a;
36
34
  if (this.isConnected()) {
37
- if (!(options?.autoSwitchDevice ?? false)) {
35
+ if (!((_a = options === null || options === void 0 ? void 0 : options.autoSwitchDevice) !== null && _a !== void 0 ? _a : false)) {
38
36
  return this.connectedDevice;
39
37
  }
40
38
  await this.connectedDevice.disconnect();
41
39
  }
42
40
  const origin = device.origin;
43
- await this.createBLEConnection({ deviceId: origin.deviceId, timeout: options?.timeout, });
41
+ await this.createBLEConnection({ deviceId: origin.deviceId, timeout: options === null || options === void 0 ? void 0 : options.timeout, });
44
42
  await await_timeout_1.default.set(500);
45
43
  const services = await this.getBLEDeviceServices({ deviceId: origin.deviceId });
46
44
  const scpair = await this.findSCPair({
@@ -133,10 +131,11 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
133
131
  }
134
132
  const devices = foundDevices
135
133
  .filter(item => {
134
+ var _a, _b;
136
135
  const name = item.name || item.localName;
137
136
  if (name)
138
137
  return true;
139
- return this.options?.allowNoName ?? true;
138
+ return (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.allowNoName) !== null && _b !== void 0 ? _b : true;
140
139
  })
141
140
  .map(item => new device_bluetooth_traits_1.JluetoothDevice({
142
141
  origin: item,
@@ -211,6 +210,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
211
210
  });
212
211
  }
213
212
  async findSCPair(options) {
213
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
214
214
  // fill data
215
215
  const _characteristicsMap = new Map();
216
216
  for (const service of options.services) {
@@ -221,21 +221,21 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
221
221
  _characteristicsMap.set(service.uuid, characteristics);
222
222
  }
223
223
  // use special first
224
- if (this.options?.allowedWriteCharacteristic && this.options?.allowedReadCharacteristic) {
224
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowedWriteCharacteristic) && ((_b = this.options) === null || _b === void 0 ? void 0 : _b.allowedReadCharacteristic)) {
225
225
  for (const service of options.services) {
226
- if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, this.options?.allowServices)) {
226
+ if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_c = this.options) === null || _c === void 0 ? void 0 : _c.allowServices)) {
227
227
  continue;
228
228
  }
229
229
  const characteristics = _characteristicsMap.get(service.uuid);
230
230
  let writeCharacteristic = null;
231
231
  let readCharacteristic = null;
232
232
  for (const characteristic of characteristics) {
233
- if (this.options?.allowedWriteCharacteristic.toLowerCase() == characteristic.uuid.toLowerCase()) {
233
+ if (((_d = this.options) === null || _d === void 0 ? void 0 : _d.allowedWriteCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
234
234
  writeCharacteristic = characteristic;
235
235
  }
236
236
  }
237
237
  for (const characteristic of characteristics) {
238
- if (this.options?.allowedReadCharacteristic.toLowerCase() == characteristic.uuid.toLowerCase()) {
238
+ if (((_e = this.options) === null || _e === void 0 ? void 0 : _e.allowedReadCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
239
239
  readCharacteristic = characteristic;
240
240
  }
241
241
  }
@@ -250,7 +250,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
250
250
  }
251
251
  // choose best characteristic
252
252
  for (const service of options.services) {
253
- if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, this.options?.allowServices)) {
253
+ if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_f = this.options) === null || _f === void 0 ? void 0 : _f.allowServices)) {
254
254
  continue;
255
255
  }
256
256
  const characteristics = _characteristicsMap.get(service.uuid);
@@ -269,10 +269,10 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
269
269
  };
270
270
  }
271
271
  }
272
- if (this.options?.allowDetectDifferentCharacteristic ?? true) {
272
+ if ((_h = (_g = this.options) === null || _g === void 0 ? void 0 : _g.allowDetectDifferentCharacteristic) !== null && _h !== void 0 ? _h : true) {
273
273
  // choose different characteristic with write and read properties
274
274
  for (const service of options.services) {
275
- if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, this.options?.allowServices)) {
275
+ if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_j = this.options) === null || _j === void 0 ? void 0 : _j.allowServices)) {
276
276
  continue;
277
277
  }
278
278
  const characteristics = _characteristicsMap.get(service.uuid);
@@ -297,7 +297,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
297
297
  else {
298
298
  // only write
299
299
  for (const service of options.services) {
300
- if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, this.options?.allowServices)) {
300
+ if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_k = this.options) === null || _k === void 0 ? void 0 : _k.allowServices)) {
301
301
  continue;
302
302
  }
303
303
  const characteristics = _characteristicsMap.get(service.uuid);