@psdk/device-ble-wechat
Advanced tools
Comparing version 0.2.67 to 0.3.0
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -11,14 +10,9 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WechatBleConnectedDevice = void 0; | ||
const frame_father_1 = require("@psdk/frame-father"); | ||
const await_timeout_1 = __importDefault(require("await-timeout")); | ||
class WechatBleConnectedDevice { | ||
import { ConnectionState } from "@psdk/frame-father"; | ||
import Timeout from 'await-timeout'; | ||
export class WechatBleConnectedDevice { | ||
constructor(options) { | ||
this.device = options.device; | ||
this.scpair = options.scpair; | ||
this._connectionState = frame_father_1.ConnectionState.CONNECTED; | ||
this._connectionState = ConnectionState.CONNECTED; | ||
this.dataOfRead = []; | ||
@@ -40,3 +34,3 @@ this.doListen(); | ||
wx.onBLEConnectionStateChange(value => { | ||
this._connectionState = value.connected ? frame_father_1.ConnectionState.CONNECTED : frame_father_1.ConnectionState.DISCONNECTED; | ||
this._connectionState = value.connected ? ConnectionState.CONNECTED : ConnectionState.DISCONNECTED; | ||
}); | ||
@@ -106,4 +100,4 @@ wx.notifyBLECharacteristicValueChange({ | ||
read(options) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
if (this.dataOfRead.length > 0) { | ||
@@ -121,3 +115,3 @@ this.dataOfRead.splice(0, this.dataOfRead.length); | ||
if (this.dataOfRead.length == 0) { | ||
yield await_timeout_1.default.set(100); | ||
yield Timeout.set(100); | ||
continue; | ||
@@ -157,2 +151,1 @@ } | ||
} | ||
exports.WechatBleConnectedDevice = WechatBleConnectedDevice; |
@@ -1,18 +0,2 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./connected"), exports); | ||
__exportStar(require("./provider"), exports); | ||
export * from './connected'; | ||
export * from './provider'; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -11,12 +10,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WechatBleBluetooth = void 0; | ||
const device_bluetooth_traits_1 = require("@psdk/device-bluetooth-traits"); | ||
const frame_father_1 = require("@psdk/frame-father"); | ||
const await_timeout_1 = __importDefault(require("await-timeout")); | ||
const connected_1 = require("./connected"); | ||
class WechatBleBluetooth extends device_bluetooth_traits_1.Jluetooth { | ||
import { Jluetooth, JluetoothDevice, TBluetoothHelpers, } from "@psdk/device-bluetooth-traits"; | ||
import { ConnectionState } from "@psdk/frame-father"; | ||
import Timeout from 'await-timeout'; | ||
import { WechatBleConnectedDevice } from "./connected"; | ||
export class WechatBleBluetooth extends Jluetooth { | ||
constructor(options) { | ||
@@ -30,3 +24,3 @@ super(); | ||
return false; | ||
return this.connectedDevice.connectionState() === frame_father_1.ConnectionState.CONNECTED; | ||
return this.connectedDevice.connectionState() === ConnectionState.CONNECTED; | ||
} | ||
@@ -43,4 +37,4 @@ bluetoothAdapterState() { | ||
connect(device, options) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
if (this.isConnected()) { | ||
@@ -54,3 +48,3 @@ if (!((_a = options === null || options === void 0 ? void 0 : options.autoSwitchDevice) !== null && _a !== void 0 ? _a : false)) { | ||
yield this.createBLEConnection({ deviceId: origin.deviceId, timeout: options === null || options === void 0 ? void 0 : options.timeout, }); | ||
yield await_timeout_1.default.set(500); | ||
yield Timeout.set(500); | ||
const services = yield this.getBLEDeviceServices({ deviceId: origin.deviceId }); | ||
@@ -64,3 +58,3 @@ const scpair = yield this.findSCPair({ | ||
} | ||
this.connectedDevice = new connected_1.WechatBleConnectedDevice({ | ||
this.connectedDevice = new WechatBleConnectedDevice({ | ||
device: origin, | ||
@@ -80,11 +74,11 @@ scpair, | ||
yield this.closeBluetoothAdapter(); | ||
yield await_timeout_1.default.set(300); | ||
yield Timeout.set(300); | ||
yield this.openBluetoothAdapter(); | ||
const state = yield this.bluetoothAdapterState(); | ||
if (!state.available) { | ||
yield await_timeout_1.default.set(500); | ||
yield Timeout.set(500); | ||
} | ||
if (state.discovering) { | ||
yield this.stopDiscovery(); | ||
yield await_timeout_1.default.set(500); | ||
yield Timeout.set(500); | ||
} | ||
@@ -164,3 +158,3 @@ return new Promise((resolve, reject) => { | ||
}) | ||
.map(item => new device_bluetooth_traits_1.JluetoothDevice({ | ||
.map(item => new JluetoothDevice({ | ||
origin: item, | ||
@@ -246,4 +240,4 @@ name: item.name || item.localName, | ||
findSCPair(options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
// fill data | ||
@@ -261,3 +255,3 @@ const _characteristicsMap = new Map(); | ||
for (const service of options.services) { | ||
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_c = this.options) === null || _c === void 0 ? void 0 : _c.allowServices)) { | ||
if (!TBluetoothHelpers.isAllowServices(service.uuid, (_c = this.options) === null || _c === void 0 ? void 0 : _c.allowServices)) { | ||
continue; | ||
@@ -289,3 +283,3 @@ } | ||
for (const service of options.services) { | ||
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_f = this.options) === null || _f === void 0 ? void 0 : _f.allowServices)) { | ||
if (!TBluetoothHelpers.isAllowServices(service.uuid, (_f = this.options) === null || _f === void 0 ? void 0 : _f.allowServices)) { | ||
continue; | ||
@@ -312,3 +306,3 @@ } | ||
for (const service of options.services) { | ||
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_j = this.options) === null || _j === void 0 ? void 0 : _j.allowServices)) { | ||
if (!TBluetoothHelpers.isAllowServices(service.uuid, (_j = this.options) === null || _j === void 0 ? void 0 : _j.allowServices)) { | ||
continue; | ||
@@ -338,3 +332,3 @@ } | ||
for (const service of options.services) { | ||
if (!device_bluetooth_traits_1.TBluetoothHelpers.isAllowServices(service.uuid, (_k = this.options) === null || _k === void 0 ? void 0 : _k.allowServices)) { | ||
if (!TBluetoothHelpers.isAllowServices(service.uuid, (_k = this.options) === null || _k === void 0 ? void 0 : _k.allowServices)) { | ||
continue; | ||
@@ -359,2 +353,1 @@ } | ||
} | ||
exports.WechatBleBluetooth = WechatBleBluetooth; |
{ | ||
"name": "@psdk/device-ble-wechat", | ||
"version": "0.2.67", | ||
"version": "0.3.0", | ||
"description": "psdk", | ||
@@ -9,3 +9,3 @@ "main": "build/index.js", | ||
"build": "tsc", | ||
"package": "tsc && ncc build --source-map build/index.js -m -C -o dist && npx webpack", | ||
"package": "tsc && ncc build --source-map build/index.js -m -C -o dist", | ||
"test": "jest", | ||
@@ -19,35 +19,16 @@ "docs": "npx typedoc --out dist/docs index.ts" | ||
"devDependencies": { | ||
"@babel/plugin-proposal-class-properties": "^7.17.12", | ||
"@babel/plugin-proposal-decorators": "^7.17.12", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.17.12", | ||
"@babel/plugin-proposal-function-sent": "^7.17.12", | ||
"@babel/plugin-proposal-numeric-separator": "^7.16.7", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.18.0", | ||
"@babel/plugin-proposal-throw-expressions": "^7.16.7", | ||
"@babel/plugin-syntax-dynamic-import": "^7.8.3", | ||
"@babel/plugin-syntax-import-meta": "^7.10.4", | ||
"@babel/plugin-transform-modules-commonjs": "^7.18.0", | ||
"@babel/plugin-transform-object-assign": "^7.16.7", | ||
"@babel/plugin-transform-runtime": "^7.18.0", | ||
"@babel/preset-env": "^7.18.0", | ||
"@babel/preset-typescript": "^7.17.12", | ||
"@babel/register": "^7.17.7", | ||
"@babel/runtime-corejs3": "^7.18.0", | ||
"@types/jest": "^27.5.1", | ||
"@types/node": "^17.0.35", | ||
"@types/wechat-miniprogram": "^3.4.1", | ||
"@vercel/ncc": "^0.33.4", | ||
"babel-loader": "^8.2.5", | ||
"buffer": "^6.0.3", | ||
"jest": "^28.1.0", | ||
"string_decoder": "^1.3.0", | ||
"ts-jest": "^28.0.2", | ||
"typedoc": "^0.22.15", | ||
"typescript": "^4.6.4", | ||
"webpack": "^5.72.1", | ||
"webpack-cli": "^4.9.2" | ||
"@babel/core": "^7.24.5", | ||
"@babel/preset-env": "^7.24.5", | ||
"@babel/preset-typescript": "^7.24.1", | ||
"@types/jest": "^29.5.12", | ||
"@types/wechat-miniprogram": "^3.4.7", | ||
"@vercel/ncc": "^0.38.1", | ||
"babel-jest": "^29.7.0", | ||
"jest": "^29.7.0", | ||
"typedoc": "^0.25.13", | ||
"typescript": "^5.4.5" | ||
}, | ||
"dependencies": { | ||
"@psdk/device-bluetooth-traits": "0.2.67", | ||
"@psdk/frame-father": "0.2.67", | ||
"@psdk/device-bluetooth-traits": "0.3.0", | ||
"@psdk/frame-father": "0.3.0", | ||
"await-timeout": "^1.1.1" | ||
@@ -59,3 +40,3 @@ }, | ||
], | ||
"gitHead": "1b469612990a3efbf1a3fe4296ed13e8c8865988" | ||
"gitHead": "9796259a6a24ae7e334340f6c28d5ae9b3e45401" | ||
} |
10
25846
542
+ Added@psdk/device-bluetooth-traits@0.3.0(transitive)
+ Added@psdk/frame-father@0.3.0(transitive)
- Removed@psdk/device-bluetooth-traits@0.2.67(transitive)
- Removed@psdk/frame-father@0.2.67(transitive)
- Removedis_js@0.9.0(transitive)
Updated@psdk/frame-father@0.3.0