Constructor options for the Bun.WebSocket client
type
WebSocketOptions
type WebSocketOptions = WebSocketOptionsProtocolsOrProtocol & WebSocketOptionsTLS & WebSocketOptionsHeaders & WebSocketOptionsProxy
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
urland optionalheaders.// 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" } } });