EventSource
EventSource copied to clipboard
EventSourcePolyfill doesn't receive all data as postman
i have this problem with EventSourcePolyfill , when i create new notification it doesn't receive any thing but after some number of notifications it receive the previous notifications but also it get truncated
`import { EventSourcePolyfill } from 'event-source-polyfill';
@Injectable({ providedIn: 'root' })
getStream(): Observable
return new Observable((observer) => {
this.eventSource = new EventSourcePolyfill(this.streamUrl, {
headers: {
'Authorization': 'Bearer ' + this.authToken,
'organization-id': this.securityDTO.OrganizationId,
},
});
this.eventSource.onmessage = (event) => {
console.log(event);
observer.next(event.data);
};
this.eventSource.onerror = (error) => {
this.eventSource?.close();
this.reconnect(observer);
};
private reconnect(observer: any): void {
this.getStream().subscribe(observer);
}`
and this is how i call it
this.streamService.getStream().subscribe((data: any) => { const notification = JSON.parse(data); console.log(data); });