forked from lavina/lavina
1
0
Fork 0
This commit is contained in:
Nikita Vilunov 2024-05-08 19:04:53 +02:00
parent b619ff5f00
commit 486bc17ec5
1 changed files with 25 additions and 1 deletions

View File

@ -1,5 +1,29 @@
use std::collections::{HashMap, HashSet};
use crate::player::PlayerId;
use crate::prelude::Str;
use crate::room::RoomId;
/// Receives updates from other nodes and broadcasts them to local player actors.
struct Broadcasting {
subscriptions: HashMap<RoomId, HashSet<PlayerId>>,
}
impl Broadcasting {
/// Creates a new broadcasting instance.
pub fn new() -> Self {
Self {
subscriptions: HashMap::new(),
}
}
/// Broadcasts the given update to player actors.
pub fn broadcast(&self, room_id: RoomId, author_id: PlayerId, message: Str) {
self.subscriptions.get(&room_id).map(|players| {
players.iter().for_each(|player_id| {
// Send the message to the player actor.
});
});
}
}