@psdk/device-ble-taro 0.3.2 → 0.3.4

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.
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { ConnectionState } from "@psdk/frame-father";
11
2
  import Timeout from 'await-timeout';
12
3
  import Taro from "@tarojs/taro";
@@ -24,12 +15,12 @@ export class TaroBleConnectedDevice {
24
15
  doListen() {
25
16
  if (this.scpair.read == null)
26
17
  return;
27
- Taro.onBLECharacteristicValueChange((value) => __awaiter(this, void 0, void 0, function* () {
18
+ Taro.onBLECharacteristicValueChange(async (value) => {
28
19
  // this.dataOfRead.push(value)
29
20
  if (this.notifyCallback) {
30
- yield this.notifyCallback(value);
21
+ await this.notifyCallback(value);
31
22
  }
32
- }));
23
+ });
33
24
  Taro.onBLEConnectionStateChange(value => {
34
25
  this._connectionState = value.connected ? ConnectionState.CONNECTED : ConnectionState.DISCONNECTED;
35
26
  });
@@ -43,27 +34,25 @@ export class TaroBleConnectedDevice {
43
34
  fail: (e) => console.error(e),
44
35
  });
45
36
  }
46
- realRead() {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- return new Promise((resolve, reject) => {
49
- if (this.scpair.read == null) {
50
- reject(`the connect device not support read operation: service id: [${this.scpair.service.uuid}]`);
51
- return;
52
- }
53
- Taro.readBLECharacteristicValue({
54
- deviceId: this.device.deviceId,
55
- serviceId: this.scpair.service.uuid,
56
- characteristicId: this.scpair.read.uuid,
57
- success: result => {
58
- if (result.errMsg.indexOf('ok') == -1) {
59
- reject(result.errMsg);
60
- return;
61
- }
62
- resolve();
63
- },
64
- // @ts-ignore
65
- fail: (e) => reject(e),
66
- });
37
+ async realRead() {
38
+ return new Promise((resolve, reject) => {
39
+ if (this.scpair.read == null) {
40
+ reject(`the connect device not support read operation: service id: [${this.scpair.service.uuid}]`);
41
+ return;
42
+ }
43
+ Taro.readBLECharacteristicValue({
44
+ deviceId: this.device.deviceId,
45
+ serviceId: this.scpair.service.uuid,
46
+ characteristicId: this.scpair.read.uuid,
47
+ success: result => {
48
+ if (result.errMsg.indexOf('ok') == -1) {
49
+ reject(result.errMsg);
50
+ return;
51
+ }
52
+ resolve();
53
+ },
54
+ // @ts-ignore
55
+ fail: (e) => reject(e),
67
56
  });
68
57
  });
69
58
  }
@@ -76,68 +65,62 @@ export class TaroBleConnectedDevice {
76
65
  deviceName() {
77
66
  return this.device.localName || this.device.name || 'NONE';
78
67
  }
79
- disconnect() {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- return new Promise((resolve, reject) => {
82
- Taro.closeBLEConnection({
83
- deviceId: this.device.deviceId,
84
- success: () => {
85
- this.device = null;
86
- this.scpair = null;
87
- resolve();
88
- },
89
- // @ts-ignore
90
- fail: (e) => reject(e),
91
- });
68
+ async disconnect() {
69
+ return new Promise((resolve, reject) => {
70
+ Taro.closeBLEConnection({
71
+ deviceId: this.device.deviceId,
72
+ success: () => {
73
+ this.device = null;
74
+ this.scpair = null;
75
+ resolve();
76
+ },
77
+ // @ts-ignore
78
+ fail: (e) => reject(e),
92
79
  });
93
80
  });
94
81
  }
95
82
  canRead() {
96
83
  return this.scpair.read != null;
97
84
  }
98
- read(options) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- var _a;
101
- if (this.dataOfRead.length > 0) {
102
- this.dataOfRead.splice(0, this.dataOfRead.length);
85
+ async read(options) {
86
+ var _a;
87
+ if (this.dataOfRead.length > 0) {
88
+ this.dataOfRead.splice(0, this.dataOfRead.length);
89
+ }
90
+ await this.realRead();
91
+ const timeout = ((_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 5000);
92
+ const startTime = +new Date();
93
+ while (true) {
94
+ const now = +new Date();
95
+ if (now - startTime > timeout) {
96
+ return new Uint8Array([]);
103
97
  }
104
- yield this.realRead();
105
- const timeout = ((_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 5000);
106
- const startTime = +new Date();
107
- while (true) {
108
- const now = +new Date();
109
- if (now - startTime > timeout) {
110
- return new Uint8Array([]);
111
- }
112
- if (this.dataOfRead.length == 0) {
113
- yield Timeout.set(100);
114
- continue;
115
- }
116
- const data = this.dataOfRead.pop();
117
- const value = data.value;
118
- return new Uint8Array(value);
98
+ if (this.dataOfRead.length == 0) {
99
+ await Timeout.set(100);
100
+ continue;
119
101
  }
120
- });
102
+ const data = this.dataOfRead.pop();
103
+ const value = data.value;
104
+ return new Uint8Array(value);
105
+ }
121
106
  }
122
- write(data) {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- return new Promise((resolve, reject) => {
125
- Taro.writeBLECharacteristicValue({
126
- deviceId: this.device.deviceId,
127
- serviceId: this.scpair.service.uuid,
128
- characteristicId: this.scpair.write.uuid,
129
- // @ts-ignore
130
- value: data.buffer,
131
- success: result => {
132
- if (result.errMsg.indexOf('ok') == -1) {
133
- reject(result.errMsg);
134
- return;
135
- }
136
- resolve();
137
- },
138
- // @ts-ignore
139
- fail: (e) => reject(e)
140
- });
107
+ async write(data) {
108
+ return new Promise((resolve, reject) => {
109
+ Taro.writeBLECharacteristicValue({
110
+ deviceId: this.device.deviceId,
111
+ serviceId: this.scpair.service.uuid,
112
+ characteristicId: this.scpair.write.uuid,
113
+ // @ts-ignore
114
+ value: data.buffer,
115
+ success: result => {
116
+ if (result.errMsg.indexOf('ok') == -1) {
117
+ reject(result.errMsg);
118
+ return;
119
+ }
120
+ resolve();
121
+ },
122
+ // @ts-ignore
123
+ fail: (e) => reject(e)
141
124
  });
142
125
  });
143
126
  }
package/build/provider.js CHANGED
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { Jluetooth, JluetoothDevice, TBluetoothHelpers, } from "@psdk/device-bluetooth-traits";
11
2
  import { ConnectionState } from "@psdk/frame-father";
12
3
  import Timeout from 'await-timeout';
@@ -23,123 +14,111 @@ export class TaroBleBluetooth extends Jluetooth {
23
14
  return false;
24
15
  return this.connectedDevice.connectionState() === ConnectionState.CONNECTED;
25
16
  }
26
- bluetoothAdapterState() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- return new Promise((resolve, reject) => {
29
- Taro.getBluetoothAdapterState({
30
- success: (r) => resolve(r),
31
- // @ts-ignore
32
- fail: (e) => reject(e)
33
- });
17
+ async bluetoothAdapterState() {
18
+ return new Promise((resolve, reject) => {
19
+ Taro.getBluetoothAdapterState({
20
+ success: (r) => resolve(r),
21
+ // @ts-ignore
22
+ fail: (e) => reject(e)
34
23
  });
35
24
  });
36
25
  }
37
- connect(device, options) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- var _a;
40
- if (this.isConnected()) {
41
- if (!((_a = options === null || options === void 0 ? void 0 : options.autoSwitchDevice) !== null && _a !== void 0 ? _a : false)) {
42
- return this.connectedDevice;
43
- }
44
- yield this.connectedDevice.disconnect();
45
- }
46
- const origin = device.origin;
47
- yield this.createBLEConnection({ deviceId: origin.deviceId, timeout: options === null || options === void 0 ? void 0 : options.timeout, });
48
- yield Timeout.set(500);
49
- const services = yield this.getBLEDeviceServices({ deviceId: origin.deviceId });
50
- const scpair = yield this.findSCPair({
51
- deviceId: origin.deviceId,
52
- services,
53
- });
54
- if (!scpair) {
55
- return Promise.reject(`Can not get write characteristic by device: ${device.name}`);
26
+ async connect(device, options) {
27
+ var _a;
28
+ if (this.isConnected()) {
29
+ if (!((_a = options === null || options === void 0 ? void 0 : options.autoSwitchDevice) !== null && _a !== void 0 ? _a : false)) {
30
+ return this.connectedDevice;
56
31
  }
57
- this.connectedDevice = new TaroBleConnectedDevice({
58
- device: origin,
59
- scpair,
60
- });
61
- yield this.stopDiscovery();
62
- return Promise.resolve(this.connectedDevice);
32
+ await this.connectedDevice.disconnect();
33
+ }
34
+ const origin = device.origin;
35
+ await this.createBLEConnection({ deviceId: origin.deviceId, timeout: options === null || options === void 0 ? void 0 : options.timeout, });
36
+ await Timeout.set(500);
37
+ const services = await this.getBLEDeviceServices({ deviceId: origin.deviceId });
38
+ const scpair = await this.findSCPair({
39
+ deviceId: origin.deviceId,
40
+ services,
63
41
  });
42
+ if (!scpair) {
43
+ return Promise.reject(`Can not get write characteristic by device: ${device.name}`);
44
+ }
45
+ this.connectedDevice = new TaroBleConnectedDevice({
46
+ device: origin,
47
+ scpair,
48
+ });
49
+ await this.stopDiscovery();
50
+ return Promise.resolve(this.connectedDevice);
64
51
  }
65
52
  discovered(callback) {
66
53
  this.discoveredCallback = callback;
67
54
  }
68
- startDiscovery() {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- yield this.requestLocation();
71
- yield this.closeBluetoothAdapter();
72
- yield Timeout.set(300);
73
- yield this.openBluetoothAdapter();
74
- const state = yield this.bluetoothAdapterState();
75
- if (!state.available) {
76
- yield Timeout.set(500);
77
- }
78
- if (state.discovering) {
79
- yield this.stopDiscovery();
80
- yield Timeout.set(500);
81
- }
82
- return new Promise((resolve, reject) => {
83
- Taro.startBluetoothDevicesDiscovery({
84
- // services: this.allowServices,
85
- allowDuplicatesKey: false,
86
- interval: 0,
87
- success: () => resolve(),
88
- // @ts-ignore
89
- fail: (e) => reject(e),
90
- // complete: () => resolve(),
91
- });
55
+ async startDiscovery() {
56
+ await this.requestLocation();
57
+ await this.closeBluetoothAdapter();
58
+ await Timeout.set(300);
59
+ await this.openBluetoothAdapter();
60
+ const state = await this.bluetoothAdapterState();
61
+ if (!state.available) {
62
+ await Timeout.set(500);
63
+ }
64
+ if (state.discovering) {
65
+ await this.stopDiscovery();
66
+ await Timeout.set(500);
67
+ }
68
+ return new Promise((resolve, reject) => {
69
+ Taro.startBluetoothDevicesDiscovery({
70
+ // services: this.allowServices,
71
+ allowDuplicatesKey: false,
72
+ interval: 0,
73
+ success: () => resolve(),
74
+ // @ts-ignore
75
+ fail: (e) => reject(e),
76
+ // complete: () => resolve(),
92
77
  });
93
78
  });
94
79
  }
95
- stopDiscovery() {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- return new Promise((resolve, reject) => {
98
- Taro.stopBluetoothDevicesDiscovery({
99
- success: (result) => resolve(result),
100
- // @ts-ignore
101
- fail: (e) => reject(e),
102
- });
80
+ async stopDiscovery() {
81
+ return new Promise((resolve, reject) => {
82
+ Taro.stopBluetoothDevicesDiscovery({
83
+ success: (result) => resolve(result),
84
+ // @ts-ignore
85
+ fail: (e) => reject(e),
103
86
  });
104
87
  });
105
88
  }
106
89
  // ### inner function
107
- openBluetoothAdapter() {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- return new Promise((resolve, reject) => {
110
- Taro.openBluetoothAdapter({
111
- success: (ret) => {
112
- if (ret.errMsg && ret.errMsg.indexOf('ok') == -1) {
113
- reject(ret);
114
- return;
115
- }
116
- resolve();
117
- },
118
- // @ts-ignore
119
- fail: (e) => reject(e)
120
- });
90
+ async openBluetoothAdapter() {
91
+ return new Promise((resolve, reject) => {
92
+ Taro.openBluetoothAdapter({
93
+ success: (ret) => {
94
+ if (ret.errMsg && ret.errMsg.indexOf('ok') == -1) {
95
+ reject(ret);
96
+ return;
97
+ }
98
+ resolve();
99
+ },
100
+ // @ts-ignore
101
+ fail: (e) => reject(e)
121
102
  });
122
103
  });
123
104
  }
124
- closeBluetoothAdapter() {
125
- return __awaiter(this, void 0, void 0, function* () {
126
- return new Promise((resolve, reject) => {
127
- Taro.closeBluetoothAdapter({
128
- success: (ret) => {
129
- if (ret.errMsg && ret.errMsg.indexOf('ok') == -1) {
130
- reject(ret);
131
- return;
132
- }
133
- resolve();
134
- },
135
- // @ts-ignore
136
- fail: (e) => reject(e)
137
- });
105
+ async closeBluetoothAdapter() {
106
+ return new Promise((resolve, reject) => {
107
+ Taro.closeBluetoothAdapter({
108
+ success: (ret) => {
109
+ if (ret.errMsg && ret.errMsg.indexOf('ok') == -1) {
110
+ reject(ret);
111
+ return;
112
+ }
113
+ resolve();
114
+ },
115
+ // @ts-ignore
116
+ fail: (e) => reject(e)
138
117
  });
139
118
  });
140
119
  }
141
120
  onBluetoothDeviceFound() {
142
- Taro.onBluetoothDeviceFound((result) => __awaiter(this, void 0, void 0, function* () {
121
+ Taro.onBluetoothDeviceFound(async (result) => {
143
122
  const foundDevices = result.devices;
144
123
  if (!foundDevices.length) {
145
124
  return;
@@ -161,183 +140,173 @@ export class TaroBleBluetooth extends Jluetooth {
161
140
  return;
162
141
  }
163
142
  if (this.discoveredCallback) {
164
- yield this.discoveredCallback(devices);
143
+ await this.discoveredCallback(devices);
165
144
  }
166
- }));
145
+ });
167
146
  }
168
- createBLEConnection(options) {
169
- return __awaiter(this, void 0, void 0, function* () {
170
- return new Promise((resolve, reject) => {
171
- Taro.createBLEConnection({
172
- deviceId: options.deviceId,
173
- timeout: options.timeout,
174
- success: () => resolve(),
175
- // @ts-ignore
176
- fail: (e) => reject(e),
177
- });
147
+ async createBLEConnection(options) {
148
+ return new Promise((resolve, reject) => {
149
+ Taro.createBLEConnection({
150
+ deviceId: options.deviceId,
151
+ timeout: options.timeout,
152
+ success: () => resolve(),
153
+ // @ts-ignore
154
+ fail: (e) => reject(e),
178
155
  });
179
156
  });
180
157
  }
181
- getBLEDeviceServices(options) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- return new Promise((resolve, reject) => {
184
- Taro.getBLEDeviceServices({
185
- deviceId: options.deviceId,
186
- success: (result) => {
187
- if (result.errMsg.indexOf('ok') == -1) {
188
- reject(result.errMsg);
189
- return;
190
- }
191
- resolve(result.services);
192
- },
193
- // @ts-ignore
194
- fail: (e) => reject(e),
195
- });
158
+ async getBLEDeviceServices(options) {
159
+ return new Promise((resolve, reject) => {
160
+ Taro.getBLEDeviceServices({
161
+ deviceId: options.deviceId,
162
+ success: (result) => {
163
+ if (result.errMsg.indexOf('ok') == -1) {
164
+ reject(result.errMsg);
165
+ return;
166
+ }
167
+ resolve(result.services);
168
+ },
169
+ // @ts-ignore
170
+ fail: (e) => reject(e),
196
171
  });
197
172
  });
198
173
  }
199
- getBLEDeviceCharacteristics(options) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- return new Promise((resolve, reject) => {
202
- Taro.getBLEDeviceCharacteristics({
203
- deviceId: options.deviceId,
204
- serviceId: options.serviceId,
205
- success: (result) => {
206
- if (result.errMsg.indexOf('ok') == -1) {
207
- reject(result.errMsg);
208
- return;
209
- }
210
- resolve(result.characteristics);
211
- },
212
- // @ts-ignore
213
- fail: (e) => reject(e),
214
- });
174
+ async getBLEDeviceCharacteristics(options) {
175
+ return new Promise((resolve, reject) => {
176
+ Taro.getBLEDeviceCharacteristics({
177
+ deviceId: options.deviceId,
178
+ serviceId: options.serviceId,
179
+ success: (result) => {
180
+ if (result.errMsg.indexOf('ok') == -1) {
181
+ reject(result.errMsg);
182
+ return;
183
+ }
184
+ resolve(result.characteristics);
185
+ },
186
+ // @ts-ignore
187
+ fail: (e) => reject(e),
215
188
  });
216
189
  });
217
190
  }
218
- requestLocation() {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- return new Promise((resolve, reject) => {
221
- // Taro.authorize({
222
- // scope: 'scope.userLocation',
223
- // success: () => resolve(),
224
- // // @ts-ignore
225
- // fail: (e) => reject(e),
226
- // });
227
- Taro.getLocation({
228
- success: () => resolve(),
229
- // @ts-ignore
230
- fail: (e) => reject(e),
231
- });
191
+ async requestLocation() {
192
+ return new Promise((resolve, reject) => {
193
+ // Taro.authorize({
194
+ // scope: 'scope.userLocation',
195
+ // success: () => resolve(),
196
+ // // @ts-ignore
197
+ // fail: (e) => reject(e),
198
+ // });
199
+ Taro.getLocation({
200
+ success: () => resolve(),
201
+ // @ts-ignore
202
+ fail: (e) => reject(e),
232
203
  });
233
204
  });
234
205
  }
235
- findSCPair(options) {
236
- return __awaiter(this, void 0, void 0, function* () {
237
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
238
- // fill data
239
- const _characteristicsMap = new Map();
206
+ async findSCPair(options) {
207
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
208
+ // fill data
209
+ const _characteristicsMap = new Map();
210
+ for (const service of options.services) {
211
+ const characteristics = await this.getBLEDeviceCharacteristics({
212
+ deviceId: options.deviceId,
213
+ serviceId: service.uuid,
214
+ });
215
+ _characteristicsMap.set(service.uuid, characteristics);
216
+ }
217
+ // use special first
218
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowedWriteCharacteristic) && ((_b = this.options) === null || _b === void 0 ? void 0 : _b.allowedReadCharacteristic)) {
240
219
  for (const service of options.services) {
241
- const characteristics = yield this.getBLEDeviceCharacteristics({
242
- deviceId: options.deviceId,
243
- serviceId: service.uuid,
244
- });
245
- _characteristicsMap.set(service.uuid, characteristics);
246
- }
247
- // use special first
248
- if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowedWriteCharacteristic) && ((_b = this.options) === null || _b === void 0 ? void 0 : _b.allowedReadCharacteristic)) {
249
- for (const service of options.services) {
250
- if (!TBluetoothHelpers.isAllowServices(service.uuid, (_c = this.options) === null || _c === void 0 ? void 0 : _c.allowServices)) {
251
- continue;
252
- }
253
- const characteristics = _characteristicsMap.get(service.uuid);
254
- let writeCharacteristic = null;
255
- let readCharacteristic = null;
256
- for (const characteristic of characteristics) {
257
- if (((_d = this.options) === null || _d === void 0 ? void 0 : _d.allowedWriteCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
258
- writeCharacteristic = characteristic;
259
- }
260
- }
261
- for (const characteristic of characteristics) {
262
- if (((_e = this.options) === null || _e === void 0 ? void 0 : _e.allowedReadCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
263
- readCharacteristic = characteristic;
264
- }
220
+ if (!TBluetoothHelpers.isAllowServices(service.uuid, (_c = this.options) === null || _c === void 0 ? void 0 : _c.allowServices)) {
221
+ continue;
222
+ }
223
+ const characteristics = _characteristicsMap.get(service.uuid);
224
+ let writeCharacteristic = null;
225
+ let readCharacteristic = null;
226
+ for (const characteristic of characteristics) {
227
+ if (((_d = this.options) === null || _d === void 0 ? void 0 : _d.allowedWriteCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
228
+ writeCharacteristic = characteristic;
265
229
  }
266
- if (writeCharacteristic != null && readCharacteristic != null) {
267
- return {
268
- service,
269
- write: writeCharacteristic,
270
- read: readCharacteristic,
271
- };
230
+ }
231
+ for (const characteristic of characteristics) {
232
+ if (((_e = this.options) === null || _e === void 0 ? void 0 : _e.allowedReadCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
233
+ readCharacteristic = characteristic;
272
234
  }
273
235
  }
236
+ if (writeCharacteristic != null && readCharacteristic != null) {
237
+ return {
238
+ service,
239
+ write: writeCharacteristic,
240
+ read: readCharacteristic,
241
+ };
242
+ }
243
+ }
244
+ }
245
+ // choose best characteristic
246
+ for (const service of options.services) {
247
+ if (!TBluetoothHelpers.isAllowServices(service.uuid, (_f = this.options) === null || _f === void 0 ? void 0 : _f.allowServices)) {
248
+ continue;
274
249
  }
275
- // choose best characteristic
250
+ const characteristics = _characteristicsMap.get(service.uuid);
251
+ // let readCharacteristic: GetBLEDeviceCharacteristicsSuccessData;
252
+ // let writeCharacteristic: GetBLEDeviceCharacteristicsSuccessData;
253
+ const pickedCharacteristic = characteristics.find(characteristic => {
254
+ const properties = characteristic.properties;
255
+ // @ts-ignore
256
+ return properties.write && (properties.notify);
257
+ });
258
+ if (pickedCharacteristic) {
259
+ return {
260
+ service,
261
+ write: pickedCharacteristic,
262
+ read: pickedCharacteristic,
263
+ };
264
+ }
265
+ }
266
+ if ((_h = (_g = this.options) === null || _g === void 0 ? void 0 : _g.allowDetectDifferentCharacteristic) !== null && _h !== void 0 ? _h : true) {
267
+ // choose different characteristic with write and read properties
276
268
  for (const service of options.services) {
277
- if (!TBluetoothHelpers.isAllowServices(service.uuid, (_f = this.options) === null || _f === void 0 ? void 0 : _f.allowServices)) {
269
+ if (!TBluetoothHelpers.isAllowServices(service.uuid, (_j = this.options) === null || _j === void 0 ? void 0 : _j.allowServices)) {
278
270
  continue;
279
271
  }
280
272
  const characteristics = _characteristicsMap.get(service.uuid);
281
- // let readCharacteristic: GetBLEDeviceCharacteristicsSuccessData;
282
- // let writeCharacteristic: GetBLEDeviceCharacteristicsSuccessData;
283
- const pickedCharacteristic = characteristics.find(characteristic => {
273
+ const writeCharacteristic = characteristics.find(characteristic => {
284
274
  const properties = characteristic.properties;
285
275
  // @ts-ignore
286
- return properties.write && (properties.notify);
276
+ return properties.write;
277
+ });
278
+ const readCharacteristic = characteristics.find(characteristic => {
279
+ const properties = characteristic.properties;
280
+ return (properties.notify);
287
281
  });
288
- if (pickedCharacteristic) {
282
+ if (writeCharacteristic && readCharacteristic) {
289
283
  return {
290
284
  service,
291
- write: pickedCharacteristic,
292
- read: pickedCharacteristic,
285
+ write: writeCharacteristic,
286
+ read: readCharacteristic,
293
287
  };
294
288
  }
295
289
  }
296
- if ((_h = (_g = this.options) === null || _g === void 0 ? void 0 : _g.allowDetectDifferentCharacteristic) !== null && _h !== void 0 ? _h : true) {
297
- // choose different characteristic with write and read properties
298
- for (const service of options.services) {
299
- if (!TBluetoothHelpers.isAllowServices(service.uuid, (_j = this.options) === null || _j === void 0 ? void 0 : _j.allowServices)) {
300
- continue;
301
- }
302
- const characteristics = _characteristicsMap.get(service.uuid);
303
- const writeCharacteristic = characteristics.find(characteristic => {
304
- const properties = characteristic.properties;
305
- // @ts-ignore
306
- return properties.write;
307
- });
308
- const readCharacteristic = characteristics.find(characteristic => {
309
- const properties = characteristic.properties;
310
- return (properties.notify);
311
- });
312
- if (writeCharacteristic && readCharacteristic) {
313
- return {
314
- service,
315
- write: writeCharacteristic,
316
- read: readCharacteristic,
317
- };
318
- }
290
+ }
291
+ else {
292
+ // only write
293
+ for (const service of options.services) {
294
+ if (!TBluetoothHelpers.isAllowServices(service.uuid, (_k = this.options) === null || _k === void 0 ? void 0 : _k.allowServices)) {
295
+ continue;
319
296
  }
320
- }
321
- else {
322
- // only write
323
- for (const service of options.services) {
324
- if (!TBluetoothHelpers.isAllowServices(service.uuid, (_k = this.options) === null || _k === void 0 ? void 0 : _k.allowServices)) {
325
- continue;
326
- }
327
- const characteristics = _characteristicsMap.get(service.uuid);
328
- const writeCharacteristic = characteristics.find(characteristic => {
329
- const properties = characteristic.properties;
330
- // @ts-ignore
331
- return properties.write;
332
- });
333
- if (writeCharacteristic) {
334
- return {
335
- service,
336
- write: writeCharacteristic,
337
- };
338
- }
297
+ const characteristics = _characteristicsMap.get(service.uuid);
298
+ const writeCharacteristic = characteristics.find(characteristic => {
299
+ const properties = characteristic.properties;
300
+ // @ts-ignore
301
+ return properties.write;
302
+ });
303
+ if (writeCharacteristic) {
304
+ return {
305
+ service,
306
+ write: writeCharacteristic,
307
+ };
339
308
  }
340
309
  }
341
- });
310
+ }
342
311
  }
343
312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psdk/device-ble-taro",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "psdk",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -27,13 +27,13 @@
27
27
  "typescript": "^5.4.5"
28
28
  },
29
29
  "dependencies": {
30
- "@psdk/device-bluetooth-traits": "0.3.2",
31
- "@psdk/frame-father": "0.3.2",
30
+ "@psdk/device-bluetooth-traits": "0.3.4",
31
+ "@psdk/frame-father": "0.3.4",
32
32
  "await-timeout": "^1.1.1"
33
33
  },
34
34
  "files": [
35
35
  "build",
36
36
  "!build/browser/psdk*"
37
37
  ],
38
- "gitHead": "479d209e3e23855e803872dffaeecf8a6c5e16dc"
38
+ "gitHead": "b8c2fdcb52f1bd3e9d75d004d37d717bd465b4c9"
39
39
  }