readyState 가 가드
OPEN 아닌 connection 에 ws.send() 부르면 InvalidStateError throw. 답은 'try/catch 로 감싸' 가 아니라 'readyState 먼저 확인하거나 open 까지 message queue 해'. readyState 를 '지금 send 가능?' 의 source of truth 로 봐.
네 개 값
0 CONNECTING — handshake 중. 1 OPEN — frame 흘러. 2 CLOSING — close handshake 시작. 3 CLOSED — terminal. WebSocket.OPEN static constant 쓰면 ws.readyState === WebSocket.OPEN 적을 수 있어, 매직 숫자 안 보고.