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

Allow creation of Observable from EventSource (server-sent events): enhancement #1644

Closed
balteo opened this issue Apr 24, 2016 · 12 comments
Closed

Comments

@balteo
Copy link

balteo commented Apr 24, 2016

RxJS version: 5.0.0-beta.1

Additional information: This is a request for enhancement.

It would be nice to have an operator to create Observables from EventSources from server-sent events.

Is is planned for a future version of RxJS? If so in which version?

If that feature is already available, maybe a relevant section could be added to the documentation.

@balteo
Copy link
Author

balteo commented Apr 25, 2016

Where is the documenation for the "from" operator?

The following link: from-static-method just links to the top of the page...

@kwonoj
Copy link
Member

kwonoj commented Apr 25, 2016

@balteo Please consider documentation is not complete, still being evolved over time.

For fromEventSources I think it's yet migrated from https://github.com/Reactive-Extensions/RxJS-DOM/blob/master/doc/operators/fromeventsource.md, maybe considerable to place under dom as same as RxJS4.

@balteo
Copy link
Author

balteo commented Apr 25, 2016

Hi OJ Kwon,
Do you mean it is migrated or it is not yet migrated?
Can I use it?
Regards,
Julien.

2016-04-25 9:29 GMT+02:00 OJ Kwon notifications@github.com:

@balteo https://github.com/balteo Please consider documentation is not
complete, still being evolved over time.

For fromEventSources I think it's yet migrated from
https://github.com/Reactive-Extensions/RxJS-DOM/blob/master/doc/operators/fromeventsource.md,
maybe considerable to place under dom as same as RxJS4.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#1644 (comment)

@kwonoj
Copy link
Member

kwonoj commented Apr 25, 2016

yet migrated

: not yet, sorry for confusion.

@balteo
Copy link
Author

balteo commented Apr 25, 2016

No problems. I'll wait for it to be available. Any timeframe?

2016-04-25 9:38 GMT+02:00 OJ Kwon notifications@github.com:

yet migrated

: not yet, sorry for confusion.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#1644 (comment)

@zygimantas
Copy link

zygimantas commented Jun 24, 2016

I am also interested in seeing this ported to 5.0. Maybe @mattpodwysocki can help us here?

@matias-casal
Copy link

+1

@victornoel
Copy link

@zh99998 that's the whole point of the discussion: it is in the old (v4) rxjs but not in the new (v5).

@kwonoj do you think it's going to be implemented? :)

@mattbrunetti
Copy link

@mattpodwysocki Are PRs welcome for this?

@rgbkrk
Copy link
Contributor

rgbkrk commented Nov 27, 2017

I would think that a PR is welcome for this @mattbrunetti, go for it! If it doesn't get accepted, we can always make it a separate node package.

@benlesh
Copy link
Member

benlesh commented Aug 18, 2020

I don't think we want to support this in the core library right now. There are probably other implementations floating around in user land.

Basically, you'd need to do something like this:

function fromEventSource(url: string): Observable<MessageEvent> {
  return new Observable<MessageEvent>(subscriber => {
    const sse = new EventSource(url);
    
    sse.onmessage = e => subscriber.next(e);
    sse.onerror = e => subscriber.error(e);

   return () => {
     if (see.readyState === 1) {
        sse.close();
     }
   };
}

However, if you wanted to use the special handling EventSource has for events with an event property on them:

const sse = new EventSource(url);

fromEvent(sse, 'myeventhere').subscribe(console.log);

@benlesh benlesh closed this as completed Aug 18, 2020
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

9 participants