Refactoring of websockets in controller.js