Skip to content

Commit c75c3c8

Browse files
committed
CR review II
1 parent 99b2ceb commit c75c3c8

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/js/serial.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,14 @@ class Serial extends EventTarget {
7272
*/
7373
selectProtocol(portPath) {
7474
// Determine which protocol to use based on port path
75-
let protocol;
76-
77-
// Select protocol based on port path. Default to webSerial for
78-
// typical serial device identifiers (e.g., COM1, /dev/ttyUSB0).
79-
if (portPath === "virtual") {
80-
protocol = this._protocols.find((p) => p.name === "virtual")?.instance;
81-
} else if (portPath === "manual" || /^(tcp|ws):\/\/([A-Za-z0-9.-]+)(?::(\d+))?$/.test(portPath)) {
82-
protocol = this._protocols.find((p) => p.name === "websocket")?.instance;
83-
} else if (portPath.startsWith("bluetooth")) {
84-
protocol = this._protocols.find((p) => p.name === "webbluetooth")?.instance;
85-
} else {
86-
protocol = this._protocols.find((p) => p.name === "webserial")?.instance;
75+
const s = typeof portPath === "string" ? portPath : "";
76+
// Default to webserial for typical serial device identifiers.
77+
if (s === "virtual") return this._protocols.find((p) => p.name === "virtual")?.instance;
78+
if (s === "manual" || /^(tcp|ws|wss):\/\/[A-Za-z0-9.-]+(?::\d+)?(\/.*)?$/.test(s)) {
79+
return this._protocols.find((p) => p.name === "websocket")?.instance;
8780
}
88-
return protocol;
81+
if (s.startsWith("bluetooth")) return this._protocols.find((p) => p.name === "webbluetooth")?.instance;
82+
return this._protocols.find((p) => p.name === "webserial")?.instance;
8983
}
9084

9185
/**

0 commit comments

Comments
 (0)