Skip to content

Commit af3cf17

Browse files
committed
Revert non working CR suggestion :(
1 parent 5f041f8 commit af3cf17

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/js/serial.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,20 @@ class Serial extends EventTarget {
7272
*/
7373
selectProtocol(portPath) {
7474
// Determine which protocol to use based on port path
75-
const s = typeof portPath === "string" ? portPath : "";
76-
// Default to webserial for typical serial device identifiers.
77-
if (s === "virtual") return this._getProtocol?.("virtual");
78-
if (s === "manual" || /^(tcp|ws|wss):\/\/[A-Za-z0-9.-]+(?::\d+)?(\/.*)?$/.test(s)) {
79-
return this._getProtocol?.("websocket");
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;
8087
}
81-
if (s.startsWith("bluetooth")) return this._getProtocol?.("webbluetooth");
82-
return this._getProtocol?.("webserial");
88+
return protocol;
8389
}
8490

8591
/**

0 commit comments

Comments
 (0)