Skip to content

UpgradeWebSocket

reference
1 min readUpdated

Kind: Interface

Source: src/helper/websocket/index.ts

Part of: Helper

Upgrade WebSocket Type

UpgradeWebSocket names the contract used by the WebSocket helper when an HTTP request is upgraded to a WebSocket connection. Code can accept or pass this interface without depending on a concrete upgrade implementation.

Diagram

mermaid
graph LR
  Request[HTTP Request] --> Upgrade[UpgradeWebSocket]
  Upgrade --> Connection[WebSocket Connection]
  Connection --> Handler[Application Handler]

Usage

ts
import type { UpgradeWebSocket } from './helper/websocket'

function registerUpgrade(
  upgrade: UpgradeWebSocket,
): UpgradeWebSocket {
  return upgrade
}

declare const platformUpgrade: UpgradeWebSocket

const upgrade = registerUpgrade(platformUpgrade)

AI Coding Instructions

  • Import UpgradeWebSocket with import type when it is only used for type checking.
  • Pass implementations through this interface instead of depending on platform-specific upgrade objects.
  • Do not assume members or behavior that are not declared by the interface.
  • Keep HTTP-to-WebSocket upgrade handling near the WebSocket helper integration.

Was this page helpful?

Download as PDF
UpgradeWebSocket — Hono (narrator proof)