Don't broadcast without clients
This commit is contained in:
parent
af177813b9
commit
bd5a620942
1 changed files with 7 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use log::warn;
|
use log::{debug, warn};
|
||||||
use tokio::sync::{Mutex, broadcast};
|
use tokio::sync::{Mutex, broadcast};
|
||||||
|
|
||||||
use super::models::WebSocketServerMessageWithOrigin;
|
use super::models::WebSocketServerMessageWithOrigin;
|
||||||
|
|
@ -39,7 +39,12 @@ impl Broadcasts {
|
||||||
vault: VaultId,
|
vault: VaultId,
|
||||||
document: WebSocketServerMessageWithOrigin,
|
document: WebSocketServerMessageWithOrigin,
|
||||||
) {
|
) {
|
||||||
let tx = self.get_or_create(vault).await;
|
let tx = self.get_or_create(vault.clone()).await;
|
||||||
|
|
||||||
|
if tx.receiver_count() == 0 {
|
||||||
|
debug!("Skipping broadcast, no clients connected for vault `{vault}`");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let result = tx
|
let result = tx
|
||||||
.send(document)
|
.send(document)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue