Reputation: 373
I have a database containing users details, then listing them separately in a page. I am using the server sent event to call them. But each time i am initializing. Is it right to do so?
if (!!window.EventSource) {
var source = new EventSource("get_vacation_days.php");
} else {
alert("Your browser does not support Server-sent events! Please upgrade it!");
}
source.addEventListener("message", function(e) {
getVacationDays(e.data);
}, false);
source.addEventListener("open", function(e) {
console.log("Connection was opened.");
}, false);
source.addEventListener("error", function(e) {
console.log("Error: " );
console.log(e);
}, false);
And the next data:
if (!!window.EventSource) {
var source = new EventSource("get_days_in_company.php");
} else {
alert("Your browser does not support Server-sent events! Please upgrade it!");
}
source.addEventListener("message", function(e) {
getDaysInCompany(e.data);
}, false);
source.addEventListener("open", function(e) {
console.log("Connection was opened.");
}, false);
source.addEventListener("error", function(e) {
console.log("Error: " );
console.log(e);
}, false);
Upvotes: 0
Views: 1010
Reputation: 7066
You can have multiple EventSource, the only limitation is how hard you want to work your client's browser and how many open connections your infrastructure can handle.
Upvotes: 3