Yaffle / EventSource

a polyfill for http://www.w3.org/TR/eventsource/
MIT License
2.11k stars 338 forks source link

EventSourcePolyfill doesn't receive all data as postman #231

Open hagerk720 opened 2 months ago

hagerk720 commented 2 months ago

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); });