@@ -51,10 +51,7 @@ class EventSource {
51
51
this . _pollTimer = null ;
52
52
this . _lastIndexProcessed = 0 ;
53
53
54
- if (
55
- ! url ||
56
- ( typeof url !== 'string' && typeof url . toString !== 'function' )
57
- ) {
54
+ if ( ! url || ( typeof url !== 'string' && typeof url . toString !== 'function' ) ) {
58
55
throw new SyntaxError ( '[EventSource] Invalid URL argument.' ) ;
59
56
}
60
57
@@ -106,34 +103,23 @@ class EventSource {
106
103
107
104
const xhr = this . _xhr ;
108
105
109
- this . _logDebug (
110
- `[EventSource][onreadystatechange] ReadyState: ${ XMLReadyStateMap [ xhr . readyState ] || 'Unknown'
111
- } (${ xhr . readyState } ), status: ${ xhr . status } `
112
- ) ;
106
+ this . _logDebug ( `[EventSource][onreadystatechange] ReadyState: ${ XMLReadyStateMap [ xhr . readyState ] || 'Unknown' } (${ xhr . readyState } ), status: ${ xhr . status } ` ) ;
113
107
114
- if (
115
- ! [ XMLHttpRequest . DONE , XMLHttpRequest . LOADING ] . includes (
116
- xhr . readyState
117
- )
118
- ) {
108
+ if ( ! [ XMLHttpRequest . DONE , XMLHttpRequest . LOADING ] . includes ( xhr . readyState ) ) {
119
109
return ;
120
110
}
121
111
122
112
if ( xhr . status >= 200 && xhr . status < 400 ) {
123
113
if ( this . status === this . CONNECTING ) {
124
114
this . status = this . OPEN ;
125
115
this . dispatch ( 'open' , { type : 'open' } ) ;
126
- this . _logDebug (
127
- '[EventSource][onreadystatechange][OPEN] Connection opened.'
128
- ) ;
116
+ this . _logDebug ( '[EventSource][onreadystatechange][OPEN] Connection opened.' ) ;
129
117
}
130
118
131
119
this . _handleEvent ( xhr . responseText || '' ) ;
132
120
133
121
if ( xhr . readyState === XMLHttpRequest . DONE ) {
134
- this . _logDebug (
135
- '[EventSource][onreadystatechange][DONE] Operation done.'
136
- ) ;
122
+ this . _logDebug ( '[EventSource][onreadystatechange][DONE] Operation done.' ) ;
137
123
this . _pollAgain ( this . interval , false ) ;
138
124
}
139
125
} else if ( xhr . status !== 0 ) {
@@ -146,9 +132,7 @@ class EventSource {
146
132
} ) ;
147
133
148
134
if ( xhr . readyState === XMLHttpRequest . DONE ) {
149
- this . _logDebug (
150
- '[EventSource][onreadystatechange][ERROR] Response status error.'
151
- ) ;
135
+ this . _logDebug ( '[EventSource][onreadystatechange][ERROR] Response status error.' ) ;
152
136
this . _pollAgain ( this . interval , false ) ;
153
137
}
154
138
}
@@ -202,16 +186,10 @@ class EventSource {
202
186
if ( this . lineEndingCharacter === null ) {
203
187
const detectedNewlineChar = this . _detectNewlineChar ( response ) ;
204
188
if ( detectedNewlineChar !== null ) {
205
- this . _logDebug (
206
- `[EventSource] Automatically detected lineEndingCharacter: ${ JSON . stringify (
207
- detectedNewlineChar
208
- ) . slice ( 1 , - 1 ) } `
209
- ) ;
189
+ this . _logDebug ( `[EventSource] Automatically detected lineEndingCharacter: ${ JSON . stringify ( detectedNewlineChar ) . slice ( 1 , - 1 ) } ` ) ;
210
190
this . lineEndingCharacter = detectedNewlineChar ;
211
191
} else {
212
- console . warn (
213
- '[EventSource] Unable to identify the line ending character. Ensure your server delivers a standard line ending character: \\r\\n, \\n, \\r, or specify your custom character using the ' lineEndingCharacter ' option.'
214
- ) ;
192
+ console . warn ( "[EventSource] Unable to identify the line ending character. Ensure your server delivers a standard line ending character: \\r\\n, \\n, \\r, or specify your custom character using the 'lineEndingCharacter' option." ) ;
215
193
return ;
216
194
}
217
195
}
@@ -221,9 +199,7 @@ class EventSource {
221
199
return ;
222
200
}
223
201
224
- const parts = response
225
- . substring ( this . _lastIndexProcessed , indexOfDoubleNewline )
226
- . split ( this . lineEndingCharacter ) ;
202
+ const parts = response . substring ( this . _lastIndexProcessed , indexOfDoubleNewline ) . split ( this . lineEndingCharacter ) ;
227
203
228
204
this . _lastIndexProcessed = indexOfDoubleNewline ;
229
205
@@ -281,8 +257,7 @@ class EventSource {
281
257
}
282
258
283
259
_getLastDoubleNewlineIndex ( response ) {
284
- const doubleLineEndingCharacter =
285
- this . lineEndingCharacter + this . lineEndingCharacter ;
260
+ const doubleLineEndingCharacter = this . lineEndingCharacter + this . lineEndingCharacter ;
286
261
const lastIndex = response . lastIndexOf ( doubleLineEndingCharacter ) ;
287
262
if ( lastIndex === - 1 ) {
288
263
return - 1 ;
@@ -301,9 +276,7 @@ class EventSource {
301
276
302
277
removeEventListener ( type , listener ) {
303
278
if ( this . eventHandlers [ type ] !== undefined ) {
304
- this . eventHandlers [ type ] = this . eventHandlers [ type ] . filter (
305
- ( handler ) => handler !== listener
306
- ) ;
279
+ this . eventHandlers [ type ] = this . eventHandlers [ type ] . filter ( ( handler ) => handler !== listener ) ;
307
280
}
308
281
}
309
282
@@ -316,9 +289,7 @@ class EventSource {
316
289
}
317
290
} else {
318
291
if ( ! availableTypes . includes ( type ) ) {
319
- throw Error (
320
- `[EventSource] '${ type } ' type is not supported event type.`
321
- ) ;
292
+ throw Error ( `[EventSource] '${ type } ' type is not supported event type.` ) ;
322
293
}
323
294
324
295
this . eventHandlers [ type ] = [ ] ;
0 commit comments