websocket-ts icon indicating copy to clipboard operation
websocket-ts copied to clipboard

feature/Allow async events add url mutation

Open hathamneh opened this issue 6 months ago • 0 comments

This PR adds two features:

  • allow modification url after the websocket is built. ex: ws.url = 'some_new_url'
  • allow async events handlers: ex:
   WebsocketBuilder.onRetry(async (ws, ev) => {
     await someAsynTask();
   })

The use case needed those is: We have a secured API that requires a temporary token per socket connection, so what is needed is to get a new token asynchronously then append it to the socket url:

   WebsocketBuilder.onRetry(async (ws, ev) => {
     const newToken = await someAsynTask();
     ws.url = `/myUrl?token=${newToken}`;
   })

hathamneh avatar Aug 23 '24 12:08 hathamneh