@buley/relay 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/sync-room.ts +17 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.1.0] - 2026-01-23
|
|
4
|
+
|
|
5
|
+
### Improvements
|
|
6
|
+
|
|
7
|
+
- **Hibernation Refinements**: Explicit broadcast handling and improved comments for Cloudflare Hibernation behavior.
|
|
8
|
+
- **Code Cleanup**: Extracted broadcast logic.
|
|
9
|
+
|
|
3
10
|
## [4.0.0] - 2026-01-23
|
|
4
11
|
|
|
5
12
|
### Features
|
package/package.json
CHANGED
package/src/sync-room.ts
CHANGED
|
@@ -45,14 +45,13 @@ export class SyncRoom extends DurableObject<Env> {
|
|
|
45
45
|
|
|
46
46
|
this.sql.exec("INSERT INTO messages (data) VALUES (?)", data as any);
|
|
47
47
|
|
|
48
|
+
this.sql.exec("INSERT INTO messages (data) VALUES (?)", data as any);
|
|
49
|
+
|
|
48
50
|
// 2. Broadcast to others
|
|
49
|
-
|
|
50
|
-
if (other !== ws) {
|
|
51
|
-
other.send(message);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
51
|
+
this.broadcast(message, ws);
|
|
54
52
|
|
|
55
53
|
// 3. Set Alarm for Write-back (Debounced)
|
|
54
|
+
// Hibernation Note: The alarm will wake the DO up even if all clients are hibernating.
|
|
56
55
|
const currentAlarm = await this.ctx.storage.getAlarm();
|
|
57
56
|
if (currentAlarm === null) {
|
|
58
57
|
// Set alarm for 10 seconds from now
|
|
@@ -60,6 +59,19 @@ export class SyncRoom extends DurableObject<Env> {
|
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
|
|
62
|
+
private broadcast(message: ArrayBuffer | string, exclude?: WebSocket) {
|
|
63
|
+
// Determine the message to send once
|
|
64
|
+
for (const client of this.ctx.getWebSockets()) {
|
|
65
|
+
if (client !== exclude) {
|
|
66
|
+
try {
|
|
67
|
+
client.send(message);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
// fast-fail on dead sockets
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
async webSocketClose(ws: WebSocket, code: number, reason: string, wasClean: boolean) {
|
|
64
76
|
// Clean up if needed
|
|
65
77
|
}
|