I am using HTML5 Server-Sent events:
SSEUpdate = new EventSource("update.php");
I want to detect when SSEUpdate.readyState
changes. I've tried .onerror
, but when I use console.log(SSEUpdate.readyState)
, I always get 0
. I want to run my function when readyState
changes to 2
.
I ended up using a polling solution:
var SSECheck = setInterval(function() {
if (SSEUpdate.readyState == 2) {
clearInterval(SSECheck);
// call to fn to restart sse
}
}, 500);
Takes up to 0.5s to capture, but it does the job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With