@psdk/device-webusb
Advanced tools
Comparing version 0.3.4 to 0.4.0
@@ -1,5 +0,16 @@ | ||
import { ConnectionState, ReadOptions } from "@psdk/frame-father"; | ||
export class Webusb { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DeviceFilter = exports.WebusbReadOptions = exports.Webusb = void 0; | ||
const frame_father_1 = require("@psdk/frame-father"); | ||
class Webusb { | ||
filters; | ||
configuration; | ||
interface; | ||
readEndpoint; | ||
writeEndpoint; | ||
inputReadEndpoint; | ||
inputWriteEndpoint; | ||
state; | ||
device; | ||
constructor(options) { | ||
var _a, _b, _c, _d; | ||
if (options.filters.length == 0) { | ||
@@ -9,7 +20,7 @@ throw new Error('Missing filters'); | ||
this.filters = options.filters; | ||
this.configuration = (_a = options.configuration) !== null && _a !== void 0 ? _a : 1; | ||
this.interface = (_b = options.interface) !== null && _b !== void 0 ? _b : 0; | ||
this.state = ConnectionState.DISCONNECTED; | ||
this.inputReadEndpoint = (_c = options.readEndpoint) !== null && _c !== void 0 ? _c : 2; | ||
this.inputWriteEndpoint = (_d = options.writeEndpoint) !== null && _d !== void 0 ? _d : 2; | ||
this.configuration = options.configuration ?? 1; | ||
this.interface = options.interface ?? 0; | ||
this.state = frame_father_1.ConnectionState.DISCONNECTED; | ||
this.inputReadEndpoint = options.readEndpoint ?? 2; | ||
this.inputWriteEndpoint = options.writeEndpoint ?? 2; | ||
} | ||
@@ -41,10 +52,10 @@ static withFilter(filter) { | ||
this.writeEndpoint = outEndpoints && outEndpoints.length ? outEndpoints[0].endpointNumber : this.inputWriteEndpoint; | ||
this.state = ConnectionState.CONNECTED; | ||
this.state = frame_father_1.ConnectionState.CONNECTED; | ||
// @ts-ignore | ||
navigator.usb.addEventListener('connect', e => { | ||
this.state = ConnectionState.CONNECTED; | ||
this.state = frame_father_1.ConnectionState.CONNECTED; | ||
}); | ||
// @ts-ignore | ||
navigator.usb.addEventListener('disconnect', e => { | ||
this.state = ConnectionState.DISCONNECTED; | ||
this.state = frame_father_1.ConnectionState.DISCONNECTED; | ||
}); | ||
@@ -66,3 +77,3 @@ this.device = device; | ||
if (!device.opened) { | ||
return ConnectionState.DISCONNECTED; | ||
return frame_father_1.ConnectionState.DISCONNECTED; | ||
} | ||
@@ -83,3 +94,3 @@ return _connectionState(); | ||
const device = _device(); | ||
const _options = options !== null && options !== void 0 ? options : WebusbReadOptions.def(); | ||
const _options = options ?? WebusbReadOptions.def(); | ||
const result = await device.transferIn(_readEndpoint(), _options.readLength); | ||
@@ -106,7 +117,8 @@ const { status, data } = result; | ||
} | ||
export class WebusbReadOptions extends ReadOptions { | ||
exports.Webusb = Webusb; | ||
class WebusbReadOptions extends frame_father_1.ReadOptions { | ||
_length; | ||
constructor(options) { | ||
var _a; | ||
super(options); | ||
this._length = (_a = options === null || options === void 0 ? void 0 : options.length) !== null && _a !== void 0 ? _a : 1024; | ||
this._length = options?.length ?? 1024; | ||
} | ||
@@ -120,3 +132,6 @@ static def() { | ||
} | ||
export class DeviceFilter { | ||
exports.WebusbReadOptions = WebusbReadOptions; | ||
class DeviceFilter { | ||
vendorId; | ||
productId; | ||
constructor(options) { | ||
@@ -127,1 +142,2 @@ this.vendorId = options.vendorId; | ||
} | ||
exports.DeviceFilter = DeviceFilter; |
{ | ||
"name": "@psdk/device-webusb", | ||
"version": "0.3.4", | ||
"version": "0.4.0", | ||
"description": "psdk", | ||
@@ -15,14 +15,12 @@ "main": "build/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.24.5", | ||
"@babel/preset-env": "^7.24.5", | ||
"@babel/preset-typescript": "^7.24.1", | ||
"@types/jest": "^29.5.12", | ||
"@vercel/ncc": "^0.38.1", | ||
"babel-jest": "^29.7.0", | ||
"jest": "^29.7.0", | ||
"typedoc": "^0.25.13", | ||
"typescript": "^5.4.5" | ||
"ts-jest": "^29.1.5", | ||
"ts-node": "^10.9.2", | ||
"typedoc": "^0.26.4", | ||
"typescript": "^5.5.3" | ||
}, | ||
"dependencies": { | ||
"@psdk/frame-father": "0.3.4" | ||
"@psdk/frame-father": "0.4.0" | ||
}, | ||
@@ -33,3 +31,3 @@ "files": [ | ||
], | ||
"gitHead": "b8c2fdcb52f1bd3e9d75d004d37d717bd465b4c9" | ||
"gitHead": "13fa8cc6aacbf8f6bacb5f485da11a7610001f61" | ||
} |
8619
7
200
+ Added@psdk/frame-father@0.4.0(transitive)
- Removed@psdk/frame-father@0.3.4(transitive)
Updated@psdk/frame-father@0.4.0