Skip to content

Commit 46edf37

Browse files
committed
Adding a new
1 parent 55435c4 commit 46edf37

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Durable Object Base Class
3+
pcx_content_type: concept
4+
sidebar:
5+
order: 1
6+
---
7+
8+
import { Render, Tabs, TabItem, GlossaryTooltip, Type, MetaInfo } from "~/components";
9+
10+
{/* DEFINITION OF DO BASE CLASS TBC */}
11+
12+
## Methods
13+
14+
### `webSocketMessage`
15+
16+
- <code> webSocketMessage(ws <Type text="WebSocket" />, message{" "} <Type text="string | ArrayBuffer" />)</code>: <Type text="void" />
17+
18+
- Called by the system when an accepted WebSocket receives a message.
19+
20+
- This method can be `async`.
21+
22+
- This method is not called for WebSocket control frames. The system will respond to an incoming [WebSocket protocol ping](https://www.rfc-editor.org/rfc/rfc6455#section-5.5.2) automatically without interrupting hibernation.
23+
24+
### `webSocketClose`
25+
26+
- <code> webSocketClose(ws <Type text="WebSocket" />, code <Type text="number" />,reason <Type text="string" />, wasClean <Type text="boolean" />)</code>: <Type text="void" />
27+
28+
- Called by the system when a WebSocket is closed. `wasClean()` is true if the connection closed cleanly, false otherwise.
29+
30+
- This method can be `async`.
31+
32+
### `webSocketError`
33+
34+
- <code> webSocketError(ws <Type text="WebSocket" />, error <Type text="any" />)</code> : <Type text="void" />
35+
36+
- Called by the system when any non-disconnection related errors occur.
37+
38+
- This method can be `async`.
39+
40+
## Properties
41+
42+
{/* Properties of DO Base Class TBC */}
43+
44+
## Related resources
45+
46+
- Refer to [Use WebSockets](/durable-objects/best-practices/websockets/) for more information on examples of WebSocket methods and best practices.

src/content/docs/durable-objects/best-practices/websockets.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,12 @@ A full example can be found in [Build a WebSocket server with WebSocket Hibernat
375375

376376
Prior to `[email protected]` and Miniflare `v3.20231016.0`, WebSockets did not hibernate when using local development environments such as `wrangler dev` or Miniflare.
377377

378-
If you are using older versions, note that while hibernatable WebSocket events such as [`webSocketMessage()`](/durable-objects/best-practices/websockets/#websocketmessage) will still be delivered, the Durable Object will never be evicted from memory.
378+
If you are using older versions, note that while hibernatable WebSocket events such as [`webSocketMessage()`](/durable-objects/api/base/#websocketmessage) will still be delivered, the Durable Object will never be evicted from memory.
379379

380380
:::
381381

382382
## Related resources
383383

384384
- [Mozilla Developer Network's (MDN) documentation on the WebSocket class](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)
385385
- [Cloudflare's WebSocket template for building applications on Workers using WebSockets](https://github.com/cloudflare/websocket-template)
386+
- [Methods of Durable Object base class](/durable-objects/api/base/)

0 commit comments

Comments
 (0)