Skip to content

WSReadyState

reference
1 min readUpdated

Kind: Type

Source: src/helper/websocket/index.ts

Part of: Helper

ReadyState for WebSocket

WSReadyState represents the current readiness state of a WebSocket connection. It is used by the WebSocket helper to expose connection status to calling code, such as UI state or message-handling logic.

Definition

ts
0 | 1 | 2 | 3

Diagram

mermaid
graph LR
  Client[Application code] --> Helper[WebSocket helper]
  Helper --> Socket[WebSocket connection]
  Socket --> State[WSReadyState]
  State --> Client

Usage

ts
import type { WSReadyState } from './helper/websocket';

function handleReadyState(state: WSReadyState) {
  console.log('WebSocket ready state:', state);
}

const state: WSReadyState = websocket.readyState;

handleReadyState(state);

AI Coding Instructions

  • Treat WSReadyState as the status contract between the WebSocket helper and its callers.
  • Keep state checks aligned with the native WebSocket.readyState value returned by the active socket.
  • Update consumers when changing the type so UI and connection logic handle every supported state.
  • Do not assume a socket is ready to send messages without checking its current ready state.

Was this page helpful?

Download as PDF
WSReadyState — Hono (narrator proof)