Refactor socket.ts