centrifugal / centrifuge-swift

Swift client SDK for bidirectional real-time communication with Centrifugo and Centrifuge-based server over WebSocket
MIT License
49 stars 44 forks source link

Feature/allow headers update #100

Open shalom-aviv opened 7 months ago

shalom-aviv commented 7 months ago

Example of changes for https://github.com/centrifugal/centrifuge-swift/issues/99

FZambia commented 7 months ago

Hello @shalom-aviv

Thanks for opening PR and investigating the solution.

Could you please show how you are planning to use this in real code? What will be a trigger for headers update in practice? I generally understand the need in updating headers dynamically, but I am not sure yet what is the best approach for this. So some real-life code could help me to understand.

shalom-aviv commented 7 months ago

Hello @shalom-aviv

Thanks for opening PR and investigating the solution.

Could you please show how you are planning to use this in real code? What will be a trigger for headers update in practice? I generally understand the need in updating headers dynamically, but I am not sure yet what is the best approach for this. So some real-life code could help me to understand.

In my case, obtaining a new token can be done synchronously, so the changes in the this pull request were sufficient. Overall, I wanted to assess the feasibility and scope of changes required for parameter updates.

In a real scenario, obtaining a new token would be asynchronous. I've looked into how you handle JWT token updates and I think adding the ability to update connection settings in a similar manner would be a natural fit.

To be able to determine .upgradeError and obtain the actual status code from the server, I had to make WSError public, but this only applies to StarscreamWebSocket.

Check changes here: https://github.com/shalom-aviv/centrifuge-swift/pull/1