| 174 | |
| 175 | // Attach to a session |
| 176 | function attachToSession(id) { |
| 177 | const session = sessions.get(id); |
| 178 | if (!session || session.exited) return false; |
| 179 | |
| 180 | // Detach from current |
| 181 | if (currentSession) { |
| 182 | currentSession.sockets.delete(socket); |
| 183 | } |
| 184 | |
| 185 | currentSession = session; |
| 186 | session.sockets.add(socket); |
| 187 | socket.emit('attached', id); |
| 188 | return true; |
| 189 | } |
| 190 | |
| 191 | // Don't auto-attach — let client decide via 'attach' event |
| 192 | // Client picks its last session (or first) after receiving 'sessions' list |