refactor web_socket.js keeping only 2 states