@wxn0brp/falcon-frame 0.9.3 → 0.9.4
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/dist/res.d.ts +7 -0
- package/dist/res.js +12 -0
- package/dist/router.d.ts +1 -1
- package/dist/router.js +1 -1
- package/dist/sse.d.ts +2 -0
- package/dist/sse.js +18 -9
- package/package.json +1 -1
package/dist/res.d.ts
CHANGED
|
@@ -83,4 +83,11 @@ export declare class FFResponse extends http.ServerResponse {
|
|
|
83
83
|
* @returns The response object
|
|
84
84
|
*/
|
|
85
85
|
sseSend(data: string | object): this;
|
|
86
|
+
/**
|
|
87
|
+
* Sends a Server-Sent Event with an event type to the client.
|
|
88
|
+
* @param event The event type
|
|
89
|
+
* @param data The data to be sent. If an object, it will be JSON.stringified.
|
|
90
|
+
* @returns The response object
|
|
91
|
+
*/
|
|
92
|
+
sseEventSend(event: string, data: string | object): this;
|
|
86
93
|
}
|
package/dist/res.js
CHANGED
|
@@ -180,4 +180,16 @@ export class FFResponse extends http.ServerResponse {
|
|
|
180
180
|
this.write(`data: ${data}\n\n`);
|
|
181
181
|
return this;
|
|
182
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Sends a Server-Sent Event with an event type to the client.
|
|
185
|
+
* @param event The event type
|
|
186
|
+
* @param data The data to be sent. If an object, it will be JSON.stringified.
|
|
187
|
+
* @returns The response object
|
|
188
|
+
*/
|
|
189
|
+
sseEventSend(event, data) {
|
|
190
|
+
if (typeof data === "object")
|
|
191
|
+
data = JSON.stringify(data);
|
|
192
|
+
this.write(`event: ${event}\ndata: ${data}\n\n`);
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
183
195
|
}
|
package/dist/router.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export declare class Router {
|
|
|
16
16
|
static(apiPath: string, dirPath?: string, opts?: StaticServeOptions): this;
|
|
17
17
|
sse(path: string, ...handlers: RouteHandler[]): SSEManager;
|
|
18
18
|
customParser(path: string, handler: RouteHandler, method?: Method): this;
|
|
19
|
-
router(path
|
|
19
|
+
router(path?: string): Router;
|
|
20
20
|
}
|
package/dist/router.js
CHANGED
package/dist/sse.d.ts
CHANGED
package/dist/sse.js
CHANGED
|
@@ -20,21 +20,30 @@ export class SSEManager {
|
|
|
20
20
|
return this._clients;
|
|
21
21
|
}
|
|
22
22
|
sendAll(data) {
|
|
23
|
-
for (const { res } of this._clients.values())
|
|
23
|
+
for (const { res } of this._clients.values())
|
|
24
24
|
res.sseSend(data);
|
|
25
|
-
}
|
|
26
25
|
}
|
|
27
26
|
sendTo(id, data) {
|
|
28
27
|
const client = this._clients.get(id);
|
|
29
|
-
if (client)
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
if (!client)
|
|
29
|
+
return;
|
|
30
|
+
client.res.sseSend(data);
|
|
31
|
+
}
|
|
32
|
+
sendEventAll(event, data) {
|
|
33
|
+
for (const { res } of this._clients.values())
|
|
34
|
+
res.sseEventSend(event, data);
|
|
35
|
+
}
|
|
36
|
+
sendEventTo(id, event, data) {
|
|
37
|
+
const client = this._clients.get(id);
|
|
38
|
+
if (!client)
|
|
39
|
+
return;
|
|
40
|
+
client.res.sseEventSend(event, data);
|
|
32
41
|
}
|
|
33
42
|
disconnect(id) {
|
|
34
43
|
const client = this._clients.get(id);
|
|
35
|
-
if (client)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
if (!client)
|
|
45
|
+
return;
|
|
46
|
+
client.res.end();
|
|
47
|
+
this._clients.delete(id);
|
|
39
48
|
}
|
|
40
49
|
}
|