File tree Expand file tree Collapse file tree 6 files changed +58
-29
lines changed
Expand file tree Collapse file tree 6 files changed +58
-29
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " electerm-web" ,
3- "version" : " 3.3.85 " ,
3+ "version" : " 3.3.100 " ,
44 "description" : " Running electerm in as web app" ,
55 "main" : " src/app/app.js" ,
66 "type" : " module" ,
4747 "preferGlobal" : true ,
4848 "devDependencies" : {
4949 "@ant-design/icons" : " 5.6.1" ,
50- "@electerm/electerm-react" : " 2.3.85 " ,
50+ "@electerm/electerm-react" : " 2.3.100 " ,
5151 "@electerm/electerm-resource" : " 1.3.7" ,
5252 "@electerm/strip-ansi" : " ^1.0.0" ,
5353 "@fontsource/maple-mono" : " ^5.2.5" ,
Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ export function wsRoutes (app) {
3838 const term = terminals ( req . params . pid )
3939 const { pid } = term
4040 log . debug ( 'ws: connected to terminal ->' , pid )
41-
41+ const dataBuffer = [ ]
42+ let sendTimeout = null
4243 term . on ( 'data' , function ( data ) {
4344 try {
4445 if ( term . sessionLogger ) {
@@ -47,9 +48,25 @@ export function wsRoutes (app) {
4748 : ''
4849 term . sessionLogger . write ( `${ dt } ${ strip ( data . toString ( ) ) } ` )
4950 }
50- ws . send ( Buffer . from ( data ) )
51+
52+ // Buffer incoming data instead of sending immediately
53+ dataBuffer . push ( data )
54+
55+ // If no timeout is pending, schedule a batched send
56+ if ( ! sendTimeout ) {
57+ sendTimeout = setTimeout ( ( ) => {
58+ // Combine buffered data (optional: limit size to avoid memory issues)
59+ const combinedData = dataBuffer . splice ( 0 ) . join ( '' )
60+
61+ // Send to WebSocket
62+ ws . send ( combinedData )
63+
64+ // Reset timeout
65+ sendTimeout = null
66+ } , 10 ) // Small delay (10ms) to throttle; adjust based on testing
67+ }
5168 } catch ( ex ) {
52- console . log ( 'kkk' , ex )
69+ console . log ( ex )
5370 // The WebSocket is not open, ignore
5471 }
5572 } )
Original file line number Diff line number Diff line change 33 */
44import pty from 'node-pty'
55import { resolve as pathResolve } from 'path'
6- import log from '../common/log.js'
76import globalState from './global-state.js'
87import { TerminalBase } from './session-base.js'
98
@@ -56,14 +55,7 @@ class TerminalLocal extends TerminalBase {
5655 }
5756
5857 write ( data ) {
59- try {
60- this . term . write ( data )
61- if ( this . sessionLogger ) {
62- this . sessionLogger . write ( data )
63- }
64- } catch ( e ) {
65- log . error ( e )
66- }
58+ this . term . write ( data )
6759 }
6860
6961 kill ( ) {
Original file line number Diff line number Diff line change @@ -725,12 +725,7 @@ class TerminalSshBase extends TerminalBase {
725725 }
726726
727727 write ( data ) {
728- try {
729- this . channel . write ( data )
730- // this.writeLog(data)
731- } catch ( e ) {
732- log . error ( e )
733- }
728+ this . channel . write ( data )
734729 }
735730
736731 kill ( ) {
Original file line number Diff line number Diff line change @@ -7,6 +7,24 @@ import { Telnet } from './telnet.js'
77import { TerminalBase } from './session-base.js'
88import globalState from './global-state.js'
99
10+ // Helper function to convert regex string to RegExp object
11+ function stringToRegExp ( regexString ) {
12+ // Check if it's already a RegExp
13+ if ( regexString instanceof RegExp ) {
14+ return regexString
15+ }
16+
17+ // Parse string format like /pattern/flags
18+ const match = regexString . match ( / ^ \/ ( .+ ) \/ ( [ g i m s u y ] * ) $ / )
19+ if ( match ) {
20+ const [ , pattern , flags ] = match
21+ return new RegExp ( pattern , flags )
22+ }
23+
24+ // If no slashes, treat as plain pattern
25+ return new RegExp ( regexString )
26+ }
27+
1028class TerminalTelnet extends TerminalBase {
1129 async init ( ) {
1230 const connection = new Telnet ( )
@@ -27,6 +45,13 @@ class TerminalTelnet extends TerminalBase {
2745 'terminalHeight'
2846 ]
2947 )
48+ // Convert string regex patterns to RegExp objects
49+ if ( typeof initOptions . loginPrompt === 'string' ) {
50+ params . loginPrompt = stringToRegExp ( initOptions . loginPrompt )
51+ }
52+ if ( typeof initOptions . passwordPrompt === 'string' ) {
53+ params . passwordPrompt = stringToRegExp ( initOptions . passwordPrompt )
54+ }
3055 Object . assign (
3156 params ,
3257 {
You can’t perform that action at this time.
0 commit comments