@donkeylabs/server 2.0.3 → 2.0.5
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/package.json +1 -1
- package/src/core/sse.ts +4 -0
- package/src/handlers.ts +5 -0
package/package.json
CHANGED
package/src/core/sse.ts
CHANGED
|
@@ -58,6 +58,10 @@ class SSEImpl implements SSE {
|
|
|
58
58
|
// Send retry interval to client
|
|
59
59
|
const retryMsg = `retry: ${this.retryInterval}\n\n`;
|
|
60
60
|
controller.enqueue(this.encoder.encode(retryMsg));
|
|
61
|
+
|
|
62
|
+
// Send immediate heartbeat to establish connection and prevent early timeout
|
|
63
|
+
const heartbeat = `: heartbeat ${Date.now()}\n\n`;
|
|
64
|
+
controller.enqueue(this.encoder.encode(heartbeat));
|
|
61
65
|
},
|
|
62
66
|
cancel: () => {
|
|
63
67
|
this.removeClient(id);
|
package/src/handlers.ts
CHANGED
|
@@ -194,6 +194,11 @@ export const SSEHandler: SSEHandler = {
|
|
|
194
194
|
ctx.core.sse.subscribe(client.id, channel);
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
// Clean up client when connection is aborted
|
|
198
|
+
req.signal.addEventListener("abort", () => {
|
|
199
|
+
ctx.core.sse.removeClient(client.id);
|
|
200
|
+
});
|
|
201
|
+
|
|
197
202
|
return response;
|
|
198
203
|
} catch (e: any) {
|
|
199
204
|
console.error(e);
|