I am using some EventSource in a service in my APP.
I would like to close all the connection when the browser is closed/refreshed.
I have seen this post
Right now, this is what I added to my service.
@HostListener('window:beforeunload')
onBrowserClose() {
this.clearAll();
}
clearAll() {
if (this.eventSource) {
this.eventSource.close();
}
this.callbacks = new Map<string, (e: any) => void>();
}
is there a better solution ?