react-native-web-serial-api 0.0.2 → 0.1.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.
- package/README.md +23 -0
- package/TESTING.md +301 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/dev/webserialapi/NativeUsbSerialModule.java +7 -1
- package/lib/commonjs/UsbSerial.js +58 -26
- package/lib/commonjs/UsbSerial.js.map +1 -1
- package/lib/commonjs/WebSerial.js +169 -57
- package/lib/commonjs/WebSerial.js.map +1 -1
- package/lib/commonjs/index.js +13 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/lib/dom-exception.js +176 -0
- package/lib/commonjs/lib/dom-exception.js.map +1 -0
- package/lib/commonjs/lib/event-target.js +138 -0
- package/lib/commonjs/lib/event-target.js.map +1 -0
- package/lib/commonjs/lib/promise.js +23 -0
- package/lib/commonjs/lib/promise.js.map +1 -0
- package/lib/commonjs/testing/index.js +70 -0
- package/lib/commonjs/testing/index.js.map +1 -0
- package/lib/commonjs/testing/install.js +54 -0
- package/lib/commonjs/testing/install.js.map +1 -0
- package/lib/commonjs/testing/serial-device.js +164 -0
- package/lib/commonjs/testing/serial-device.js.map +1 -0
- package/lib/commonjs/testing/virtual-serial.js +615 -0
- package/lib/commonjs/testing/virtual-serial.js.map +1 -0
- package/lib/commonjs/transport.js +61 -0
- package/lib/commonjs/transport.js.map +1 -0
- package/lib/typescript/src/UsbSerial.d.ts +24 -67
- package/lib/typescript/src/UsbSerial.d.ts.map +1 -1
- package/lib/typescript/src/WebSerial.d.ts +11 -2
- package/lib/typescript/src/WebSerial.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/lib/dom-exception.d.ts +100 -0
- package/lib/typescript/src/lib/dom-exception.d.ts.map +1 -0
- package/lib/typescript/src/lib/event-target.d.ts +53 -0
- package/lib/typescript/src/lib/event-target.d.ts.map +1 -0
- package/lib/typescript/src/lib/promise.d.ts +11 -0
- package/lib/typescript/src/lib/promise.d.ts.map +1 -0
- package/lib/typescript/src/testing/index.d.ts +23 -0
- package/lib/typescript/src/testing/index.d.ts.map +1 -0
- package/lib/typescript/src/testing/install.d.ts +25 -0
- package/lib/typescript/src/testing/install.d.ts.map +1 -0
- package/lib/typescript/src/testing/serial-device.d.ts +127 -0
- package/lib/typescript/src/testing/serial-device.d.ts.map +1 -0
- package/lib/typescript/src/testing/virtual-serial.d.ts +205 -0
- package/lib/typescript/src/testing/virtual-serial.d.ts.map +1 -0
- package/lib/typescript/src/transport.d.ts +131 -0
- package/lib/typescript/src/transport.d.ts.map +1 -0
- package/package.json +38 -2
- package/src/UsbSerial.ts +65 -90
- package/src/WebSerial.ts +227 -88
- package/src/index.ts +2 -7
- package/src/lib/dom-exception.ts +129 -60
- package/src/lib/event-target.ts +46 -21
- package/src/lib/promise.ts +7 -7
- package/src/testing/index.ts +42 -0
- package/src/testing/install.ts +65 -0
- package/src/testing/serial-device.ts +193 -0
- package/src/testing/virtual-serial.ts +801 -0
- package/src/transport.ts +200 -0
- package/babel.config.js +0 -3
- package/biome.json +0 -35
- package/example/.watchmanconfig +0 -1
- package/example/App.tsx +0 -71
- package/example/__tests__/App.test.tsx +0 -16
- package/example/__tests__/connectEvents.test.tsx +0 -81
- package/example/__tests__/getPorts.test.tsx +0 -140
- package/example/android/app/build.gradle +0 -120
- package/example/android/app/debug.keystore +0 -0
- package/example/android/app/proguard-rules.pro +0 -10
- package/example/android/app/src/debug/AndroidManifest.xml +0 -9
- package/example/android/app/src/main/AndroidManifest.xml +0 -38
- package/example/android/app/src/main/java/dev/uzlopak/MainActivity.kt +0 -22
- package/example/android/app/src/main/java/dev/uzlopak/MainApplication.kt +0 -41
- package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +0 -37
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/values/strings.xml +0 -3
- package/example/android/app/src/main/res/values/styles.xml +0 -9
- package/example/android/build.gradle +0 -22
- package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/android/gradle/wrapper/gradle-wrapper.properties +0 -7
- package/example/android/gradle.properties +0 -47
- package/example/android/gradlew +0 -252
- package/example/android/gradlew.bat +0 -94
- package/example/android/settings.gradle +0 -6
- package/example/app.json +0 -4
- package/example/babel.config.js +0 -21
- package/example/biome.json +0 -47
- package/example/deploy.sh +0 -11
- package/example/index.html +0 -26
- package/example/index.js +0 -9
- package/example/index.web.js +0 -8
- package/example/jest.config.js +0 -12
- package/example/metro.config.js +0 -58
- package/example/package-lock.json +0 -14510
- package/example/package.json +0 -48
- package/example/react-native.config.js +0 -17
- package/example/src/components/AppBar.tsx +0 -73
- package/example/src/components/Menu.tsx +0 -90
- package/example/src/components/SingleChoiceDialog.tsx +0 -120
- package/example/src/screens/ConnectScreen.tsx +0 -195
- package/example/src/screens/DevicesScreen.tsx +0 -248
- package/example/src/screens/TerminalScreen.tsx +0 -564
- package/example/src/settings.ts +0 -43
- package/example/src/theme.ts +0 -19
- package/example/src/util/TextUtil.ts +0 -129
- package/example/tsconfig.json +0 -10
- package/example/vite.config.mjs +0 -55
- package/scripts/deploy-release.sh +0 -127
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -20
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StopBits = exports.Parity = exports.DataBits = exports.DEFAULT_OPEN_OPTIONS = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Hardware-transport seam for the Web Serial polyfill.
|
|
9
|
+
*
|
|
10
|
+
* `SerialTransport` is the single interface that the `Serial`/`SerialPort`
|
|
11
|
+
* classes depend on to talk to "the device". The production implementation
|
|
12
|
+
* (`UsbSerialModule`, backed by the `NativeUsbSerial` TurboModule — see
|
|
13
|
+
* {@link ./UsbSerial}) and the in-memory test/dev double
|
|
14
|
+
* (`VirtualSerialTransport` — see {@link ./testing/virtual-serial}) both
|
|
15
|
+
* implement it.
|
|
16
|
+
*
|
|
17
|
+
* This module is intentionally free of any `react-native` import. That is what
|
|
18
|
+
* lets the virtual transport — and therefore the conformance suite built on top
|
|
19
|
+
* of it — run unchanged under Node/Jest, in a browser, and on a device.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// UsbSerialPort.ControlLine enum
|
|
23
|
+
|
|
24
|
+
// UsbSerialPort.FlowControl enum
|
|
25
|
+
|
|
26
|
+
const Parity = exports.Parity = {
|
|
27
|
+
NONE: 0,
|
|
28
|
+
ODD: 1,
|
|
29
|
+
EVEN: 2,
|
|
30
|
+
MARK: 3,
|
|
31
|
+
SPACE: 4
|
|
32
|
+
};
|
|
33
|
+
const DataBits = exports.DataBits = {
|
|
34
|
+
FIVE: 5,
|
|
35
|
+
SIX: 6,
|
|
36
|
+
SEVEN: 7,
|
|
37
|
+
EIGHT: 8
|
|
38
|
+
};
|
|
39
|
+
const StopBits = exports.StopBits = {
|
|
40
|
+
ONE: 1,
|
|
41
|
+
ONE_FIVE: 3,
|
|
42
|
+
TWO: 2
|
|
43
|
+
};
|
|
44
|
+
const DEFAULT_OPEN_OPTIONS = exports.DEFAULT_OPEN_OPTIONS = {
|
|
45
|
+
dataBits: DataBits.EIGHT,
|
|
46
|
+
stopBits: StopBits.ONE,
|
|
47
|
+
parity: Parity.NONE
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** Handle returned by the `on*` subscription methods. */
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The contract every serial transport must satisfy. It mirrors the JS-friendly
|
|
54
|
+
* surface of `UsbSerialModule` exactly, so `UsbSerialModule implements
|
|
55
|
+
* SerialTransport` is a faithful 1:1 and any conforming double (e.g.
|
|
56
|
+
* `VirtualSerialTransport`) is a drop-in replacement.
|
|
57
|
+
*
|
|
58
|
+
* Ports are addressed by the pair `(deviceId, portNumber)`. Inbound bytes,
|
|
59
|
+
* read errors and device attach/detach arrive through the `on*` subscriptions.
|
|
60
|
+
*/
|
|
61
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Parity","exports","NONE","ODD","EVEN","MARK","SPACE","DataBits","FIVE","SIX","SEVEN","EIGHT","StopBits","ONE","ONE_FIVE","TWO","DEFAULT_OPEN_OPTIONS","dataBits","stopBits","parity"],"sourceRoot":"../../src","sources":["transport.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAGA;;AA0DO,MAAMA,MAAM,GAAAC,OAAA,CAAAD,MAAA,GAAG;EACpBE,IAAI,EAAE,CAAC;EACPC,GAAG,EAAE,CAAC;EACNC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,KAAK,EAAE;AACT,CAAU;AAEH,MAAMC,QAAQ,GAAAN,OAAA,CAAAM,QAAA,GAAG;EACtBC,IAAI,EAAE,CAAC;EACPC,GAAG,EAAE,CAAC;EACNC,KAAK,EAAE,CAAC;EACRC,KAAK,EAAE;AACT,CAAU;AAEH,MAAMC,QAAQ,GAAAX,OAAA,CAAAW,QAAA,GAAG;EACtBC,GAAG,EAAE,CAAC;EACNC,QAAQ,EAAE,CAAC;EACXC,GAAG,EAAE;AACP,CAAU;AASH,MAAMC,oBAA6D,GAAAf,OAAA,CAAAe,oBAAA,GAAG;EAC3EC,QAAQ,EAAEV,QAAQ,CAACI,KAAK;EACxBO,QAAQ,EAAEN,QAAQ,CAACC,GAAG;EACtBM,MAAM,EAAEnB,MAAM,CAACE;AACjB,CAAC;;AAED;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -1,68 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export type
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
usbProductId?: number;
|
|
6
|
-
};
|
|
7
|
-
export type PortPickerLabels = {
|
|
8
|
-
titleSelectPort?: string;
|
|
9
|
-
titleNoPortsAvailable?: string;
|
|
10
|
-
messageNoPortsAvailable?: string;
|
|
11
|
-
};
|
|
12
|
-
export type PortId = {
|
|
13
|
-
deviceId: number;
|
|
14
|
-
portNumber: number;
|
|
15
|
-
usbVendorId: number;
|
|
16
|
-
usbProductId: number;
|
|
17
|
-
/**
|
|
18
|
-
* Whether the app currently holds Android USB permission to access this
|
|
19
|
-
* device (via the system attach dialog or a prior permission request).
|
|
20
|
-
*/
|
|
21
|
-
hasPermission: boolean;
|
|
22
|
-
};
|
|
23
|
-
export type DataEvent = {
|
|
24
|
-
deviceId: number;
|
|
25
|
-
portNumber: number;
|
|
26
|
-
data: number[];
|
|
27
|
-
};
|
|
28
|
-
export type ErrorEvent = {
|
|
29
|
-
deviceId: number;
|
|
30
|
-
portNumber: number;
|
|
31
|
-
error: string;
|
|
32
|
-
};
|
|
33
|
-
export type ConnectEvent = {
|
|
34
|
-
deviceId: number;
|
|
35
|
-
usbVendorId: number;
|
|
36
|
-
usbProductId: number;
|
|
37
|
-
};
|
|
38
|
-
export declare const Parity: {
|
|
39
|
-
readonly NONE: 0;
|
|
40
|
-
readonly ODD: 1;
|
|
41
|
-
readonly EVEN: 2;
|
|
42
|
-
readonly MARK: 3;
|
|
43
|
-
readonly SPACE: 4;
|
|
44
|
-
};
|
|
45
|
-
export declare const DataBits: {
|
|
46
|
-
readonly FIVE: 5;
|
|
47
|
-
readonly SIX: 6;
|
|
48
|
-
readonly SEVEN: 7;
|
|
49
|
-
readonly EIGHT: 8;
|
|
50
|
-
};
|
|
51
|
-
export declare const StopBits: {
|
|
52
|
-
readonly ONE: 1;
|
|
53
|
-
readonly ONE_FIVE: 3;
|
|
54
|
-
readonly TWO: 2;
|
|
55
|
-
};
|
|
56
|
-
export type OpenOptions = {
|
|
57
|
-
baudRate: number;
|
|
58
|
-
dataBits?: number;
|
|
59
|
-
stopBits?: number;
|
|
60
|
-
parity?: number;
|
|
61
|
-
};
|
|
62
|
-
type Subscription = {
|
|
63
|
-
remove: () => void;
|
|
64
|
-
};
|
|
65
|
-
export declare class UsbSerialModule {
|
|
1
|
+
import type { ConnectEvent, ControlLine, DataEvent, ErrorEvent, FlowControl, OpenOptions, PortFilter, PortId, PortPickerLabels, SerialTransport, Subscription } from './transport';
|
|
2
|
+
export type { ConnectEvent, ControlLine, DataEvent, ErrorEvent, FlowControl, OpenOptions, PortFilter, PortId, PortPickerLabels, SerialTransport, } from './transport';
|
|
3
|
+
export { DataBits, Parity, StopBits } from './transport';
|
|
4
|
+
export declare class UsbSerialModule implements SerialTransport {
|
|
66
5
|
private readonly native;
|
|
67
6
|
private readonly emitter;
|
|
68
7
|
constructor();
|
|
@@ -97,6 +36,24 @@ export declare class UsbSerialModule {
|
|
|
97
36
|
onConnect(listener: (event: ConnectEvent) => void): Subscription;
|
|
98
37
|
onDisconnect(listener: (event: ConnectEvent) => void): Subscription;
|
|
99
38
|
}
|
|
100
|
-
|
|
101
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Resolve the active serial transport. Returns the override set via
|
|
41
|
+
* {@link setUsbSerial} if present (used by tests and by the example's on-device
|
|
42
|
+
* "virtual device" mode); otherwise lazily constructs the real native-backed
|
|
43
|
+
* {@link UsbSerialModule}.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getUsbSerial(): SerialTransport;
|
|
46
|
+
/**
|
|
47
|
+
* Override the transport returned by {@link getUsbSerial}. Pass a
|
|
48
|
+
* {@link SerialTransport} (e.g. a `VirtualSerialTransport`) to make the
|
|
49
|
+
* singleton `serial` instance — and any `new Serial()` created without an
|
|
50
|
+
* explicit transport — talk to it instead of real hardware. Pass `null` to
|
|
51
|
+
* clear the override.
|
|
52
|
+
*
|
|
53
|
+
* Inject before the first `getPorts()` / `requestPort()` / `addEventListener()`
|
|
54
|
+
* call so the lazy initialisation in `Serial` picks it up.
|
|
55
|
+
*/
|
|
56
|
+
export declare function setUsbSerial(transport: SerialTransport | null): void;
|
|
57
|
+
/** Clear any override and drop the cached native instance (test teardown). */
|
|
58
|
+
export declare function resetUsbSerial(): void;
|
|
102
59
|
//# sourceMappingURL=UsbSerial.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsbSerial.d.ts","sourceRoot":"","sources":["../../../src/UsbSerial.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"UsbSerial.d.ts","sourceRoot":"","sources":["../../../src/UsbSerial.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,SAAS,EACT,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,YAAY,EACb,MAAM,aAAa,CAAC;AAOrB,YAAY,EACV,YAAY,EACZ,WAAW,EACX,SAAS,EACT,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAC;AAEvD,qBAAa,eAAgB,YAAW,eAA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,GACb,OAAO,CAAC,IAAI,CAAC;IAIhB,cAAc,CACZ,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,OAAO,EAC1B,gBAAgB,EAAE,OAAO,GACxB,OAAO,CAAC,IAAI,CAAC;IAShB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhE,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,GAAG,YAAY;IAO1D,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,GAAG,YAAY;IAO5D,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,YAAY;IAOhE,YAAY,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,YAAY;CAMpE;AAKD;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,eAAe,CAM9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAEpE;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,IAAI,IAAI,CAGrC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReadableStream, WritableStream } from 'web-streams-polyfill';
|
|
2
2
|
import { Event, EventTarget } from './lib/event-target';
|
|
3
|
-
import type {
|
|
3
|
+
import type { SerialTransport } from './transport';
|
|
4
4
|
/**
|
|
5
5
|
* @see https://wicg.github.io/serial/#dom-paritytype
|
|
6
6
|
*
|
|
@@ -149,7 +149,7 @@ export type SerialPortRequestOptions = {
|
|
|
149
149
|
*/
|
|
150
150
|
export declare class SerialPort extends EventTarget {
|
|
151
151
|
#private;
|
|
152
|
-
constructor(usb:
|
|
152
|
+
constructor(usb: SerialTransport, deviceId: number, portNumber: number, usbVendorId: number, usbProductId: number);
|
|
153
153
|
/**
|
|
154
154
|
* @see https://wicg.github.io/serial/#dom-serialport-onconnect
|
|
155
155
|
*/
|
|
@@ -212,6 +212,15 @@ export declare class SerialPort extends EventTarget {
|
|
|
212
212
|
*/
|
|
213
213
|
export declare class Serial extends EventTarget {
|
|
214
214
|
#private;
|
|
215
|
+
/**
|
|
216
|
+
* @param transport Optional transport override. When provided, this `Serial`
|
|
217
|
+
* talks to it instead of the global native module — the seam used by tests
|
|
218
|
+
* and the virtual-device harness (`new Serial(new VirtualSerialTransport())`).
|
|
219
|
+
* Omit it for the normal native-backed instance; the singleton `serial`
|
|
220
|
+
* export is created this way and can still be redirected globally via
|
|
221
|
+
* `setUsbSerial()`.
|
|
222
|
+
*/
|
|
223
|
+
constructor(transport?: SerialTransport);
|
|
215
224
|
/**
|
|
216
225
|
* Subscribing to "connect"/"disconnect" must wire up the native USB state
|
|
217
226
|
* listeners, so a consumer can receive attach/detach/permission events
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSerial.d.ts","sourceRoot":"","sources":["../../../src/WebSerial.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,cAAc,EACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAC,KAAK,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"WebSerial.d.ts","sourceRoot":"","sources":["../../../src/WebSerial.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,cAAc,EACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAC,KAAK,EAAE,WAAW,EAAiB,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAK,EAMV,eAAe,EAChB,MAAM,aAAa,CAAC;AAGrB;;;;;;GAMG;AACH,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAE1C;;;;GAIG;AACH,KAAK,eAAe,GAAG,MAAM,GAAG,UAAU,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,aA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IjD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA6D5B;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB7B;;OAEG;IACG,UAAU,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoElE;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,kBAAkB,CAAC;CAiFhD;AAED;;GAEG;AACH,qBAAa,MAAO,SAAQ,WAAW;;IAWrC;;;;;;;OAOG;gBACS,SAAS,CAAC,EAAE,eAAe;IAKvC;;;;OAIG;IACH,gBAAgB,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,GAAG,IAAI;IAgF5E;;OAEG;IACH,IAAI,SAAS,IAIK,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,CAFhD;IAED,IAAI,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,EAUhD;IAED;;OAEG;IACH,IAAI,YAAY,IAIK,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,CAFnD;IAED,IAAI,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,EAUnD;IAMD;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IA8CvC;;OAEG;IACG,WAAW,CACf,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,UAAU,CAAC;CAiFvB;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { default as serial } from './serial';
|
|
2
|
+
export type { SerialTransport } from './transport';
|
|
3
|
+
export { resetUsbSerial, setUsbSerial } from './UsbSerial';
|
|
2
4
|
export type { SerialInputSignals, SerialOptions, SerialOutputSignals, SerialPortFilter, SerialPortInfo, SerialPortRequestOptions, } from './WebSerial';
|
|
3
5
|
export { Serial, SerialPort } from './WebSerial';
|
|
4
6
|
import * as UsbSerial from './UsbSerial';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,UAAU,CAAC;AAC3C,YAAY,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AACjD,OAAO,EAAC,cAAc,EAAE,YAAY,EAAC,MAAM,aAAa,CAAC;AACzD,YAAY,EACV,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAC,KAAK,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAC,SAAS,EAAC,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOMException Polyfill
|
|
3
|
+
*
|
|
4
|
+
* Provides a spec-compliant DOMException implementation for environments
|
|
5
|
+
* where it is missing or incomplete (e.g. Node.js < 17, some older browsers).
|
|
6
|
+
*
|
|
7
|
+
* Spec: https://webidl.spec.whatwg.org/#idl-DOMException
|
|
8
|
+
*/
|
|
9
|
+
declare const DOM_EXCEPTION_CODES: Record<string, number>;
|
|
10
|
+
declare const DOM_EXCEPTION_NAMES: Record<number, string>;
|
|
11
|
+
export interface DOMExceptionConstructor {
|
|
12
|
+
new (message?: string, name?: string): DOMException;
|
|
13
|
+
readonly prototype: DOMException;
|
|
14
|
+
readonly INDEX_SIZE_ERR: 1;
|
|
15
|
+
readonly DOMSTRING_SIZE_ERR: 2;
|
|
16
|
+
readonly HIERARCHY_REQUEST_ERR: 3;
|
|
17
|
+
readonly WRONG_DOCUMENT_ERR: 4;
|
|
18
|
+
readonly INVALID_CHARACTER_ERR: 5;
|
|
19
|
+
readonly NO_DATA_ALLOWED_ERR: 6;
|
|
20
|
+
readonly NO_MODIFICATION_ALLOWED_ERR: 7;
|
|
21
|
+
readonly NOT_FOUND_ERR: 8;
|
|
22
|
+
readonly NOT_SUPPORTED_ERR: 9;
|
|
23
|
+
readonly INUSE_ATTRIBUTE_ERR: 10;
|
|
24
|
+
readonly INVALID_STATE_ERR: 11;
|
|
25
|
+
readonly SYNTAX_ERR: 12;
|
|
26
|
+
readonly INVALID_MODIFICATION_ERR: 13;
|
|
27
|
+
readonly NAMESPACE_ERR: 14;
|
|
28
|
+
readonly INVALID_ACCESS_ERR: 15;
|
|
29
|
+
readonly VALIDATION_ERR: 16;
|
|
30
|
+
readonly TYPE_MISMATCH_ERR: 17;
|
|
31
|
+
readonly SECURITY_ERR: 18;
|
|
32
|
+
readonly NETWORK_ERR: 19;
|
|
33
|
+
readonly ABORT_ERR: 20;
|
|
34
|
+
readonly URL_MISMATCH_ERR: 21;
|
|
35
|
+
readonly QUOTA_EXCEEDED_ERR: 22;
|
|
36
|
+
readonly TIMEOUT_ERR: 23;
|
|
37
|
+
readonly INVALID_NODE_TYPE_ERR: 24;
|
|
38
|
+
readonly DATA_CLONE_ERR: 25;
|
|
39
|
+
}
|
|
40
|
+
declare class DOMExceptionPolyfill extends Error {
|
|
41
|
+
readonly code: number;
|
|
42
|
+
readonly name: string;
|
|
43
|
+
static readonly INDEX_SIZE_ERR: 1;
|
|
44
|
+
static readonly DOMSTRING_SIZE_ERR: 2;
|
|
45
|
+
static readonly HIERARCHY_REQUEST_ERR: 3;
|
|
46
|
+
static readonly WRONG_DOCUMENT_ERR: 4;
|
|
47
|
+
static readonly INVALID_CHARACTER_ERR: 5;
|
|
48
|
+
static readonly NO_DATA_ALLOWED_ERR: 6;
|
|
49
|
+
static readonly NO_MODIFICATION_ALLOWED_ERR: 7;
|
|
50
|
+
static readonly NOT_FOUND_ERR: 8;
|
|
51
|
+
static readonly NOT_SUPPORTED_ERR: 9;
|
|
52
|
+
static readonly INUSE_ATTRIBUTE_ERR: 10;
|
|
53
|
+
static readonly INVALID_STATE_ERR: 11;
|
|
54
|
+
static readonly SYNTAX_ERR: 12;
|
|
55
|
+
static readonly INVALID_MODIFICATION_ERR: 13;
|
|
56
|
+
static readonly NAMESPACE_ERR: 14;
|
|
57
|
+
static readonly INVALID_ACCESS_ERR: 15;
|
|
58
|
+
static readonly VALIDATION_ERR: 16;
|
|
59
|
+
static readonly TYPE_MISMATCH_ERR: 17;
|
|
60
|
+
static readonly SECURITY_ERR: 18;
|
|
61
|
+
static readonly NETWORK_ERR: 19;
|
|
62
|
+
static readonly ABORT_ERR: 20;
|
|
63
|
+
static readonly URL_MISMATCH_ERR: 21;
|
|
64
|
+
static readonly QUOTA_EXCEEDED_ERR: 22;
|
|
65
|
+
static readonly TIMEOUT_ERR: 23;
|
|
66
|
+
static readonly INVALID_NODE_TYPE_ERR: 24;
|
|
67
|
+
static readonly DATA_CLONE_ERR: 25;
|
|
68
|
+
constructor(message?: string, name?: string);
|
|
69
|
+
/** Mirror static constants on the prototype (spec §3.1.2) */
|
|
70
|
+
get INDEX_SIZE_ERR(): number;
|
|
71
|
+
get DOMSTRING_SIZE_ERR(): number;
|
|
72
|
+
get HIERARCHY_REQUEST_ERR(): number;
|
|
73
|
+
get WRONG_DOCUMENT_ERR(): number;
|
|
74
|
+
get INVALID_CHARACTER_ERR(): number;
|
|
75
|
+
get NO_DATA_ALLOWED_ERR(): number;
|
|
76
|
+
get NO_MODIFICATION_ALLOWED_ERR(): number;
|
|
77
|
+
get NOT_FOUND_ERR(): number;
|
|
78
|
+
get NOT_SUPPORTED_ERR(): number;
|
|
79
|
+
get INUSE_ATTRIBUTE_ERR(): number;
|
|
80
|
+
get INVALID_STATE_ERR(): number;
|
|
81
|
+
get SYNTAX_ERR(): number;
|
|
82
|
+
get INVALID_MODIFICATION_ERR(): number;
|
|
83
|
+
get NAMESPACE_ERR(): number;
|
|
84
|
+
get INVALID_ACCESS_ERR(): number;
|
|
85
|
+
get VALIDATION_ERR(): number;
|
|
86
|
+
get TYPE_MISMATCH_ERR(): number;
|
|
87
|
+
get SECURITY_ERR(): number;
|
|
88
|
+
get NETWORK_ERR(): number;
|
|
89
|
+
get ABORT_ERR(): number;
|
|
90
|
+
get URL_MISMATCH_ERR(): number;
|
|
91
|
+
get QUOTA_EXCEEDED_ERR(): number;
|
|
92
|
+
get TIMEOUT_ERR(): number;
|
|
93
|
+
get INVALID_NODE_TYPE_ERR(): number;
|
|
94
|
+
get DATA_CLONE_ERR(): number;
|
|
95
|
+
/** Canonical string representation */
|
|
96
|
+
toString(): string;
|
|
97
|
+
}
|
|
98
|
+
export declare const DOMExceptionImpl: DOMExceptionConstructor;
|
|
99
|
+
export { DOM_EXCEPTION_CODES, DOM_EXCEPTION_NAMES, DOMExceptionImpl as DOMException, DOMExceptionPolyfill, };
|
|
100
|
+
//# sourceMappingURL=dom-exception.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-exception.d.ts","sourceRoot":"","sources":["../../../../src/lib/dom-exception.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,QAAA,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAuB/C,CAAC;AAEF,QAAA,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAE/C,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACtC,KAAK,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IACpD,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IAEjC,QAAQ,CAA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Event {
|
|
7
|
+
readonly type: string;
|
|
8
|
+
readonly bubbles: boolean;
|
|
9
|
+
readonly cancelable: boolean;
|
|
10
|
+
readonly composed: boolean;
|
|
11
|
+
target: EventTarget | null;
|
|
12
|
+
currentTarget: EventTarget | null;
|
|
13
|
+
defaultPrevented: boolean;
|
|
14
|
+
cancelBubble: boolean;
|
|
15
|
+
_stopImmediatePropagationFlag: boolean;
|
|
16
|
+
readonly timeStamp: number;
|
|
17
|
+
readonly isTrusted: boolean;
|
|
18
|
+
static readonly NONE = 0;
|
|
19
|
+
static readonly CAPTURING_PHASE = 1;
|
|
20
|
+
static readonly AT_TARGET = 2;
|
|
21
|
+
static readonly BUBBLING_PHASE = 3;
|
|
22
|
+
readonly NONE = 0;
|
|
23
|
+
readonly CAPTURING_PHASE = 1;
|
|
24
|
+
readonly AT_TARGET = 2;
|
|
25
|
+
readonly BUBBLING_PHASE = 3;
|
|
26
|
+
eventPhase: number;
|
|
27
|
+
constructor(type: string, options?: EventInit);
|
|
28
|
+
preventDefault(): void;
|
|
29
|
+
stopPropagation(): void;
|
|
30
|
+
stopImmediatePropagation(): void;
|
|
31
|
+
composedPath(): EventTarget[];
|
|
32
|
+
initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
|
|
33
|
+
}
|
|
34
|
+
type EventListener = (event: Event) => void;
|
|
35
|
+
interface EventListenerObject {
|
|
36
|
+
handleEvent(event: Event): void;
|
|
37
|
+
}
|
|
38
|
+
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
|
|
39
|
+
type ListenerOptions = {
|
|
40
|
+
once?: boolean;
|
|
41
|
+
capture?: boolean;
|
|
42
|
+
passive?: boolean;
|
|
43
|
+
} | boolean | undefined;
|
|
44
|
+
/** Make events dispatched on `child` also bubble to `parent`'s listeners. */
|
|
45
|
+
export declare function setEventParent(child: EventTarget, parent: EventTarget): void;
|
|
46
|
+
export declare class EventTarget {
|
|
47
|
+
constructor();
|
|
48
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: ListenerOptions): void;
|
|
49
|
+
dispatchEvent(event: Event): boolean;
|
|
50
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, _options?: ListenerOptions): void;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=event-target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-target.d.ts","sourceRoot":"","sources":["../../../../src/lib/event-target.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,KAAK;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B,MAAM,EAAE,WAAW,GAAG,IAAI,CAAQ;IAClC,aAAa,EAAE,WAAW,GAAG,IAAI,CAAQ;IAEzC,gBAAgB,EAAE,OAAO,CAAS;IAClC,YAAY,EAAE,OAAO,CAAS;IAC9B,6BAA6B,EAAE,OAAO,CAAS;IAE/C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAc;IACxC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAS;IAEpC,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK;IACzB,MAAM,CAAC,QAAQ,CAAC,eAAe,KAAK;IACpC,MAAM,CAAC,QAAQ,CAAC,SAAS,KAAK;IAC9B,MAAM,CAAC,QAAQ,CAAC,cAAc,KAAK;IAEnC,QAAQ,CAAC,IAAI,KAAK;IAClB,QAAQ,CAAC,eAAe,KAAK;IAC7B,QAAQ,CAAC,SAAS,KAAK;IACvB,QAAQ,CAAC,cAAc,KAAK;IAE5B,UAAU,EAA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
|
+
/**
|
|
7
|
+
* @returns An object containing a promise and its resolve/reject methods.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createDeferredPromise<T>(): DeferredPromise<T>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../../../src/lib/promise.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,CAAC,CAAC,IAAI;IACxB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;IAC7B,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,KAAK,eAAe,CAAC,CAAC,CAAC,CAS7D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Testing & on-device-demo entry point.
|
|
3
|
+
*
|
|
4
|
+
* Imported via the package subpath:
|
|
5
|
+
*
|
|
6
|
+
* import {VirtualSerialTransport, installSerialMock}
|
|
7
|
+
* from 'react-native-web-serial-api/testing';
|
|
8
|
+
*
|
|
9
|
+
* These are reusable building blocks for *consumers'* tests and demos — an
|
|
10
|
+
* in-memory transport and an authorable `SerialDevice` peripheral model — so
|
|
11
|
+
* they ship with the package. The library's own spec-compliance suite is NOT
|
|
12
|
+
* here: it lives in `src/__tests__/conformance-suite.ts` (test-only, excluded
|
|
13
|
+
* from the build and the published package). None of this is in the main bundle.
|
|
14
|
+
*/
|
|
15
|
+
export type { SerialTransport } from '../transport';
|
|
16
|
+
export { getUsbSerial, resetUsbSerial, setUsbSerial } from '../UsbSerial';
|
|
17
|
+
export type { InstallSerialMockOptions, SerialMockDevice } from './install';
|
|
18
|
+
export { installSerialMock } from './install';
|
|
19
|
+
export type { DeviceIdentity, SerialDeviceHost, SerialDeviceOpenOptions, SerialHostSignals, SerialInputSignals, } from './serial-device';
|
|
20
|
+
export { EchoDevice, LineDevice, SerialDevice, SilentDevice, } from './serial-device';
|
|
21
|
+
export type { FailableOp, VirtualDeviceOptions, VirtualSerialOptions, } from './virtual-serial';
|
|
22
|
+
export { VirtualDevice, VirtualSerialTransport } from './virtual-serial';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,YAAY,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAGlD,OAAO,EAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC;AACxE,YAAY,EAAC,wBAAwB,EAAE,gBAAgB,EAAC,MAAM,WAAW,CAAC;AAE1E,OAAO,EAAC,iBAAiB,EAAC,MAAM,WAAW,CAAC;AAC5C,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,UAAU,EACV,UAAU,EACV,YAAY,EACZ,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,UAAU,EACV,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAC,aAAa,EAAE,sBAAsB,EAAC,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SerialDevice } from './serial-device';
|
|
2
|
+
import type { VirtualDeviceOptions, VirtualSerialOptions } from './virtual-serial';
|
|
3
|
+
import { VirtualSerialTransport } from './virtual-serial';
|
|
4
|
+
/** A device to register: a SerialDevice, optionally with transport options. */
|
|
5
|
+
export type SerialMockDevice = SerialDevice | {
|
|
6
|
+
device: SerialDevice;
|
|
7
|
+
options?: VirtualDeviceOptions;
|
|
8
|
+
};
|
|
9
|
+
export type InstallSerialMockOptions = {
|
|
10
|
+
/** The simulated devices to expose. */
|
|
11
|
+
devices: SerialMockDevice[];
|
|
12
|
+
/** When false, no mock is installed and `null` is returned. Defaults to true. */
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
/** Transport-level options (latency, chunkSize, …). */
|
|
15
|
+
transport?: VirtualSerialOptions;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Build a {@link VirtualSerialTransport} from `devices` and install it globally
|
|
19
|
+
* via {@link setUsbSerial}. SerialDevices default to granted USB permission (so
|
|
20
|
+
* they show up immediately); pass the `{device, options}` form to override.
|
|
21
|
+
* Returns the transport (handy for driving devices in-test), or `null` when
|
|
22
|
+
* disabled.
|
|
23
|
+
*/
|
|
24
|
+
export declare function installSerialMock(options: InstallSerialMockOptions): VirtualSerialTransport | null;
|
|
25
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../../src/testing/install.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAC,sBAAsB,EAAC,MAAM,kBAAkB,CAAC;AAExD,+EAA+E;AAC/E,MAAM,MAAM,gBAAgB,GACxB,YAAY,GACZ;IAAC,MAAM,EAAE,YAAY,CAAC;IAAC,OAAO,CAAC,EAAE,oBAAoB,CAAA;CAAC,CAAC;AAE3D,MAAM,MAAM,wBAAwB,GAAG;IACrC,uCAAuC;IACvC,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,iFAAiF;IACjF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uDAAuD;IACvD,SAAS,CAAC,EAAE,oBAAoB,CAAC;CAClC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,wBAAwB,GAChC,sBAAsB,GAAG,IAAI,CAiB/B"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SerialDevice — author a complete simulated serial peripheral.
|
|
3
|
+
*
|
|
4
|
+
* Extend the class and override the lifecycle hooks to model a real device's
|
|
5
|
+
* whole behaviour (firmware/protocol): react to `open()`, to bytes the host
|
|
6
|
+
* writes, to control-signal changes, and stream data back over time. It is
|
|
7
|
+
* hosted by a {@link VirtualSerialTransport} ({@link ./virtual-serial}) and is
|
|
8
|
+
* free of any `react-native` dependency, so the same device runs under Jest,
|
|
9
|
+
* in a browser, and inside a React Native app on a device/emulator (for E2E).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* class Thermometer extends SerialDevice {
|
|
13
|
+
* usbVendorId = 0x0403;
|
|
14
|
+
* usbProductId = 0x6001;
|
|
15
|
+
* #timer?: ReturnType<typeof setInterval>;
|
|
16
|
+
* onOpen() {
|
|
17
|
+
* this.#timer = setInterval(() => this.send(`${20 + Math.random()}C\r\n`), 1000);
|
|
18
|
+
* }
|
|
19
|
+
* onData(bytes) { // host wrote a command
|
|
20
|
+
* if (String.fromCharCode(...bytes).trim() === 'ID?') this.send('ACME-TEMP\r\n');
|
|
21
|
+
* }
|
|
22
|
+
* onClose() { clearInterval(this.#timer); }
|
|
23
|
+
* }
|
|
24
|
+
* transport.addDevice(new Thermometer(), {hasPermission: true});
|
|
25
|
+
*/
|
|
26
|
+
import type { OpenOptions } from '../transport';
|
|
27
|
+
/** The negotiated connection parameters (native parity code: 0 none/1 odd/2 even). */
|
|
28
|
+
export type SerialDeviceOpenOptions = Required<OpenOptions>;
|
|
29
|
+
/** Device-asserted input signals — what the host reads via getSignals(). */
|
|
30
|
+
export type SerialInputSignals = {
|
|
31
|
+
dataCarrierDetect?: boolean;
|
|
32
|
+
clearToSend?: boolean;
|
|
33
|
+
ringIndicator?: boolean;
|
|
34
|
+
dataSetReady?: boolean;
|
|
35
|
+
};
|
|
36
|
+
/** Host-asserted output signals (DTR/RTS/break) the device observes. */
|
|
37
|
+
export type SerialHostSignals = {
|
|
38
|
+
dataTerminalReady: boolean;
|
|
39
|
+
requestToSend: boolean;
|
|
40
|
+
break: boolean;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The handle a {@link SerialDevice} uses to talk back to the host. Provided by
|
|
44
|
+
* the transport; you normally use the `protected` helpers on `SerialDevice`
|
|
45
|
+
* rather than this directly.
|
|
46
|
+
*/
|
|
47
|
+
export interface SerialDeviceHost {
|
|
48
|
+
readonly deviceId: number;
|
|
49
|
+
readonly portNumber: number;
|
|
50
|
+
readonly isOpen: boolean;
|
|
51
|
+
readonly openOptions: SerialDeviceOpenOptions | null;
|
|
52
|
+
send(bytes: number[]): void;
|
|
53
|
+
raiseError(message: string, name?: string): void;
|
|
54
|
+
setSignals(signals: SerialInputSignals): void;
|
|
55
|
+
}
|
|
56
|
+
/** Coerce a payload into a byte array (string → char codes, & 0xff). */
|
|
57
|
+
export declare function toBytes(data: number[] | Uint8Array | string): number[];
|
|
58
|
+
/**
|
|
59
|
+
* Base class for a simulated serial peripheral. Override the `on*` hooks you
|
|
60
|
+
* care about (all default to no-ops and may be async) and use the `protected`
|
|
61
|
+
* helpers to drive the host.
|
|
62
|
+
*/
|
|
63
|
+
export declare abstract class SerialDevice {
|
|
64
|
+
#private;
|
|
65
|
+
/** USB Vendor ID this device reports for enumeration. */
|
|
66
|
+
abstract readonly usbVendorId: number;
|
|
67
|
+
/** USB Product ID this device reports for enumeration. */
|
|
68
|
+
abstract readonly usbProductId: number;
|
|
69
|
+
/** Optional USB serial number. */
|
|
70
|
+
readonly serialNumber?: string;
|
|
71
|
+
/** @internal Bind the transport host (called by VirtualSerialTransport). */
|
|
72
|
+
_bind(host: SerialDeviceHost): void;
|
|
73
|
+
/** Send bytes to the host (they appear on `port.readable`). */
|
|
74
|
+
protected send(data: number[] | Uint8Array | string): void;
|
|
75
|
+
/**
|
|
76
|
+
* Raise a typed read error on the host's readable stream. `name` is the W3C
|
|
77
|
+
* error type, e.g. "BreakError", "BufferOverrunError", "FramingError",
|
|
78
|
+
* "ParityError" (defaults to "NetworkError").
|
|
79
|
+
*/
|
|
80
|
+
protected raiseError(message: string, name?: string): void;
|
|
81
|
+
/** Set device-asserted input signals (DCD/CTS/RI/DSR) the host can read. */
|
|
82
|
+
protected setSignals(signals: SerialInputSignals): void;
|
|
83
|
+
/** The parameters the host opened the port with, or null when closed. */
|
|
84
|
+
protected get openOptions(): SerialDeviceOpenOptions | null;
|
|
85
|
+
protected get deviceId(): number;
|
|
86
|
+
protected get portNumber(): number;
|
|
87
|
+
/** The host opened the port. */
|
|
88
|
+
onOpen(_options: SerialDeviceOpenOptions): void | Promise<void>;
|
|
89
|
+
/** The host wrote bytes to the device. */
|
|
90
|
+
onData(_data: Uint8Array): void | Promise<void>;
|
|
91
|
+
/** The host changed DTR/RTS/break. */
|
|
92
|
+
onHostSignals(_signals: SerialHostSignals): void | Promise<void>;
|
|
93
|
+
/** The host closed the port. */
|
|
94
|
+
onClose(): void | Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
/** Optional USB identity for the built-in devices. */
|
|
97
|
+
export type DeviceIdentity = {
|
|
98
|
+
usbVendorId?: number;
|
|
99
|
+
usbProductId?: number;
|
|
100
|
+
serialNumber?: string;
|
|
101
|
+
};
|
|
102
|
+
/** A loopback device: every byte written is echoed straight back. */
|
|
103
|
+
export declare class EchoDevice extends SerialDevice {
|
|
104
|
+
readonly usbVendorId: number;
|
|
105
|
+
readonly usbProductId: number;
|
|
106
|
+
readonly serialNumber?: string;
|
|
107
|
+
constructor(identity?: DeviceIdentity);
|
|
108
|
+
onData(data: Uint8Array): void;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Base for a line-oriented command/response device: buffers incoming bytes and
|
|
112
|
+
* calls {@link onLine} for each `\n`-terminated line (trailing CR/LF stripped).
|
|
113
|
+
*/
|
|
114
|
+
export declare abstract class LineDevice extends SerialDevice {
|
|
115
|
+
#private;
|
|
116
|
+
/** Handle one line received from the host. */
|
|
117
|
+
abstract onLine(line: string): void | Promise<void>;
|
|
118
|
+
onData(data: Uint8Array): void;
|
|
119
|
+
}
|
|
120
|
+
/** A device that accepts writes but never sends anything back. */
|
|
121
|
+
export declare class SilentDevice extends SerialDevice {
|
|
122
|
+
readonly usbVendorId: number;
|
|
123
|
+
readonly usbProductId: number;
|
|
124
|
+
readonly serialNumber?: string;
|
|
125
|
+
constructor(identity?: DeviceIdentity);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=serial-device.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serial-device.d.ts","sourceRoot":"","sources":["../../../../src/testing/serial-device.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAE9C,sFAAsF;AACtF,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;AAE5D,4EAA4E;AAC5E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,wEAAwE;AACxE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B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