Fix to only handle events once an empty line is present.
When events are sent as multipart messages onreadystatechange will be called multiple times. Since response.substr(this.lastIndexProcessed).split('\n') also return an empty string with only 1 newline, dispatch will also be called multiple time (e.g. "event: add\n data: 4\n".split('\n') will give [ "event: add", " data: 4", "" ]). This fix will check if indeed (a new) empty line is present before processing the event.
Fix to only handle events once an empty line is present.
When events are sent as multipart messages
onreadystatechange
will be called multiple times. Sinceresponse.substr(this.lastIndexProcessed).split('\n')
also return an empty string with only 1 newline, dispatch will also be called multiple time (e.g."event: add\n data: 4\n".split('\n')
will give[ "event: add", " data: 4", "" ]
). This fix will check if indeed (a new) empty line is present before processing the event.