@psdk/device-webusb 0.3.4 → 0.5.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.
Files changed (2) hide show
  1. package/build/index.js +33 -17
  2. package/package.json +7 -9
package/build/index.js CHANGED
@@ -1,16 +1,27 @@
1
- import { ConnectionState, ReadOptions } from "@psdk/frame-father";
2
- export class Webusb {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceFilter = exports.WebusbReadOptions = exports.Webusb = void 0;
4
+ const frame_father_1 = require("@psdk/frame-father");
5
+ class Webusb {
6
+ filters;
7
+ configuration;
8
+ interface;
9
+ readEndpoint;
10
+ writeEndpoint;
11
+ inputReadEndpoint;
12
+ inputWriteEndpoint;
13
+ state;
14
+ device;
3
15
  constructor(options) {
4
- var _a, _b, _c, _d;
5
16
  if (options.filters.length == 0) {
6
17
  throw new Error('Missing filters');
7
18
  }
8
19
  this.filters = options.filters;
9
- this.configuration = (_a = options.configuration) !== null && _a !== void 0 ? _a : 1;
10
- this.interface = (_b = options.interface) !== null && _b !== void 0 ? _b : 0;
11
- this.state = ConnectionState.DISCONNECTED;
12
- this.inputReadEndpoint = (_c = options.readEndpoint) !== null && _c !== void 0 ? _c : 2;
13
- this.inputWriteEndpoint = (_d = options.writeEndpoint) !== null && _d !== void 0 ? _d : 2;
20
+ this.configuration = options.configuration ?? 1;
21
+ this.interface = options.interface ?? 0;
22
+ this.state = frame_father_1.ConnectionState.DISCONNECTED;
23
+ this.inputReadEndpoint = options.readEndpoint ?? 2;
24
+ this.inputWriteEndpoint = options.writeEndpoint ?? 2;
14
25
  }
15
26
  static withFilter(filter) {
16
27
  return this.withFilters([filter]);
@@ -37,14 +48,14 @@ export class Webusb {
37
48
  const outEndpoints = alternates.endpoints.filter(endpoint => endpoint.direction === 'out');
38
49
  this.readEndpoint = inEndpoints && inEndpoints.length ? inEndpoints[0].endpointNumber : this.inputReadEndpoint;
39
50
  this.writeEndpoint = outEndpoints && outEndpoints.length ? outEndpoints[0].endpointNumber : this.inputWriteEndpoint;
40
- this.state = ConnectionState.CONNECTED;
51
+ this.state = frame_father_1.ConnectionState.CONNECTED;
41
52
  // @ts-ignore
42
53
  navigator.usb.addEventListener('connect', e => {
43
- this.state = ConnectionState.CONNECTED;
54
+ this.state = frame_father_1.ConnectionState.CONNECTED;
44
55
  });
45
56
  // @ts-ignore
46
57
  navigator.usb.addEventListener('disconnect', e => {
47
- this.state = ConnectionState.DISCONNECTED;
58
+ this.state = frame_father_1.ConnectionState.DISCONNECTED;
48
59
  });
49
60
  this.device = device;
50
61
  return await this.connectedDevice();
@@ -61,7 +72,7 @@ export class Webusb {
61
72
  connectionState() {
62
73
  const device = _device();
63
74
  if (!device.opened) {
64
- return ConnectionState.DISCONNECTED;
75
+ return frame_father_1.ConnectionState.DISCONNECTED;
65
76
  }
66
77
  return _connectionState();
67
78
  }
@@ -77,7 +88,7 @@ export class Webusb {
77
88
  }
78
89
  async read(options) {
79
90
  const device = _device();
80
- const _options = options !== null && options !== void 0 ? options : WebusbReadOptions.def();
91
+ const _options = options ?? WebusbReadOptions.def();
81
92
  const result = await device.transferIn(_readEndpoint(), _options.readLength);
82
93
  const { status, data } = result;
83
94
  if (status != 'ok') {
@@ -99,11 +110,12 @@ export class Webusb {
99
110
  };
100
111
  }
101
112
  }
102
- export class WebusbReadOptions extends ReadOptions {
113
+ exports.Webusb = Webusb;
114
+ class WebusbReadOptions extends frame_father_1.ReadOptions {
115
+ _length;
103
116
  constructor(options) {
104
- var _a;
105
117
  super(options);
106
- this._length = (_a = options === null || options === void 0 ? void 0 : options.length) !== null && _a !== void 0 ? _a : 1024;
118
+ this._length = options?.length ?? 1024;
107
119
  }
108
120
  static def() {
109
121
  return new WebusbReadOptions();
@@ -112,9 +124,13 @@ export class WebusbReadOptions extends ReadOptions {
112
124
  return this._length;
113
125
  }
114
126
  }
115
- export class DeviceFilter {
127
+ exports.WebusbReadOptions = WebusbReadOptions;
128
+ class DeviceFilter {
129
+ vendorId;
130
+ productId;
116
131
  constructor(options) {
117
132
  this.vendorId = options.vendorId;
118
133
  this.productId = options.productId;
119
134
  }
120
135
  }
136
+ exports.DeviceFilter = DeviceFilter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psdk/device-webusb",
3
- "version": "0.3.4",
3
+ "version": "0.5.0",
4
4
  "description": "psdk",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -12,22 +12,20 @@
12
12
  },
13
13
  "author": "",
14
14
  "devDependencies": {
15
- "@babel/core": "^7.24.5",
16
- "@babel/preset-env": "^7.24.5",
17
- "@babel/preset-typescript": "^7.24.1",
18
15
  "@types/jest": "^29.5.12",
19
16
  "@vercel/ncc": "^0.38.1",
20
- "babel-jest": "^29.7.0",
21
17
  "jest": "^29.7.0",
22
- "typedoc": "^0.25.13",
23
- "typescript": "^5.4.5"
18
+ "ts-jest": "^29.1.5",
19
+ "ts-node": "^10.9.2",
20
+ "typedoc": "^0.26.4",
21
+ "typescript": "^5.5.3"
24
22
  },
25
23
  "dependencies": {
26
- "@psdk/frame-father": "0.3.4"
24
+ "@psdk/frame-father": "0.5.0"
27
25
  },
28
26
  "files": [
29
27
  "build",
30
28
  "!build/browser/psdk*"
31
29
  ],
32
- "gitHead": "b8c2fdcb52f1bd3e9d75d004d37d717bd465b4c9"
30
+ "gitHead": "0de75b4e37274d7a68a04aa34501fa3297769185"
33
31
  }