Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Created May 7, 2022 12:59
var source = new EventSource("https://localhost/notifications");
var notification = document.getElementById("notification-count");
source.onmessage = event => {
const count = event.data;
if(notification){
notification.style.visibility = count > 0 ? "visible" : "hidden";
}
this.updateCount(count);
};
source.onerror = error => {
console.log("Notification error", error);
if(notification){
notification.style.visibility = "hidden";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment