@@ -63,33 +63,35 @@ class WebSocket extends Transport {
63
63
* @api private
64
64
*/
65
65
send ( packets ) {
66
- for ( let i = 0 ; i < packets . length ; i ++ ) {
67
- const packet = packets [ i ] ;
66
+ const packet = packets . shift ( ) ;
67
+ if ( typeof packet === "undefined" ) {
68
+ this . writable = true ;
69
+ this . emit ( "drain" ) ;
70
+ return ;
71
+ }
68
72
69
- // always creates a new object since ws modifies it
70
- const opts = { } ;
71
- if ( packet . options ) {
72
- opts . compress = packet . options . compress ;
73
- }
73
+ // always creates a new object since ws modifies it
74
+ const opts = { } ;
75
+ if ( packet . options ) {
76
+ opts . compress = packet . options . compress ;
77
+ }
74
78
75
- this . parser . encodePacket ( packet , this . supportsBinary , data => {
76
- if ( this . perMessageDeflate ) {
77
- const len =
78
- "string" === typeof data ? Buffer . byteLength ( data ) : data . length ;
79
- if ( len < this . perMessageDeflate . threshold ) {
80
- opts . compress = false ;
81
- }
79
+ this . parser . encodePacket ( packet , this . supportsBinary , data => {
80
+ if ( this . perMessageDeflate ) {
81
+ const len =
82
+ "string" === typeof data ? Buffer . byteLength ( data ) : data . length ;
83
+ if ( len < this . perMessageDeflate . threshold ) {
84
+ opts . compress = false ;
82
85
}
83
- debug ( 'writing "%s"' , data ) ;
84
- this . writable = false ;
86
+ }
87
+ debug ( 'writing "%s"' , data ) ;
88
+ this . writable = false ;
85
89
86
- this . socket . send ( data , opts , err => {
87
- if ( err ) return this . onError ( "write error" , err . stack ) ;
88
- this . writable = true ;
89
- this . emit ( "drain" ) ;
90
- } ) ;
90
+ this . socket . send ( data , opts , err => {
91
+ if ( err ) return this . onError ( "write error" , err . stack ) ;
92
+ this . send ( packets ) ;
91
93
} ) ;
92
- }
94
+ } ) ;
93
95
}
94
96
95
97
/**
0 commit comments