TWebSocketOptions
Bun

type

WebSocketOptions

Referenced types

type WebSocketOptionsProtocolsOrProtocol = { protocols: string | string[] } | { protocol: string }
type WebSocketOptionsTLS =
  • tls?: TLSOptions

    Options for the TLS connection.

    Supports full TLS configuration including custom CA certificates, client certificates, and other TLS settings (same as fetch).

    // Using BunFile for certificates
    const ws = new WebSocket("wss://example.com", {
      tls: {
        ca: Bun.file("./ca.pem")
      }
    });
    
    // Using Buffer
    const ws = new WebSocket("wss://example.com", {
      tls: {
        ca: fs.readFileSync("./ca.pem")
      }
    });
    
type WebSocketOptionsHeaders =
type WebSocketOptionsProxy =
  • proxy?: string | { headers: OutgoingHttpHeaders | Headers; url: string }

    HTTP proxy to use for the WebSocket connection.

    Can be a string URL or an object with url and optional headers.

    // String format
    const ws = new WebSocket("wss://example.com", {
      proxy: "http://proxy.example.com:8080"
    });
    
    // With credentials
    const ws = new WebSocket("wss://example.com", {
      proxy: "http://user:pass@proxy.example.com:8080"
    });
    
    // Object format with custom headers
    const ws = new WebSocket("wss://example.com", {
      proxy: {
        url: "http://proxy.example.com:8080",
        headers: {
          "Proxy-Authorization": "Bearer token"
        }
      }
    });