@psdk/device-ble-taro 0.2.3 → 0.2.5

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/index.d.ts CHANGED
@@ -1,21 +1,22 @@
1
- import { ConnectedDevice, ConnectionState, ReadOptions } from "@psdk/frame";
2
- import Taro from "@tarojs/taro";
3
- export declare class TaroBleConnectedDevice implements ConnectedDevice {
4
- private readonly device;
5
- private readonly service;
6
- private readonly characteristic;
7
- private _connectionState;
8
- private dataOfRead;
9
- constructor(options: {
10
- device: Taro.getBluetoothDevices.SuccessCallbackResultBlueToothDevice;
11
- service: Taro.getBLEDeviceServices.BLEService;
12
- characteristic: Taro.getBLEDeviceCharacteristics.BLECharacteristic;
13
- });
14
- private doListen;
15
- private realRead;
16
- connectionState(): ConnectionState;
17
- deviceName(): string;
18
- read(options?: ReadOptions): Promise<Uint8Array>;
19
- write(data: Uint8Array): Promise<void>;
20
- }
1
+ import { ConnectedDevice, ConnectionState, ReadOptions } from "@psdk/frame";
2
+ import Taro from "@tarojs/taro";
3
+ export declare class TaroBleConnectedDevice implements ConnectedDevice {
4
+ private readonly device;
5
+ private readonly service;
6
+ private readonly characteristic;
7
+ private _connectionState;
8
+ private dataOfRead;
9
+ constructor(options: {
10
+ device: Taro.getBluetoothDevices.SuccessCallbackResultBlueToothDevice;
11
+ service: Taro.getBLEDeviceServices.BLEService;
12
+ characteristic: Taro.getBLEDeviceCharacteristics.BLECharacteristic;
13
+ });
14
+ private doListen;
15
+ private realRead;
16
+ connectionState(): ConnectionState;
17
+ deviceName(): string;
18
+ disconnect(): Promise<void>;
19
+ read(options?: ReadOptions): Promise<Uint8Array>;
20
+ write(data: Uint8Array): Promise<void>;
21
+ }
21
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,eAAe,EAAE,WAA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AAC;QACtE,OAAO,EAAE,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC;QAC9C,cAAc,EAAE,IAAI,CAAC,2BAA2B,CAAC,iBAAiB,CAAC;KACpE;IAQD,OAAO,CAAC,QAAQ;YASF,QAAQ;IAYtB,eAAe,IAAI,eAAe;IAIlC,UAAU,IAAI,MAAM;IAId,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAG3B,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAsBhD,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAiB7C"}
package/build/index.js CHANGED
@@ -1,96 +1,100 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
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_1 = require("@psdk/frame");
17
- const taro_1 = __importDefault(require("@tarojs/taro"));
18
- const await_timeout_1 = __importDefault(require("await-timeout"));
19
- class TaroBleConnectedDevice {
20
- constructor(options) {
21
- this.device = options.device;
22
- this.service = options.service;
23
- this.characteristic = options.characteristic;
24
- this._connectionState = frame_1.ConnectionState.CONNECTED;
25
- this.doListen();
26
- }
27
- doListen() {
28
- taro_1.default.onBLECharacteristicValueChange(value => {
29
- this.dataOfRead.push(value);
30
- });
31
- taro_1.default.onBLEConnectionStateChange(value => {
32
- this._connectionState = value.connected ? frame_1.ConnectionState.CONNECTED : frame_1.ConnectionState.DISCONNECTED;
33
- });
34
- }
35
- realRead() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- return new Promise((resolve, reject) => {
38
- taro_1.default.readBLECharacteristicValue({
39
- deviceId: this.device.deviceId,
40
- serviceId: this.service.uuid,
41
- characteristicId: this.characteristic.uuid,
42
- success: res => resolve(),
43
- fail: res => reject(),
44
- });
45
- });
46
- });
47
- }
48
- connectionState() {
49
- return this._connectionState;
50
- }
51
- deviceName() {
52
- return this.device.localName || this.device.name || 'NONE';
53
- }
54
- read(options) {
55
- var _a;
56
- return __awaiter(this, void 0, void 0, function* () {
57
- if (this.dataOfRead.length > 0) {
58
- this.dataOfRead.splice(0, this.dataOfRead.length);
59
- }
60
- yield this.realRead();
61
- const timeout = ((_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 3) * 1000;
62
- const startTime = +new Date();
63
- while (true) {
64
- const now = +new Date();
65
- if (now - startTime > timeout) {
66
- return new Uint8Array([]);
67
- }
68
- if (this.dataOfRead.length == 0) {
69
- yield await_timeout_1.default.set(50);
70
- continue;
71
- }
72
- const data = this.dataOfRead.pop();
73
- const value = data.value;
74
- return new Uint8Array(value);
75
- }
76
- });
77
- }
78
- write(data) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- return new Promise((resolve, reject) => {
81
- taro_1.default.writeBLECharacteristicValue({
82
- deviceId: this.device.deviceId,
83
- serviceId: this.service.uuid,
84
- characteristicId: this.characteristic.uuid,
85
- value: data.buffer,
86
- success: res => resolve(),
87
- fail: res => {
88
- console.error('Failed to write data:', res.errMsg);
89
- reject(res.errMsg);
90
- }
91
- });
92
- });
93
- });
94
- }
95
- }
96
- exports.TaroBleConnectedDevice = TaroBleConnectedDevice;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
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_1 = require("@psdk/frame");
17
+ const taro_1 = __importDefault(require("@tarojs/taro"));
18
+ const await_timeout_1 = __importDefault(require("await-timeout"));
19
+ class TaroBleConnectedDevice {
20
+ constructor(options) {
21
+ this.device = options.device;
22
+ this.service = options.service;
23
+ this.characteristic = options.characteristic;
24
+ this._connectionState = frame_1.ConnectionState.CONNECTED;
25
+ this.doListen();
26
+ }
27
+ doListen() {
28
+ taro_1.default.onBLECharacteristicValueChange(value => {
29
+ this.dataOfRead.push(value);
30
+ });
31
+ taro_1.default.onBLEConnectionStateChange(value => {
32
+ this._connectionState = value.connected ? frame_1.ConnectionState.CONNECTED : frame_1.ConnectionState.DISCONNECTED;
33
+ });
34
+ }
35
+ realRead() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ return new Promise((resolve, reject) => {
38
+ taro_1.default.readBLECharacteristicValue({
39
+ deviceId: this.device.deviceId,
40
+ serviceId: this.service.uuid,
41
+ characteristicId: this.characteristic.uuid,
42
+ success: res => resolve(),
43
+ fail: res => reject(),
44
+ });
45
+ });
46
+ });
47
+ }
48
+ connectionState() {
49
+ return this._connectionState;
50
+ }
51
+ deviceName() {
52
+ return this.device.localName || this.device.name || 'NONE';
53
+ }
54
+ disconnect() {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ });
57
+ }
58
+ read(options) {
59
+ var _a;
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ if (this.dataOfRead.length > 0) {
62
+ this.dataOfRead.splice(0, this.dataOfRead.length);
63
+ }
64
+ yield this.realRead();
65
+ const timeout = ((_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 3) * 1000;
66
+ const startTime = +new Date();
67
+ while (true) {
68
+ const now = +new Date();
69
+ if (now - startTime > timeout) {
70
+ return new Uint8Array([]);
71
+ }
72
+ if (this.dataOfRead.length == 0) {
73
+ yield await_timeout_1.default.set(50);
74
+ continue;
75
+ }
76
+ const data = this.dataOfRead.pop();
77
+ const value = data.value;
78
+ return new Uint8Array(value);
79
+ }
80
+ });
81
+ }
82
+ write(data) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ return new Promise((resolve, reject) => {
85
+ taro_1.default.writeBLECharacteristicValue({
86
+ deviceId: this.device.deviceId,
87
+ serviceId: this.service.uuid,
88
+ characteristicId: this.characteristic.uuid,
89
+ value: data.buffer,
90
+ success: res => resolve(),
91
+ fail: res => {
92
+ console.error('Failed to write data:', res.errMsg);
93
+ reject(res.errMsg);
94
+ }
95
+ });
96
+ });
97
+ });
98
+ }
99
+ }
100
+ exports.TaroBleConnectedDevice = TaroBleConnectedDevice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psdk/device-ble-taro",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "psdk",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -43,12 +43,12 @@
43
43
  "webpack-cli": "^4.9.2"
44
44
  },
45
45
  "dependencies": {
46
- "@psdk/frame": "latest",
46
+ "@psdk/frame": "*",
47
47
  "await-timeout": "^1.1.1"
48
48
  },
49
49
  "files": [
50
50
  "build",
51
51
  "!build/browser/psdk*"
52
52
  ],
53
- "gitHead": "dbaeb4780df34ddb6347d9437773ed215d383fd7"
53
+ "gitHead": "b30312bea1f3aa4c74b2582cfe3ac484f504aa29"
54
54
  }