The ws:// or wss:// endpoint to dial.
Optional subprotocols and extra request headers.
The connected WsConnection.
import { connect } from 'edgeport/ws';
const ws = await connect('wss://echo.example.com', { protocols: ['chat'] });
ws.send('ping');
for await (const msg of ws) {
if (msg.type === 'text') console.log('reply:', msg.data);
break;
}
ws.close(1000, 'done');
const { code } = await ws.closed;
console.log('closed with', code);
Opens a WebSocket connection from a Cloudflare Worker.
Performs the outbound client handshake with a
fetchupgrade (the runtime handles the wss TLS, RFC 6455 framing, and client masking), accepts the returned socket, then yields a WsConnection you async-iterate for inbound messages. Offered subprotocols are sent as a comma-joinedSec-WebSocket-Protocolheader; anyopts.headersare merged in.