@tc-libs/sse 3.6.0 → 3.6.1
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/README.md +48 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,53 @@
|
|
|
1
|
-
# sse
|
|
1
|
+
# @tc-libs/sse
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Hub semplice per Server-Sent Events.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Espone:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- `SseModule`
|
|
8
|
+
- `SseHubService`
|
|
9
|
+
- `SseController`
|
|
8
10
|
|
|
9
|
-
##
|
|
11
|
+
## Cosa fa
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
`SseHubService` mantiene una mappa di client connessi e permette di:
|
|
14
|
+
|
|
15
|
+
- aggiungere un client con `addClient`
|
|
16
|
+
- rimuoverlo con `removeClient`
|
|
17
|
+
- inviare eventi a tutti con `broadcast`
|
|
18
|
+
- contare le connessioni con `count`
|
|
19
|
+
|
|
20
|
+
## Uso del service
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
this.sseHubService.broadcast('job.completed', {
|
|
24
|
+
jobId: '123',
|
|
25
|
+
status: 'done',
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Quando un client si collega riceve subito un evento `hello`.
|
|
30
|
+
|
|
31
|
+
## Endpoint incluso
|
|
32
|
+
|
|
33
|
+
Il controller esporta un endpoint SSE su `GET /sse`:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
@Sse('sse')
|
|
37
|
+
stream(@Req() req: Request): Observable<MessageEvent>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Alla chiusura della connessione il client viene rimosso automaticamente.
|
|
41
|
+
|
|
42
|
+
## Note operative
|
|
43
|
+
|
|
44
|
+
- Il modulo e `@Global()`.
|
|
45
|
+
- Il package non gestisce autenticazione o stanze/canali.
|
|
46
|
+
- Il package `request` esclude esplicitamente l'endpoint SSE dal timeout globale.
|
|
47
|
+
|
|
48
|
+
## Sviluppo
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
nx build sse
|
|
52
|
+
nx test sse
|
|
53
|
+
```
|