@psdk/device-ble-taro 0.2.65 → 0.3.0

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,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,19 +7,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.TaroBleConnectedDevice = void 0;
16
- const frame_father_1 = require("@psdk/frame-father");
17
- const await_timeout_1 = __importDefault(require("await-timeout"));
18
- const taro_1 = __importDefault(require("@tarojs/taro"));
19
- class TaroBleConnectedDevice {
10
+ import { ConnectionState } from "@psdk/frame-father";
11
+ import Timeout from 'await-timeout';
12
+ import Taro from "@tarojs/taro";
13
+ export class TaroBleConnectedDevice {
20
14
  constructor(options) {
21
15
  this.device = options.device;
22
16
  this.scpair = options.scpair;
23
- this._connectionState = frame_father_1.ConnectionState.CONNECTED;
17
+ this._connectionState = ConnectionState.CONNECTED;
24
18
  this.dataOfRead = [];
25
19
  this.doListen();
26
20
  }
@@ -30,16 +24,16 @@ class TaroBleConnectedDevice {
30
24
  doListen() {
31
25
  if (this.scpair.read == null)
32
26
  return;
33
- taro_1.default.onBLECharacteristicValueChange((value) => __awaiter(this, void 0, void 0, function* () {
27
+ Taro.onBLECharacteristicValueChange((value) => __awaiter(this, void 0, void 0, function* () {
34
28
  // this.dataOfRead.push(value)
35
29
  if (this.notifyCallback) {
36
30
  yield this.notifyCallback(value);
37
31
  }
38
32
  }));
39
- taro_1.default.onBLEConnectionStateChange(value => {
40
- this._connectionState = value.connected ? frame_father_1.ConnectionState.CONNECTED : frame_father_1.ConnectionState.DISCONNECTED;
33
+ Taro.onBLEConnectionStateChange(value => {
34
+ this._connectionState = value.connected ? ConnectionState.CONNECTED : ConnectionState.DISCONNECTED;
41
35
  });
42
- taro_1.default.notifyBLECharacteristicValueChange({
36
+ Taro.notifyBLECharacteristicValueChange({
43
37
  deviceId: this.device.deviceId,
44
38
  serviceId: this.scpair.service.uuid,
45
39
  characteristicId: this.scpair.read.uuid,
@@ -56,7 +50,7 @@ class TaroBleConnectedDevice {
56
50
  reject(`the connect device not support read operation: service id: [${this.scpair.service.uuid}]`);
57
51
  return;
58
52
  }
59
- taro_1.default.readBLECharacteristicValue({
53
+ Taro.readBLECharacteristicValue({
60
54
  deviceId: this.device.deviceId,
61
55
  serviceId: this.scpair.service.uuid,
62
56
  characteristicId: this.scpair.read.uuid,
@@ -85,7 +79,7 @@ class TaroBleConnectedDevice {
85
79
  disconnect() {
86
80
  return __awaiter(this, void 0, void 0, function* () {
87
81
  return new Promise((resolve, reject) => {
88
- taro_1.default.closeBLEConnection({
82
+ Taro.closeBLEConnection({
89
83
  deviceId: this.device.deviceId,
90
84
  success: () => {
91
85
  this.device = null;
@@ -102,8 +96,8 @@ class TaroBleConnectedDevice {
102
96
  return this.scpair.read != null;
103
97
  }
104
98
  read(options) {
105
- var _a;
106
99
  return __awaiter(this, void 0, void 0, function* () {
100
+ var _a;
107
101
  if (this.dataOfRead.length > 0) {
108
102
  this.dataOfRead.splice(0, this.dataOfRead.length);
109
103
  }
@@ -116,7 +110,7 @@ class TaroBleConnectedDevice {
116
110
  return new Uint8Array([]);
117
111
  }
118
112
  if (this.dataOfRead.length == 0) {
119
- yield await_timeout_1.default.set(100);
113
+ yield Timeout.set(100);
120
114
  continue;
121
115
  }
122
116
  const data = this.dataOfRead.pop();
@@ -128,7 +122,7 @@ class TaroBleConnectedDevice {
128
122
  write(data) {
129
123
  return __awaiter(this, void 0, void 0, function* () {
130
124
  return new Promise((resolve, reject) => {
131
- taro_1.default.writeBLECharacteristicValue({
125
+ Taro.writeBLECharacteristicValue({
132
126
  deviceId: this.device.deviceId,
133
127
  serviceId: this.scpair.service.uuid,
134
128
  characteristicId: this.scpair.write.uuid,
@@ -151,4 +145,3 @@ class TaroBleConnectedDevice {
151
145
  this.dataOfRead.splice(0, this.dataOfRead.length);
152
146
  }
153
147
  }
154
- exports.TaroBleConnectedDevice = TaroBleConnectedDevice;
package/build/index.js CHANGED
@@ -1,18 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./connected"), exports);
18
- __exportStar(require("./provider"), exports);
1
+ export * from './connected';
2
+ export * from './provider';
package/build/provider.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,17 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.TaroBleBluetooth = void 0;
16
- const device_bluetooth_traits_1 = require("@psdk/device-bluetooth-traits");
17
- const frame_father_1 = require("@psdk/frame-father");
18
- const await_timeout_1 = __importDefault(require("await-timeout"));
19
- const connected_1 = require("./connected");
20
- const taro_1 = __importDefault(require("@tarojs/taro"));
21
- class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
10
+ import { Jluetooth, JluetoothDevice, TBluetoothHelpers, } from "@psdk/device-bluetooth-traits";
11
+ import { ConnectionState } from "@psdk/frame-father";
12
+ import Timeout from 'await-timeout';
13
+ import { TaroBleConnectedDevice } from "./connected";
14
+ import Taro from "@tarojs/taro";
15
+ export class TaroBleBluetooth extends Jluetooth {
22
16
  constructor(options) {
23
17
  super();
24
18
  this.options = options;
@@ -27,12 +21,12 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
27
21
  isConnected() {
28
22
  if (!this.connectedDevice)
29
23
  return false;
30
- return this.connectedDevice.connectionState() === frame_father_1.ConnectionState.CONNECTED;
24
+ return this.connectedDevice.connectionState() === ConnectionState.CONNECTED;
31
25
  }
32
26
  bluetoothAdapterState() {
33
27
  return __awaiter(this, void 0, void 0, function* () {
34
28
  return new Promise((resolve, reject) => {
35
- taro_1.default.getBluetoothAdapterState({
29
+ Taro.getBluetoothAdapterState({
36
30
  success: (r) => resolve(r),
37
31
  // @ts-ignore
38
32
  fail: (e) => reject(e)
@@ -41,8 +35,8 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
41
35
  });
42
36
  }
43
37
  connect(device, options) {
44
- var _a;
45
38
  return __awaiter(this, void 0, void 0, function* () {
39
+ var _a;
46
40
  if (this.isConnected()) {
47
41
  if (!((_a = options === null || options === void 0 ? void 0 : options.autoSwitchDevice) !== null && _a !== void 0 ? _a : false)) {
48
42
  return this.connectedDevice;
@@ -51,7 +45,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
51
45
  }
52
46
  const origin = device.origin;
53
47
  yield this.createBLEConnection({ deviceId: origin.deviceId, timeout: options === null || options === void 0 ? void 0 : options.timeout, });
54
- yield await_timeout_1.default.set(500);
48
+ yield Timeout.set(500);
55
49
  const services = yield this.getBLEDeviceServices({ deviceId: origin.deviceId });
56
50
  const scpair = yield this.findSCPair({
57
51
  deviceId: origin.deviceId,
@@ -60,7 +54,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
60
54
  if (!scpair) {
61
55
  return Promise.reject(`Can not get write characteristic by device: ${device.name}`);
62
56
  }
63
- this.connectedDevice = new connected_1.TaroBleConnectedDevice({
57
+ this.connectedDevice = new TaroBleConnectedDevice({
64
58
  device: origin,
65
59
  scpair,
66
60
  });
@@ -75,18 +69,18 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
75
69
  return __awaiter(this, void 0, void 0, function* () {
76
70
  yield this.requestLocation();
77
71
  yield this.closeBluetoothAdapter();
78
- yield await_timeout_1.default.set(300);
72
+ yield Timeout.set(300);
79
73
  yield this.openBluetoothAdapter();
80
74
  const state = yield this.bluetoothAdapterState();
81
75
  if (!state.available) {
82
- yield await_timeout_1.default.set(500);
76
+ yield Timeout.set(500);
83
77
  }
84
78
  if (state.discovering) {
85
79
  yield this.stopDiscovery();
86
- yield await_timeout_1.default.set(500);
80
+ yield Timeout.set(500);
87
81
  }
88
82
  return new Promise((resolve, reject) => {
89
- taro_1.default.startBluetoothDevicesDiscovery({
83
+ Taro.startBluetoothDevicesDiscovery({
90
84
  // services: this.allowServices,
91
85
  allowDuplicatesKey: false,
92
86
  interval: 0,
@@ -101,7 +95,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
101
95
  stopDiscovery() {
102
96
  return __awaiter(this, void 0, void 0, function* () {
103
97
  return new Promise((resolve, reject) => {
104
- taro_1.default.stopBluetoothDevicesDiscovery({
98
+ Taro.stopBluetoothDevicesDiscovery({
105
99
  success: (result) => resolve(result),
106
100
  // @ts-ignore
107
101
  fail: (e) => reject(e),
@@ -113,7 +107,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
113
107
  openBluetoothAdapter() {
114
108
  return __awaiter(this, void 0, void 0, function* () {
115
109
  return new Promise((resolve, reject) => {
116
- taro_1.default.openBluetoothAdapter({
110
+ Taro.openBluetoothAdapter({
117
111
  success: (ret) => {
118
112
  if (ret.errMsg && ret.errMsg.indexOf('ok') == -1) {
119
113
  reject(ret);
@@ -130,7 +124,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
130
124
  closeBluetoothAdapter() {
131
125
  return __awaiter(this, void 0, void 0, function* () {
132
126
  return new Promise((resolve, reject) => {
133
- taro_1.default.closeBluetoothAdapter({
127
+ Taro.closeBluetoothAdapter({
134
128
  success: (ret) => {
135
129
  if (ret.errMsg && ret.errMsg.indexOf('ok') == -1) {
136
130
  reject(ret);
@@ -145,7 +139,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
145
139
  });
146
140
  }
147
141
  onBluetoothDeviceFound() {
148
- taro_1.default.onBluetoothDeviceFound((result) => __awaiter(this, void 0, void 0, function* () {
142
+ Taro.onBluetoothDeviceFound((result) => __awaiter(this, void 0, void 0, function* () {
149
143
  const foundDevices = result.devices;
150
144
  if (!foundDevices.length) {
151
145
  return;
@@ -158,7 +152,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
158
152
  return true;
159
153
  return (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.allowNoName) !== null && _b !== void 0 ? _b : true;
160
154
  })
161
- .map(item => new device_bluetooth_traits_1.JluetoothDevice({
155
+ .map(item => new JluetoothDevice({
162
156
  origin: item,
163
157
  name: item.name || item.localName,
164
158
  deviceId: item.deviceId,
@@ -174,7 +168,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
174
168
  createBLEConnection(options) {
175
169
  return __awaiter(this, void 0, void 0, function* () {
176
170
  return new Promise((resolve, reject) => {
177
- taro_1.default.createBLEConnection({
171
+ Taro.createBLEConnection({
178
172
  deviceId: options.deviceId,
179
173
  timeout: options.timeout,
180
174
  success: () => resolve(),
@@ -187,7 +181,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
187
181
  getBLEDeviceServices(options) {
188
182
  return __awaiter(this, void 0, void 0, function* () {
189
183
  return new Promise((resolve, reject) => {
190
- taro_1.default.getBLEDeviceServices({
184
+ Taro.getBLEDeviceServices({
191
185
  deviceId: options.deviceId,
192
186
  success: (result) => {
193
187
  if (result.errMsg.indexOf('ok') == -1) {
@@ -205,7 +199,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
205
199
  getBLEDeviceCharacteristics(options) {
206
200
  return __awaiter(this, void 0, void 0, function* () {
207
201
  return new Promise((resolve, reject) => {
208
- taro_1.default.getBLEDeviceCharacteristics({
202
+ Taro.getBLEDeviceCharacteristics({
209
203
  deviceId: options.deviceId,
210
204
  serviceId: options.serviceId,
211
205
  success: (result) => {
@@ -230,7 +224,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
230
224
  // // @ts-ignore
231
225
  // fail: (e) => reject(e),
232
226
  // });
233
- taro_1.default.getLocation({
227
+ Taro.getLocation({
234
228
  success: () => resolve(),
235
229
  // @ts-ignore
236
230
  fail: (e) => reject(e),
@@ -239,8 +233,8 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
239
233
  });
240
234
  }
241
235
  findSCPair(options) {
242
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
243
236
  return __awaiter(this, void 0, void 0, function* () {
237
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
244
238
  // fill data
245
239
  const _characteristicsMap = new Map();
246
240
  for (const service of options.services) {
@@ -253,7 +247,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
253
247
  // use special first
254
248
  if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowedWriteCharacteristic) && ((_b = this.options) === null || _b === void 0 ? void 0 : _b.allowedReadCharacteristic)) {
255
249
  for (const service of options.services) {
256
- if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_c = this.options) === null || _c === void 0 ? void 0 : _c.allowServices)) {
250
+ if (!TBluetoothHelpers.isAllowServices(service.uuid, (_c = this.options) === null || _c === void 0 ? void 0 : _c.allowServices)) {
257
251
  continue;
258
252
  }
259
253
  const characteristics = _characteristicsMap.get(service.uuid);
@@ -280,7 +274,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
280
274
  }
281
275
  // choose best characteristic
282
276
  for (const service of options.services) {
283
- if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_f = this.options) === null || _f === void 0 ? void 0 : _f.allowServices)) {
277
+ if (!TBluetoothHelpers.isAllowServices(service.uuid, (_f = this.options) === null || _f === void 0 ? void 0 : _f.allowServices)) {
284
278
  continue;
285
279
  }
286
280
  const characteristics = _characteristicsMap.get(service.uuid);
@@ -302,7 +296,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
302
296
  if ((_h = (_g = this.options) === null || _g === void 0 ? void 0 : _g.allowDetectDifferentCharacteristic) !== null && _h !== void 0 ? _h : true) {
303
297
  // choose different characteristic with write and read properties
304
298
  for (const service of options.services) {
305
- if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_j = this.options) === null || _j === void 0 ? void 0 : _j.allowServices)) {
299
+ if (!TBluetoothHelpers.isAllowServices(service.uuid, (_j = this.options) === null || _j === void 0 ? void 0 : _j.allowServices)) {
306
300
  continue;
307
301
  }
308
302
  const characteristics = _characteristicsMap.get(service.uuid);
@@ -327,7 +321,7 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
327
321
  else {
328
322
  // only write
329
323
  for (const service of options.services) {
330
- if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_k = this.options) === null || _k === void 0 ? void 0 : _k.allowServices)) {
324
+ if (!TBluetoothHelpers.isAllowServices(service.uuid, (_k = this.options) === null || _k === void 0 ? void 0 : _k.allowServices)) {
331
325
  continue;
332
326
  }
333
327
  const characteristics = _characteristicsMap.get(service.uuid);
@@ -347,4 +341,3 @@ class TaroBleBluetooth extends device_bluetooth_traits_1.Jluetooth {
347
341
  });
348
342
  }
349
343
  }
350
- exports.TaroBleBluetooth = TaroBleBluetooth;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@psdk/device-ble-taro",
3
- "version": "0.2.65",
3
+ "version": "0.3.0",
4
4
  "description": "psdk",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "package": "tsc && ncc build --source-map build/index.js -m -C -o dist && npx webpack",
9
+ "package": "tsc && ncc build --source-map build/index.js -m -C -o dist",
10
10
  "test": "jest",
11
11
  "docs": "npx typedoc --out dist/docs index.ts"
12
12
  },
@@ -15,44 +15,25 @@
15
15
  },
16
16
  "author": "",
17
17
  "devDependencies": {
18
- "@babel/plugin-proposal-class-properties": "^7.17.12",
19
- "@babel/plugin-proposal-decorators": "^7.17.12",
20
- "@babel/plugin-proposal-export-namespace-from": "^7.17.12",
21
- "@babel/plugin-proposal-function-sent": "^7.17.12",
22
- "@babel/plugin-proposal-numeric-separator": "^7.16.7",
23
- "@babel/plugin-proposal-object-rest-spread": "^7.18.0",
24
- "@babel/plugin-proposal-throw-expressions": "^7.16.7",
25
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
26
- "@babel/plugin-syntax-import-meta": "^7.10.4",
27
- "@babel/plugin-transform-modules-commonjs": "^7.18.0",
28
- "@babel/plugin-transform-object-assign": "^7.16.7",
29
- "@babel/plugin-transform-runtime": "^7.18.0",
30
- "@babel/preset-env": "^7.18.0",
31
- "@babel/preset-typescript": "^7.17.12",
32
- "@babel/register": "^7.17.7",
33
- "@babel/runtime-corejs3": "^7.18.0",
34
- "@tarojs/taro": "^3.5.1",
35
- "@types/jest": "^27.5.1",
36
- "@types/node": "^17.0.35",
37
- "@vercel/ncc": "^0.33.4",
38
- "babel-loader": "^8.2.5",
39
- "buffer": "^6.0.3",
40
- "jest": "^28.1.0",
41
- "string_decoder": "^1.3.0",
42
- "ts-jest": "^28.0.2",
43
- "typedoc": "^0.22.15",
44
- "typescript": "^4.6.4",
45
- "webpack": "^5.72.1",
46
- "webpack-cli": "^4.9.2"
18
+ "@babel/core": "^7.24.5",
19
+ "@babel/preset-env": "^7.24.5",
20
+ "@babel/preset-typescript": "^7.24.1",
21
+ "@tarojs/taro": "^3.6.29",
22
+ "@types/jest": "^29.5.12",
23
+ "@vercel/ncc": "^0.38.1",
24
+ "babel-jest": "^29.7.0",
25
+ "jest": "^29.7.0",
26
+ "typedoc": "^0.25.13",
27
+ "typescript": "^5.4.5"
47
28
  },
48
29
  "dependencies": {
49
- "@psdk/device-bluetooth-traits": "0.2.65",
50
- "@psdk/frame-father": "0.2.65",
30
+ "@psdk/device-bluetooth-traits": "0.3.0",
31
+ "@psdk/frame-father": "0.3.0",
51
32
  "await-timeout": "^1.1.1"
52
33
  },
53
34
  "files": [
54
35
  "build",
55
36
  "!build/browser/psdk*"
56
37
  ],
57
- "gitHead": "21ed60439fa22935194c0baede0fb849b0be5da6"
38
+ "gitHead": "9796259a6a24ae7e334340f6c28d5ae9b3e45401"
58
39
  }