How to intercept Websockets, Server Sent Events (SSE) and ReadableStream Request and Response in Angular?

306 views Asked by At

I want stream real time data from server to client. We are using Angular 16. I want to intercept the Request and Response of WebSockets, Server Sent Events (SSE) and ReadableStream using Angular Interceptor. Is any one implemented?

Does any one used Angular HttpClientModule and Http interceptor in following HTML5 API's SSE API, WebSockets or Fetch API. I want to stream the real time data from server to client. I implemented one fetch API in the project but that request is not happening through Angular Interceptor. Because Http client module not having the fetch Method. Is anyone extend or override the Angular Client module or Http interceptor?

1

There are 1 answers

0
enno.void On

There is no way to intercept Websockets or Server Send Events with HttpInterceptors. I think you have to implement something by yourself.

  1. For SSE you can create a custom wrapper of EventSource that fit your needs.

  2. For intercepting Websocket send and received messages, i think the only way is to monkey-patch the Websocket-Class