0

Tried following the article below to read eventstreams. Instead of using formData like it is done in the article, I'm using Json to post. It works smoothly with a 200 response. Even tells that some kb of data was sent over the wire, but the eventstream tab shows nothing. The same curl works on my terminal.

https://medium.com/swlh/how-do-server-sent-events-sse-or-eventsource-work-in-angular-e9e27b6a3295

Network call of the stream

EventStream tab in the network call

Shyam
  • 114
  • 5
  • did you correctly subscribe to it in js, also did you put correct stream headers on BE side and events are of correct format? – Andrei Apr 15 '21 at 23:36
  • @Andrei I tried doing it using fetch, similar response, but using its curl seems to work fine on the terminal. – Shyam Apr 18 '21 at 09:35

1 Answers1

0

As shown in the article

    return Observable.create((observer) => {
      const eventSource = this.sseService.getEventSourceWithPost(url, data);
      // Launch query
      eventSource.stream();
      // on answer from message listener 
      eventSource.onmessage = (event) => {
        this.zone.run(() => {
          observer.next(event.progress);
        });
      };
      eventSource.onerror = (error) => {
        this.zone.run(() => {
          observer.error(error);
        });
      };
    });

Changing this part to

    return Observable.create((observer) => {
      const eventSource = this.sseService.getEventSourceWithPost(url, data);
      // Launch query
      eventSource.stream();
      // on answer from message listener 
      eventSource.addEventListener('EVENT_NAME_FROM_STREAM', (event) => {
        this.zone.run(() => {
          observer.next(event.data);
        });
      };
    });

Got the data to show up. But in the network tab I still don't see the events.

Shyam
  • 114
  • 5