File tree Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Original file line number Diff line number Diff 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" || / ^ ( t c p | w s ) : \/ \/ ( [ A - Z a - z 0 - 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" || / ^ ( t c p | w s | w s s ) : \/ \/ [ A - Z a - z 0 - 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 /**
You can’t perform that action at this time.
0 commit comments