marcospds / ngx-sse-client

An SSE (server sent event) client alternative solution for Angular
MIT License
22 stars 3 forks source link

Support HttpContext as SseRequestOptions #4

Closed JayAhn2 closed 1 year ago

JayAhn2 commented 1 year ago

Hi.

I need to put HttpContext as SseRequestOptions, but the interface doesn't support it.

Can you allow to put httpContext as an option?

    this._sseClient
      .stream(
        'api/sse/connect',
        {
          keepAlive: true,
          reconnectionDelay: 1_000,
          responseType: 'event',
        },
        {
          context: new HttpContext().set(NGX_LOADING_BAR_IGNORED, true),
        } as any, // here!
        'GET'
      )
      .subscribe(event => {
        if (event.type === 'error') {
          const errorEvent = event as ErrorEvent;
          console.error(errorEvent.error, errorEvent.message);
        } else {
          const messageEvent = event as MessageEvent;
          console.info(
            `SSE request with type "${messageEvent.type}" and data "${messageEvent.data}"`
          );
        }
      });
rubinhos commented 1 year ago

Hey @JayAhn2 , thank you for your input. Unfortunately it's been a while since I am not working with Angular, but I will include your request I soon as I can. If you are comfortable, feel free to create a PR I will be glad to take a look.

rubinhos commented 1 year ago

Hey @JayAhn2 , I am happy to tell you that I just release the v3.0.0. This version has the official support for Angular >=v12 and also supports the context attribute on the HTTP request options.