@psdk/device-webusb 0.5.16 → 0.5.18

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/README.md ADDED
@@ -0,0 +1,19 @@
1
+ @psdk/device-webusb
2
+ ===
3
+
4
+ ```
5
+ npm i @psdk/device-webusb
6
+ ```
7
+
8
+ <!--harmony-->
9
+
10
+ ## How to use
11
+
12
+ ```js
13
+ const webusb = Webusb.withFilter({
14
+ vendorId: 1234,
15
+ productId: 5678,
16
+ });
17
+ await webusb.connect();
18
+ ```
19
+
package/build/index.js CHANGED
@@ -3,17 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeviceFilter = exports.WebusbReadOptions = exports.Webusb = void 0;
4
4
  const frame_father_1 = require("@psdk/frame-father");
5
5
  class Webusb {
6
+ filters;
7
+ configuration;
8
+ interface;
9
+ readEndpoint;
10
+ writeEndpoint;
11
+ inputReadEndpoint;
12
+ inputWriteEndpoint;
13
+ state;
14
+ device;
6
15
  constructor(options) {
7
- var _a, _b, _c, _d;
8
16
  if (options.filters.length == 0) {
9
17
  throw new Error('Missing filters');
10
18
  }
11
19
  this.filters = options.filters;
12
- this.configuration = (_a = options.configuration) !== null && _a !== void 0 ? _a : 1;
13
- this.interface = (_b = options.interface) !== null && _b !== void 0 ? _b : 0;
20
+ this.configuration = options.configuration ?? 1;
21
+ this.interface = options.interface ?? 0;
14
22
  this.state = frame_father_1.ConnectionState.DISCONNECTED;
15
- this.inputReadEndpoint = (_c = options.readEndpoint) !== null && _c !== void 0 ? _c : 2;
16
- this.inputWriteEndpoint = (_d = options.writeEndpoint) !== null && _d !== void 0 ? _d : 2;
23
+ this.inputReadEndpoint = options.readEndpoint ?? 2;
24
+ this.inputWriteEndpoint = options.writeEndpoint ?? 2;
17
25
  }
18
26
  static withFilter(filter) {
19
27
  return this.withFilters([filter]);
@@ -80,7 +88,7 @@ class Webusb {
80
88
  }
81
89
  async read(options) {
82
90
  const device = _device();
83
- const _options = options !== null && options !== void 0 ? options : WebusbReadOptions.def();
91
+ const _options = options ?? WebusbReadOptions.def();
84
92
  const result = await device.transferIn(_readEndpoint(), _options.readLength);
85
93
  const { status, data } = result;
86
94
  if (status != 'ok') {
@@ -104,10 +112,10 @@ class Webusb {
104
112
  }
105
113
  exports.Webusb = Webusb;
106
114
  class WebusbReadOptions extends frame_father_1.ReadOptions {
115
+ _length;
107
116
  constructor(options) {
108
- var _a;
109
117
  super(options);
110
- this._length = (_a = options === null || options === void 0 ? void 0 : options.length) !== null && _a !== void 0 ? _a : 1024;
118
+ this._length = options?.length ?? 1024;
111
119
  }
112
120
  static def() {
113
121
  return new WebusbReadOptions();
@@ -118,6 +126,8 @@ class WebusbReadOptions extends frame_father_1.ReadOptions {
118
126
  }
119
127
  exports.WebusbReadOptions = WebusbReadOptions;
120
128
  class DeviceFilter {
129
+ vendorId;
130
+ productId;
121
131
  constructor(options) {
122
132
  this.vendorId = options.vendorId;
123
133
  this.productId = options.productId;