File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff 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" || / ^ ( t c p | w s | w s s ) : \/ \/ [ A - Z a - z 0 - 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" || / ^ ( 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 ;
8087 }
81- if ( s . startsWith ( "bluetooth" ) ) return this . _getProtocol ?. ( "webbluetooth" ) ;
82- return this . _getProtocol ?. ( "webserial" ) ;
88+ return protocol ;
8389 }
8490
8591 /**
You can’t perform that action at this time.
0 commit comments