Registers client with broadcaster, returning an SSE response body.
(&self)
| 65 | |
| 66 | /// Registers client with broadcaster, returning an SSE response body. |
| 67 | pub async fn new_client(&self) -> Sse<InfallibleStream<ReceiverStream<sse::Event>>> { |
| 68 | let (tx, rx) = mpsc::channel(10); |
| 69 | |
| 70 | tx.send(sse::Data::new("connected").into()).await.unwrap(); |
| 71 | |
| 72 | self.inner.lock().clients.push(tx); |
| 73 | |
| 74 | Sse::from_infallible_receiver(rx) |
| 75 | } |
| 76 | |
| 77 | /// Broadcasts `msg` to all clients. |
| 78 | pub async fn broadcast(&self, msg: &str) { |