Skip to content

Commit 6cd02c7

Browse files
joshthowardOxyjun
andauthored
Refactor Durable Objects WebSocket documentation (#18344)
* Fix typo * Update order and lint files * Refactor Durable Objects WebSocket documentation * Fixing bad Prettier automation in <code> blocks. * Removing <br> and using MDX syntax. * Update src/content/docs/durable-objects/api/alarms.mdx Co-authored-by: Jun Lee <[email protected]> * Apply suggestions from code review Co-authored-by: Jun Lee <[email protected]> * Fixing broken links to deleted chapters. Adding public redirect. * Fixing broken links part 2 --------- Co-authored-by: Jun Lee <[email protected]>
1 parent 9231e61 commit 6cd02c7

File tree

18 files changed

+502
-332
lines changed

18 files changed

+502
-332
lines changed

public/_redirects

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,17 @@
358358
/support/dns/troubleshooting/why-was-my-domain-deleted-from-cloudflare/ /dns/zone-setups/troubleshooting/domain-deleted/ 301
359359

360360
/durable-objects/examples/durable-object-example/ /durable-objects/examples/durable-object-in-memory-state/ 301
361-
/durable-objects/api/hibernatable-websockets-api/ /durable-objects/api/websockets/ 301
361+
/durable-objects/api/hibernatable-websockets-api/ /durable-objects/best-practices/websockets/ 301
362362
/durable-objects/api/alarms-in-durable-objects/ /durable-objects/api/alarms/ 301
363+
/durable-objects/api/websockets/ /durable-objects/best-practices/websockets/ 301
363364
/durable-objects/platform/data-location/ /durable-objects/reference/data-location/ 301
364365
/durable-objects/platform/environments/ /durable-objects/reference/environments/ 301
365366
/durable-objects/platform/graphql-analytics/ /durable-objects/observability/graphql-analytics/ 301
366367
/durable-objects/platform/troubleshooting/ /durable-objects/observability/troubleshooting/ 301
367368
/durable-objects/learning/ /durable-objects/reference/ 301
368369
/durable-objects/learning/in-memory-state/ /durable-objects/reference/in-memory-state/ 301
369370
/durable-objects/learning/durable-objects-migrations/ /durable-objects/reference/durable-objects-migrations/ 301
370-
/durable-objects/learning/websockets/ /durable-objects/reference/websockets/ 301
371+
/durable-objects/learning/websockets/ /durable-objects/best-practices/websockets/ 301
371372
/durable-objects/examples/durable-object-location-example/ /durable-objects/examples/durable-object-in-memory-state/ 301
372373
/durable-objects/how-to/ /durable-objects/best-practices/ 301
373374
/durable-objects/how-to/access-durable-object-from-a-worker/ /durable-objects/best-practices/access-durable-objects-from-a-worker/ 301
@@ -377,6 +378,7 @@
377378
/durable-objects/reference/error-handling/ /durable-objects/best-practices/error-handling/ 301
378379
/durable-objects/reference/troubleshooting/ /durable-objects/observability/troubleshooting/ 301
379380
/durable-objects/reference/graphql-analytics/ /durable-objects/observability/graphql-analytics/ 301
381+
/durable-objects/reference/websockets/ /durable-objects/best-practices/websockets/ 301
380382
/durable-objects/api/transactional-storage-api/ /durable-objects/api/storage-api/ 301
381383
/durable-objects/platform/changelog/ /durable-objects/changelog/ 301
382384
/durable-objects/glossary/ /durable-objects/reference/glossary/ 301

src/content/changelogs/workers.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ entries:
190190
- Added the [`strict_compression_checks`](/workers/configuration/compatibility-flags/#strict-compression-error-checking) compatibility flag for additional [`DecompressionStream`](/workers/runtime-apis/web-standards/#compression-streams) error checking.
191191
- publish_date: "2023-05-26"
192192
description: |-
193-
- A new [Hibernatable WebSockets API](/durable-objects/api/websockets/)
193+
- A new [Hibernatable WebSockets API](/durable-objects/best-practices/websockets/)
194194
(beta) has been added to [Durable Objects](/durable-objects/). The Hibernatable
195195
WebSockets API allows a Durable Object that is not currently running an event
196196
handler (for example, processing a WebSocket message or alarm) to be removed from

src/content/docs/durable-objects/api/state.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ export class MyDurableObject extends DurableObject {
106106

107107
### `acceptWebSocket`
108108

109-
`acceptWebSocket` is part of the [WebSocket Hibernation API](/durable-objects/reference/websockets/#websocket-hibernation), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
109+
`acceptWebSocket` is part of the [WebSocket Hibernation API](/durable-objects/best-practices/websockets/#websocket-hibernation-api), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
110110

111111
`acceptWebSocket` adds a WebSocket to the set of WebSockets attached to the Durable Object. Once called, any incoming messages will be delivered by calling the Durable Object's `webSocketMessage` handler, and `webSocketClose` will be invoked upon disconnect. After calling `acceptWebSocket`, the WebSocket is accepted and its `send` and `close` methods can be used.
112112

113-
The [WebSocket Hibernation API](/durable-objects/reference/websockets/#websocket-hibernation) takes the place of the standard [WebSockets API](/workers/runtime-apis/websockets/). Therefore, `ws.accept` must not have been called separately and `ws.addEventListener` method will not receive events as they will instead be delivered to the Durable Object.
113+
The [WebSocket Hibernation API](/durable-objects/best-practices/websockets/#websocket-hibernation-api) takes the place of the standard [WebSockets API](/workers/runtime-apis/websockets/). Therefore, `ws.accept` must not have been called separately and `ws.addEventListener` method will not receive events as they will instead be delivered to the Durable Object.
114114

115115
The WebSocket Hibernation API permits a maximum of 32,768 WebSocket connections per Durable Object, but the CPU and memory usage of a given workload may further limit the practical number of simultaneous connections.
116116

@@ -125,7 +125,7 @@ The WebSocket Hibernation API permits a maximum of 32,768 WebSocket connections
125125

126126
### `getWebSockets`
127127

128-
`getWebSockets` is part of the [WebSocket Hibernation API](/durable-objects/reference/websockets/#websocket-hibernation), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
128+
`getWebSockets` is part of the [WebSocket Hibernation API](/durable-objects/best-practices/websockets/#websocket-hibernation-api), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
129129

130130
`getWebSockets` returns an `Array<WebSocket>` which is the set of WebSockets attached to the Durable Object. An optional tag argument can be used to filter the list according to tags supplied when calling [`DurableObjectState::acceptWebSocket`](/durable-objects/api/state/#acceptwebsocket).
131131

@@ -145,7 +145,7 @@ Disconnected WebSockets are not returned by this method, but `getWebSockets` may
145145

146146
### `setWebSocketAutoResponse`
147147

148-
`setWebSocketAutoResponse` is part of the [WebSocket Hibernation API](/durable-objects/reference/websockets/#websocket-hibernation), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
148+
`setWebSocketAutoResponse` is part of the [WebSocket Hibernation API](/durable-objects/best-practices/websockets/#websocket-hibernation-api), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
149149

150150
`setWebSocketAutoResponse` sets an automatic response, auto-response, for the request provided for all WebSockets attached to the Durable Object. If a request is received matching the provided request then the auto-response will be returned without waking WebSockets in hibernation and incurring billable duration charges.
151151

@@ -179,7 +179,7 @@ Disconnected WebSockets are not returned by this method, but `getWebSockets` may
179179

180180
### `getWebSocketAutoResponseTimestamp`
181181

182-
`getWebSocketAutoResponseTimestamp` is part of the [WebSocket Hibernation API](/durable-objects/reference/websockets/#websocket-hibernation), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
182+
`getWebSocketAutoResponseTimestamp` is part of the [WebSocket Hibernation API](/durable-objects/best-practices/websockets/#websocket-hibernation-api), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
183183

184184
`getWebSocketAutoResponseTimestamp` gets the most recent `Date` on which the given WebSocket sent an auto-response, or null if the given WebSocket never sent an auto-response.
185185

@@ -193,7 +193,7 @@ Disconnected WebSockets are not returned by this method, but `getWebSockets` may
193193

194194
### `setHibernatableWebSocketEventTimeout`
195195

196-
`setHibernatableWebSocketEventTimeout` is part of the [WebSocket Hibernation API](/durable-objects/reference/websockets/#websocket-hibernation), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
196+
`setHibernatableWebSocketEventTimeout` is part of the [WebSocket Hibernation API](/durable-objects/best-practices/websockets/#websocket-hibernation-api), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
197197

198198
`setHibernatableWebSocketEventTimeout` sets the maximum amount of time in milliseconds that a WebSocket event can run for.
199199

@@ -209,7 +209,7 @@ If no parameter or a parameter of `0` is provided and a timeout has been previou
209209

210210
### `getHibernatableWebSocketEventTimeout`
211211

212-
`getHibernatableWebSocketEventTimeout` is part of the [WebSocket Hibernation API](/durable-objects/reference/websockets/#websocket-hibernation), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
212+
`getHibernatableWebSocketEventTimeout` is part of the [WebSocket Hibernation API](/durable-objects/best-practices/websockets/#websocket-hibernation-api), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
213213

214214
`getHibernatableWebSocketEventTimeout` gets the currently set hibernatable WebSocket event timeout if one has been set via [`DurableObjectState::setHibernatableWebSocketEventTimeout`](/durable-objects/api/state/#sethibernatablewebsocketeventtimeout).
215215

@@ -223,7 +223,7 @@ If no parameter or a parameter of `0` is provided and a timeout has been previou
223223

224224
### `getTags`
225225

226-
`getTags` is part of the [WebSocket Hibernation API](/durable-objects/reference/websockets/#websocket-hibernation), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
226+
`getTags` is part of the [WebSocket Hibernation API](/durable-objects/best-practices/websockets/#websocket-hibernation-api), which allows a Durable Object to be removed from memory to save costs while keeping its WebSockets connected.
227227

228228
`getTags` returns tags associated with a given WebSocket. This method throws an exception if the WebSocket has not been associated with the Durable Object via [`DurableObjectState::acceptWebSocket`](/durable-objects/api/state/#acceptwebsocket).
229229

0 commit comments

Comments
 (0)