Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventSourcePolyfill doesn't receive all data as postman #231

Open
hagerk720 opened this issue Jul 1, 2024 · 0 comments
Open

EventSourcePolyfill doesn't receive all data as postman #231

hagerk720 opened this issue Jul 1, 2024 · 0 comments

Comments

@hagerk720
Copy link

hagerk720 commented Jul 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant