Skip to content

Commit 5a12ac3

Browse files
authored
add comments about server/client weirdness
1 parent ae622eb commit 5a12ac3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/content/docs/workers/examples/websockets.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ async function handleRequest(request) {
9494
}
9595

9696
const webSocketPair = new WebSocketPair();
97-
const client = webSocketPair[0],
98-
server = webSocketPair[1];
97+
const client = webSocketPair[0], // server-side WS endpoint in the worker
98+
server = webSocketPair[1]; // this is the remote from whoever connected to your worker-a browser client for example
9999

100100
return new Response(null, {
101101
status: 101,
@@ -118,8 +118,8 @@ async fn fetch(req: HttpRequest, _env: Env, _ctx: Context) -> Result<worker::Res
118118
}
119119

120120
let ws = WebSocketPair::new()?;
121-
let client = ws.client;
122-
let server = ws.server;
121+
let client = ws.client; // server-side WS endpoint in the worker
122+
let server = ws.server; // this is the remote from whoever connected to your worker-a browser client for example
123123
server.accept()?;
124124

125125
worker::Response::from_websocket(client)
@@ -300,4 +300,4 @@ async function websocket(url) {
300300

301301
## WebSocket compression
302302

303-
Cloudflare Workers supports WebSocket compression. Refer to [WebSocket Compression](/workers/configuration/compatibility-flags/#websocket-compression) for more information.
303+
Cloudflare Workers supports WebSocket compression. Refer to [WebSocket Compression](/workers/configuration/compatibility-flags/#websocket-compression) for more information.

0 commit comments

Comments
 (0)