Part of ENG-10186 and overall improvement.
There are a couple of places in the codebase where we try to send a message and it could fail with Tunnelbroker not connected but only because using an outdated or not yet re-rendered version of sendMessage, for example:
- There is an asynchronous useCallback which is doing a lot of things, and after calls sendMessage, it starts its execution when Tunnelbroker is disconnected.
- During execution, a socket connection is established.
- In the callback mentioned above, sendMessage is called but it fails because it is bound to the old socketState even though the socket is connected. This diff fixes this.
Not sure if this isn't too hacky, curious about alternatives. We still want to keep the state to return it and allow adding it to dependency where needed.