@myshkouski/web-serial-polyfill 1.0.16

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/dist/serial.js ADDED
@@ -0,0 +1,505 @@
1
+ /*
2
+ * Copyright 2019 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the
5
+ * "License"); you may not use this file except in
6
+ * compliance with the License. You may obtain a copy of
7
+ * the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in
12
+ * writing, software distributed under the License is
13
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
14
+ * OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing
16
+ * permissions and limitations under the License.
17
+ */
18
+ 'use strict';
19
+ export var SerialPolyfillProtocol;
20
+ (function (SerialPolyfillProtocol) {
21
+ SerialPolyfillProtocol[SerialPolyfillProtocol["UsbCdcAcm"] = 0] = "UsbCdcAcm";
22
+ })(SerialPolyfillProtocol || (SerialPolyfillProtocol = {}));
23
+ const kSetLineCoding = 0x20;
24
+ const kSetControlLineState = 0x22;
25
+ const kSendBreak = 0x23;
26
+ const kDefaultBufferSize = 255;
27
+ const kDefaultDataBits = 8;
28
+ const kDefaultParity = 'none';
29
+ const kDefaultStopBits = 1;
30
+ const kAcceptableDataBits = [16, 8, 7, 6, 5];
31
+ const kAcceptableStopBits = [1, 2];
32
+ const kAcceptableParity = ['none', 'even', 'odd'];
33
+ const kParityIndexMapping = ['none', 'odd', 'even'];
34
+ const kStopBitsIndexMapping = [1, 1.5, 2];
35
+ const kDefaultPolyfillOptions = {
36
+ protocol: SerialPolyfillProtocol.UsbCdcAcm,
37
+ usbControlInterfaceClass: 2,
38
+ usbTransferInterfaceClass: 10,
39
+ };
40
+ /**
41
+ * Utility function to get the interface implementing a desired class.
42
+ * @param {USBDevice} device The USB device.
43
+ * @param {number} classCode The desired interface class.
44
+ * @return {USBInterface} The first interface found that implements the desired
45
+ * class.
46
+ * @throws TypeError if no interface is found.
47
+ */
48
+ function findInterface(device, classCode) {
49
+ const configuration = device.configurations[0];
50
+ for (const iface of configuration.interfaces) {
51
+ const alternate = iface.alternates[0];
52
+ if (alternate.interfaceClass === classCode) {
53
+ return iface;
54
+ }
55
+ }
56
+ throw new TypeError(`Unable to find interface with class ${classCode}.`);
57
+ }
58
+ /**
59
+ * Utility function to get an endpoint with a particular direction.
60
+ * @param {USBInterface} iface The interface to search.
61
+ * @param {USBDirection} direction The desired transfer direction.
62
+ * @return {USBEndpoint} The first endpoint with the desired transfer direction.
63
+ * @throws TypeError if no endpoint is found.
64
+ */
65
+ function findEndpoint(iface, direction) {
66
+ const alternate = iface.alternates[0];
67
+ for (const endpoint of alternate.endpoints) {
68
+ if (endpoint.direction == direction) {
69
+ return endpoint;
70
+ }
71
+ }
72
+ throw new TypeError(`Interface ${iface.interfaceNumber} does not have an ` +
73
+ `${direction} endpoint.`);
74
+ }
75
+ /**
76
+ * Implementation of the underlying source API[1] which reads data from a USB
77
+ * endpoint. This can be used to construct a ReadableStream.
78
+ *
79
+ * [1]: https://streams.spec.whatwg.org/#underlying-source-api
80
+ */
81
+ class UsbEndpointUnderlyingSource {
82
+ /**
83
+ * Constructs a new UnderlyingSource that will pull data from the specified
84
+ * endpoint on the given USB device.
85
+ *
86
+ * @param {USBDevice} device
87
+ * @param {USBEndpoint} endpoint
88
+ * @param {function} onError function to be called on error
89
+ */
90
+ constructor(device, endpoint, onError) {
91
+ this.type = 'bytes';
92
+ this.device_ = device;
93
+ this.endpoint_ = endpoint;
94
+ this.onError_ = onError;
95
+ }
96
+ /**
97
+ * Reads a chunk of data from the device.
98
+ *
99
+ * @param {ReadableByteStreamController} controller
100
+ */
101
+ async pull(controller) {
102
+ var _a;
103
+ let chunkSize;
104
+ if (controller.desiredSize) {
105
+ const d = controller.desiredSize / this.endpoint_.packetSize;
106
+ chunkSize = Math.ceil(d) * this.endpoint_.packetSize;
107
+ }
108
+ else {
109
+ chunkSize = this.endpoint_.packetSize;
110
+ }
111
+ try {
112
+ const result = await this.device_.transferIn(this.endpoint_.endpointNumber, chunkSize);
113
+ if (result.status != 'ok') {
114
+ controller.error(`USB error: ${result.status}`);
115
+ this.onError_();
116
+ }
117
+ if ((_a = result.data) === null || _a === void 0 ? void 0 : _a.buffer) {
118
+ const chunk = new Uint8Array(result.data.buffer, result.data.byteOffset, result.data.byteLength);
119
+ controller.enqueue(chunk);
120
+ }
121
+ }
122
+ catch (error) {
123
+ controller.error(error.toString());
124
+ this.onError_();
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * Implementation of the underlying sink API[2] which writes data to a USB
130
+ * endpoint. This can be used to construct a WritableStream.
131
+ *
132
+ * [2]: https://streams.spec.whatwg.org/#underlying-sink-api
133
+ */
134
+ class UsbEndpointUnderlyingSink {
135
+ /**
136
+ * Constructs a new UnderlyingSink that will write data to the specified
137
+ * endpoint on the given USB device.
138
+ *
139
+ * @param {USBDevice} device
140
+ * @param {USBEndpoint} endpoint
141
+ * @param {function} onError function to be called on error
142
+ */
143
+ constructor(device, endpoint, onError) {
144
+ this.device_ = device;
145
+ this.endpoint_ = endpoint;
146
+ this.onError_ = onError;
147
+ }
148
+ /**
149
+ * Writes a chunk to the device.
150
+ *
151
+ * @param {Uint8Array} chunk
152
+ * @param {WritableStreamDefaultController} controller
153
+ */
154
+ async write(chunk, controller) {
155
+ try {
156
+ const result = await this.device_.transferOut(this.endpoint_.endpointNumber, chunk);
157
+ if (result.status != 'ok') {
158
+ controller.error(result.status);
159
+ this.onError_();
160
+ }
161
+ }
162
+ catch (error) {
163
+ controller.error(error.toString());
164
+ this.onError_();
165
+ }
166
+ }
167
+ }
168
+ /** a class used to control serial devices over WebUSB */
169
+ export class SerialPort {
170
+ /**
171
+ * constructor taking a WebUSB device that creates a SerialPort instance.
172
+ * @param {USBDevice} device A device acquired from the WebUSB API
173
+ * @param {SerialPolyfillOptions} polyfillOptions Optional options to
174
+ * configure the polyfill.
175
+ */
176
+ constructor(device, polyfillOptions) {
177
+ this.polyfillOptions_ = Object.assign(Object.assign({}, kDefaultPolyfillOptions), polyfillOptions);
178
+ this.outputSignals_ = {
179
+ dataTerminalReady: false,
180
+ requestToSend: false,
181
+ break: false,
182
+ };
183
+ this.device_ = device;
184
+ this.controlInterface_ = findInterface(this.device_, this.polyfillOptions_.usbControlInterfaceClass);
185
+ this.transferInterface_ = findInterface(this.device_, this.polyfillOptions_.usbTransferInterfaceClass);
186
+ this.inEndpoint_ = findEndpoint(this.transferInterface_, 'in');
187
+ this.outEndpoint_ = findEndpoint(this.transferInterface_, 'out');
188
+ }
189
+ /**
190
+ * Getter for the readable attribute. Constructs a new ReadableStream as
191
+ * necessary.
192
+ * @return {ReadableStream} the current readable stream
193
+ */
194
+ get readable() {
195
+ var _a;
196
+ if (!this.readable_ && this.device_.opened) {
197
+ this.readable_ = new ReadableStream(new UsbEndpointUnderlyingSource(this.device_, this.inEndpoint_, () => {
198
+ this.readable_ = null;
199
+ }), {
200
+ highWaterMark: (_a = this.serialOptions_.bufferSize) !== null && _a !== void 0 ? _a : kDefaultBufferSize,
201
+ });
202
+ }
203
+ return this.readable_;
204
+ }
205
+ /**
206
+ * Getter for the writable attribute. Constructs a new WritableStream as
207
+ * necessary.
208
+ * @return {WritableStream} the current writable stream
209
+ */
210
+ get writable() {
211
+ var _a;
212
+ if (!this.writable_ && this.device_.opened) {
213
+ this.writable_ = new WritableStream(new UsbEndpointUnderlyingSink(this.device_, this.outEndpoint_, () => {
214
+ this.writable_ = null;
215
+ }), new ByteLengthQueuingStrategy({
216
+ highWaterMark: (_a = this.serialOptions_.bufferSize) !== null && _a !== void 0 ? _a : kDefaultBufferSize,
217
+ }));
218
+ }
219
+ return this.writable_;
220
+ }
221
+ /**
222
+ * a function that opens the device and claims all interfaces needed to
223
+ * control and communicate to and from the serial device
224
+ * @param {SerialOptions} options Object containing serial options
225
+ * @return {Promise<void>} A promise that will resolve when device is ready
226
+ * for communication
227
+ */
228
+ async open(options) {
229
+ this.serialOptions_ = options;
230
+ this.validateOptions();
231
+ try {
232
+ await this.device_.open();
233
+ if (this.device_.configuration === null) {
234
+ await this.device_.selectConfiguration(1);
235
+ }
236
+ await this.device_.claimInterface(this.controlInterface_.interfaceNumber);
237
+ if (this.controlInterface_ !== this.transferInterface_) {
238
+ await this.device_.claimInterface(this.transferInterface_.interfaceNumber);
239
+ }
240
+ await this.setLineCoding();
241
+ await this.setSignals({ dataTerminalReady: true });
242
+ }
243
+ catch (error) {
244
+ if (this.device_.opened) {
245
+ await this.device_.close();
246
+ }
247
+ throw new Error('Error setting up device: ' + error.toString());
248
+ }
249
+ }
250
+ /**
251
+ * Closes the port.
252
+ *
253
+ * @return {Promise<void>} A promise that will resolve when the port is
254
+ * closed.
255
+ */
256
+ async close() {
257
+ const promises = [];
258
+ if (this.readable_) {
259
+ promises.push(this.readable_.cancel());
260
+ }
261
+ if (this.writable_) {
262
+ promises.push(this.writable_.abort());
263
+ }
264
+ await Promise.all(promises);
265
+ this.readable_ = null;
266
+ this.writable_ = null;
267
+ if (this.device_.opened) {
268
+ await this.setSignals({ dataTerminalReady: false, requestToSend: false });
269
+ await this.device_.releaseInterface(this.transferInterface_.interfaceNumber);
270
+ await this.device_.close();
271
+ }
272
+ }
273
+ /**
274
+ * Forgets the port.
275
+ *
276
+ * @return {Promise<void>} A promise that will resolve when the port is
277
+ * forgotten.
278
+ */
279
+ async forget() {
280
+ return this.device_.forget();
281
+ }
282
+ /**
283
+ * A function that returns properties of the device.
284
+ * @return {SerialPortInfo} Device properties.
285
+ */
286
+ getInfo() {
287
+ return {
288
+ usbVendorId: this.device_.vendorId,
289
+ usbProductId: this.device_.productId,
290
+ };
291
+ }
292
+ /**
293
+ * A function used to change the serial settings of the device
294
+ * @param {object} options the object which carries serial settings data
295
+ * @return {Promise<void>} A promise that will resolve when the options are
296
+ * set
297
+ */
298
+ reconfigure(options) {
299
+ this.serialOptions_ = Object.assign(Object.assign({}, this.serialOptions_), options);
300
+ this.validateOptions();
301
+ return this.setLineCoding();
302
+ }
303
+ /**
304
+ * Sets control signal state for the port.
305
+ * @param {SerialOutputSignals} signals The signals to enable or disable.
306
+ * @return {Promise<void>} a promise that is resolved when the signal state
307
+ * has been changed.
308
+ */
309
+ async setSignals(signals) {
310
+ this.outputSignals_ = Object.assign(Object.assign({}, this.outputSignals_), signals);
311
+ if (signals.dataTerminalReady !== undefined ||
312
+ signals.requestToSend !== undefined) {
313
+ // The Set_Control_Line_State command expects a bitmap containing the
314
+ // values of all output signals that should be enabled or disabled.
315
+ //
316
+ // Ref: USB CDC specification version 1.1 §6.2.14.
317
+ const value = (this.outputSignals_.dataTerminalReady ? 1 << 0 : 0) |
318
+ (this.outputSignals_.requestToSend ? 1 << 1 : 0);
319
+ await this.device_.controlTransferOut({
320
+ 'requestType': 'class',
321
+ 'recipient': 'interface',
322
+ 'request': kSetControlLineState,
323
+ 'value': value,
324
+ 'index': this.controlInterface_.interfaceNumber,
325
+ });
326
+ }
327
+ if (signals.break !== undefined) {
328
+ // The SendBreak command expects to be given a duration for how long the
329
+ // break signal should be asserted. Passing 0xFFFF enables the signal
330
+ // until 0x0000 is send.
331
+ //
332
+ // Ref: USB CDC specification version 1.1 §6.2.15.
333
+ const value = this.outputSignals_.break ? 0xFFFF : 0x0000;
334
+ await this.device_.controlTransferOut({
335
+ 'requestType': 'class',
336
+ 'recipient': 'interface',
337
+ 'request': kSendBreak,
338
+ 'value': value,
339
+ 'index': this.controlInterface_.interfaceNumber,
340
+ });
341
+ }
342
+ }
343
+ /**
344
+ * Checks the serial options for validity and throws an error if it is
345
+ * not valid
346
+ */
347
+ validateOptions() {
348
+ if (!this.isValidBaudRate(this.serialOptions_.baudRate)) {
349
+ throw new RangeError('invalid Baud Rate ' + this.serialOptions_.baudRate);
350
+ }
351
+ if (!this.isValidDataBits(this.serialOptions_.dataBits)) {
352
+ throw new RangeError('invalid dataBits ' + this.serialOptions_.dataBits);
353
+ }
354
+ if (!this.isValidStopBits(this.serialOptions_.stopBits)) {
355
+ throw new RangeError('invalid stopBits ' + this.serialOptions_.stopBits);
356
+ }
357
+ if (!this.isValidParity(this.serialOptions_.parity)) {
358
+ throw new RangeError('invalid parity ' + this.serialOptions_.parity);
359
+ }
360
+ }
361
+ /**
362
+ * Checks the baud rate for validity
363
+ * @param {number} baudRate the baud rate to check
364
+ * @return {boolean} A boolean that reflects whether the baud rate is valid
365
+ */
366
+ isValidBaudRate(baudRate) {
367
+ return baudRate % 1 === 0;
368
+ }
369
+ /**
370
+ * Checks the data bits for validity
371
+ * @param {number} dataBits the data bits to check
372
+ * @return {boolean} A boolean that reflects whether the data bits setting is
373
+ * valid
374
+ */
375
+ isValidDataBits(dataBits) {
376
+ if (typeof dataBits === 'undefined') {
377
+ return true;
378
+ }
379
+ return kAcceptableDataBits.includes(dataBits);
380
+ }
381
+ /**
382
+ * Checks the stop bits for validity
383
+ * @param {number} stopBits the stop bits to check
384
+ * @return {boolean} A boolean that reflects whether the stop bits setting is
385
+ * valid
386
+ */
387
+ isValidStopBits(stopBits) {
388
+ if (typeof stopBits === 'undefined') {
389
+ return true;
390
+ }
391
+ return kAcceptableStopBits.includes(stopBits);
392
+ }
393
+ /**
394
+ * Checks the parity for validity
395
+ * @param {string} parity the parity to check
396
+ * @return {boolean} A boolean that reflects whether the parity is valid
397
+ */
398
+ isValidParity(parity) {
399
+ if (typeof parity === 'undefined') {
400
+ return true;
401
+ }
402
+ return kAcceptableParity.includes(parity);
403
+ }
404
+ /**
405
+ * sends the options alog the control interface to set them on the device
406
+ * @return {Promise} a promise that will resolve when the options are set
407
+ */
408
+ async setLineCoding() {
409
+ var _a, _b, _c;
410
+ // Ref: USB CDC specification version 1.1 §6.2.12.
411
+ const buffer = new ArrayBuffer(7);
412
+ const view = new DataView(buffer);
413
+ view.setUint32(0, this.serialOptions_.baudRate, true);
414
+ view.setUint8(4, kStopBitsIndexMapping.indexOf((_a = this.serialOptions_.stopBits) !== null && _a !== void 0 ? _a : kDefaultStopBits));
415
+ view.setUint8(5, kParityIndexMapping.indexOf((_b = this.serialOptions_.parity) !== null && _b !== void 0 ? _b : kDefaultParity));
416
+ view.setUint8(6, (_c = this.serialOptions_.dataBits) !== null && _c !== void 0 ? _c : kDefaultDataBits);
417
+ const result = await this.device_.controlTransferOut({
418
+ 'requestType': 'class',
419
+ 'recipient': 'interface',
420
+ 'request': kSetLineCoding,
421
+ 'value': 0x00,
422
+ 'index': this.controlInterface_.interfaceNumber,
423
+ }, buffer);
424
+ if (result.status != 'ok') {
425
+ throw new DOMException('NetworkError', 'Failed to set line coding.');
426
+ }
427
+ }
428
+ }
429
+ /** generic implementation of navigator.serial object */
430
+ export class BaseSerial {
431
+ /**
432
+ * @param {USB} usb Instance of navigator.usb object
433
+ */
434
+ constructor(usb) {
435
+ this.usb = usb;
436
+ }
437
+ /**
438
+ * Requests permission to access a new port.
439
+ *
440
+ * @param {SerialPortRequestOptions} options
441
+ * @param {SerialPolyfillOptions} polyfillOptions
442
+ * @return {Promise<SerialPort>}
443
+ */
444
+ async requestPort(options, polyfillOptions) {
445
+ polyfillOptions = Object.assign(Object.assign({}, kDefaultPolyfillOptions), polyfillOptions);
446
+ const usbFilters = [];
447
+ if (options && options.filters) {
448
+ for (const filter of options.filters) {
449
+ const usbFilter = {
450
+ classCode: polyfillOptions.usbControlInterfaceClass,
451
+ };
452
+ if (filter.usbVendorId !== undefined) {
453
+ usbFilter.vendorId = filter.usbVendorId;
454
+ }
455
+ if (filter.usbProductId !== undefined) {
456
+ usbFilter.productId = filter.usbProductId;
457
+ }
458
+ usbFilters.push(usbFilter);
459
+ }
460
+ }
461
+ if (usbFilters.length === 0) {
462
+ usbFilters.push({
463
+ classCode: polyfillOptions.usbControlInterfaceClass,
464
+ });
465
+ }
466
+ const device = await this.usb.requestDevice({ 'filters': usbFilters });
467
+ const port = this.createPort(device, polyfillOptions);
468
+ return port;
469
+ }
470
+ /**
471
+ * Get the set of currently available ports.
472
+ *
473
+ * @param {SerialPolyfillOptions} polyfillOptions Polyfill configuration that
474
+ * should be applied to these ports.
475
+ * @return {Promise<SerialPort[]>} a promise that is resolved with a list of
476
+ * ports.
477
+ */
478
+ async getPorts(polyfillOptions) {
479
+ polyfillOptions = Object.assign(Object.assign({}, kDefaultPolyfillOptions), polyfillOptions);
480
+ const devices = await this.usb.getDevices();
481
+ const ports = [];
482
+ devices.forEach((device) => {
483
+ try {
484
+ const port = this.createPort(device, polyfillOptions);
485
+ ports.push(port);
486
+ }
487
+ catch (e) {
488
+ // Skip unrecognized port.
489
+ }
490
+ });
491
+ return ports;
492
+ }
493
+ }
494
+ /** default implementation of the global navigator.serial object */
495
+ export class Serial extends BaseSerial {
496
+ /**
497
+ * @param {USBDevice} device
498
+ * @param {SerialPolyfillOptions} options
499
+ * @return {SerialPort} Default serial port implementation
500
+ */
501
+ createPort(device, options) {
502
+ return new SerialPort(device, options);
503
+ }
504
+ }
505
+ //# sourceMappingURL=serial.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serial.js","sourceRoot":"","sources":["../serial.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,YAAY,CAAC;AAEb,MAAM,CAAN,IAAY,sBAEX;AAFD,WAAY,sBAAsB;IAChC,6EAAS,CAAA;AACX,CAAC,EAFW,sBAAsB,KAAtB,sBAAsB,QAEjC;AAQD,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,MAAM,mBAAmB,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7C,MAAM,mBAA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ClB;YAAC,OAAO,CAAC,EAAE;gBACV,0BAA0B;aAC3B;QACH,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,mEAAmE;AACnE,MAAM,OAAO,MAAO,SAAQ,UAAsB;IAChD;;;;OAIG;IACO,UAAU,CAAC,MAAiB,EAClC,OAA+B;QACjC,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@myshkouski/web-serial-polyfill",
3
+ "version": "1.0.16",
4
+ "description": "An implementation of the [Serial API](https://wicg.github.io/serial) on top of the [WebUSB API](https://wicg.github.io/webusb) for use with USB-to-serial adapters. Use of this library is limited to hardware and platforms where the device is accessible via the WebUSB API because it has not been claimed by a built-in device driver. This project will be used to prototype the design of the Serial API.",
5
+ "type": "module",
6
+ "main": "./dist/serial.js",
7
+ "types": "./dist/serial.d.ts",
8
+ "scripts": {
9
+ "lint": "eslint serial.ts",
10
+ "build": "tsc -d",
11
+ "prepublish": "tsc -d"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/google/web-serial-polyfill.git"
16
+ },
17
+ "author": "James C Hollyer",
18
+ "license": "Apache",
19
+ "devDependencies": {
20
+ "@types/w3c-web-serial": "^1.0.3",
21
+ "@types/w3c-web-usb": "^1.0.6",
22
+ "@types/web": "^0.0.71",
23
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
24
+ "@typescript-eslint/parser": "^5.33.0",
25
+ "eslint": "^8.21.0",
26
+ "eslint-config-google": "^0.14.0",
27
+ "typescript": "^4.7.4"
28
+ }
29
+ }