DoryDocs

WebSocket Playground

The <WebSocketPlayground> component embeds a fully interactive WebSocket client inside your documentation. Readers can open connections, send messages, and observe responses in real time.

Live Demo#

Connect to a public WebSocket echo server — it sends back whatever you send:

With Subprotocols#

Usage in MDX#

MDX

<WebSocketPlayground
  url="wss://api.example.com/ws"
  title="Real-time Events"
  description="Subscribe to live events from the API."
  subprotocols={["events-v1"]}
  headers={{
    "X-Client-Version": "2.0"
  }}
  authType="bearer"
  servers={[
    { url: "wss://api.example.com/ws", description: "Production" },
    { url: "wss://staging.api.example.com/ws", description: "Staging" }
  ]}
/>

Features#

Live Connection

Real WebSocket connection with connect/disconnect controls and live status indicator.

Message History

Timestamped message log with color-coded sent, received, error, and system messages.

Subprotocols

Configure and negotiate WebSocket subprotocols.

Authentication

Supports Bearer token, API key, Basic auth, and custom headers.

Multiple Servers

Switch between server environments (production, staging, local).

Custom Headers

Add custom headers to the WebSocket handshake request.

Message Types#

Messages in the log are color-coded:

TypeColorDescription
SENDOrangeMessages you send to the server
RECVBlueMessages received from the server
ERRRedConnection errors and protocol errors
SYSMutedConnect, disconnect, and status events

Testing JSON APIs#

For WebSocket APIs that use JSON messages, send structured messages like:

JSON

{ "type": "subscribe", "channel": "updates" }

JSON

{ "type": "message", "content": "Hello!", "room": "general" }

Props Reference#

PropTypeRequiredDescription
urlstringYesWebSocket URL (ws:// or wss://).
titlestringNoDisplay title.
descriptionstringNoDescription shown above the playground.
subprotocolsstring[]NoPre-configured WebSocket subprotocols.
headersRecord<string, string>NoPre-populated handshake headers.
authType'bearer' | 'apiKey' | 'basic' | 'none'NoAuthentication method.
serversArray<{ url, description, protocol? }>NoServer environment options.

Was this page helpful?