File tree Expand file tree Collapse file tree 1 file changed +12
-15
lines changed Expand file tree Collapse file tree 1 file changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -111,35 +111,32 @@ function startServer() {
111111 }
112112 // binary message buffering
113113 function bufferUtf8 ( socket , timeout , maxSize ) {
114- const dataBuffer = new Uint8Array ( maxSize ) ;
115- let sender = null ;
114+ const chunks = [ ] ;
116115 let length = 0 ;
116+ let sender = null ;
117117 return ( data ) => {
118- function flush ( ) {
119- socket . send ( Buffer . from ( dataBuffer . buffer , 0 , length ) ) ;
118+ chunks . push ( data ) ;
119+ length += data . length ;
120+ if ( length > maxSize || userInput ) {
121+ userInput = false ;
122+ socket . send ( Buffer . concat ( chunks ) ) ;
123+ chunks . length = 0 ;
120124 length = 0 ;
121125 if ( sender ) {
122126 clearTimeout ( sender ) ;
123127 sender = null ;
124128 }
125- }
126- if ( length + data . length > maxSize ) {
127- flush ( ) ;
128- }
129- dataBuffer . set ( data , length ) ;
130- length += data . length ;
131- if ( length > maxSize || userInput ) {
132- userInput = false ;
133- flush ( ) ;
134129 } else if ( ! sender ) {
135130 sender = setTimeout ( ( ) => {
131+ socket . send ( Buffer . concat ( chunks ) ) ;
132+ chunks . length = 0 ;
133+ length = 0 ;
136134 sender = null ;
137- flush ( ) ;
138135 } , timeout ) ;
139136 }
140137 } ;
141138 }
142- const send = ( USE_BINARY ? bufferUtf8 : buffer ) ( ws , 5 , 262144 ) ;
139+ const send = ( USE_BINARY ? bufferUtf8 : buffer ) ( ws , 3 , 262144 ) ;
143140
144141 // WARNING: This is a naive implementation that will not throttle the flow of data. This means
145142 // it could flood the communication channel and make the terminal unresponsive. Learn more about
You can’t perform that action at this time.
0 commit comments