Js and chat server refactoring