websocket-ts
websocket-ts copied to clipboard
feature/Allow async events add url mutation
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}`;
})