File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change
1
+ const XMLReadyStateMap = [
2
+ 'UNSENT' ,
3
+ 'OPENED' ,
4
+ 'HEADERS_RECEIVED' ,
5
+ 'LOADING' ,
6
+ 'DONE' ,
7
+ ] ;
8
+
1
9
class EventSource {
2
10
ERROR = - 1 ;
3
11
CONNECTING = 0 ;
@@ -86,7 +94,7 @@ class EventSource {
86
94
87
95
const xhr = this . _xhr ;
88
96
89
- this . _logDebug ( `[EventSource][onreadystatechange] ReadyState: ${ xhr . readyState } , status: ${ xhr . status } ` ) ;
97
+ this . _logDebug ( `[EventSource][onreadystatechange] ReadyState: ${ XMLReadyStateMap [ xhr . readyState ] || 'Unknown' } ( ${ xhr . readyState } ) , status: ${ xhr . status } ` ) ;
90
98
91
99
if ( ! [ XMLHttpRequest . DONE , XMLHttpRequest . LOADING ] . includes ( xhr . readyState ) ) {
92
100
return ;
@@ -96,6 +104,7 @@ class EventSource {
96
104
if ( this . status === this . CONNECTING ) {
97
105
this . status = this . OPEN ;
98
106
this . dispatch ( 'open' , { type : 'open' } ) ;
107
+ this . _logDebug ( '[EventSource][onreadystatechange][OPEN] Connection opened.' ) ;
99
108
}
100
109
101
110
this . _handleEvent ( xhr . responseText || '' ) ;
@@ -166,10 +175,12 @@ class EventSource {
166
175
167
176
_handleEvent ( response ) {
168
177
const parts = response . substr ( this . lastIndexProcessed ) . split ( '\n' ) ;
169
- let indexOfDoubleNewline = response . lastIndexOf ( '\n\n' ) ;
178
+
179
+ const indexOfDoubleNewline = response . lastIndexOf ( '\n\n' ) ;
170
180
if ( indexOfDoubleNewline != - 1 ) {
171
181
this . lastIndexProcessed = indexOfDoubleNewline + 2 ;
172
182
}
183
+
173
184
let data = [ ] ;
174
185
let retry = 0 ;
175
186
let line = '' ;
You can’t perform that action at this time.
0 commit comments