Refactored WebSocket.cs