I'm working on an app which uses the window.EventSource to stream data's on to a table view. Since there is a restriction on the max-connections-per-server limit as 6, i'm trying to have one EventSource object at a given point of time, so fundamentally i need to close the first eventsource object on the second one's onopen method and then the second one's onmessage event will stream the data to the table view. Consider the below code runs on an onclick event,
if(firstEventSource) {
firstEventSource.close();
}
var firstEventSource = new window.EventSource(endPoint);
firstEventSource.onmessage = function (evt) {
//... code goes here
}
The above code works but as i mentioned rather than closing the firstEventSource directly, i need to close it by making sure that the second Event source has opened it's connection.