refactor socket event listener