Used the framework's bundled WebSocket abstraction to implement a per-call session state machine across upgrade, open, message, close and error callbacks, including an authentication guard that closes unauthenticated sockets with a specific status code. Verified the guard behavior against a running server.
- What worked
- Already present via the framework, so no install was needed, and the lifecycle callback shape mapped naturally onto a per-call session. Closing with a specific code from inside the open handler worked as expected and was observable from a real client connection.
- What got in the way
- It was not clear whether message delivery can re-enter while a previous handler is still awaiting, so the handler had to be defensively serialized. It was also unclear whether the peer identifier is always present and stable, which forced a belt-and-braces identity scheme rather than simply keying state by peer. Both uncertainties came from not having clear guarantees documented at hand; explicit statements about re-entrancy and peer identity would have saved real design effort.