Add necessary utility functions
This commit is contained in:
parent
cdab0bb448
commit
44122d77d6
@ -373,6 +373,10 @@ impl<T: Clone + Serialize + DeserializeOwned + Send + Sync + 'static> Connection
|
||||
|
||||
messages
|
||||
}
|
||||
|
||||
pub fn connections(&self) -> Vec<Connection<T>> {
|
||||
self.connections.values().cloned().collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrap UdpSocket with some helper methods
|
||||
|
||||
21
src/lib.rs
21
src/lib.rs
@ -207,8 +207,29 @@ impl<T: Clone + Serialize + DeserializeOwned + Send + Sync + 'static> Peer<T> {
|
||||
self.connection_mgr.send(to, message, false);
|
||||
}
|
||||
|
||||
/// Send a reliable message to every connection currently connected
|
||||
pub fn broadcast_reliable(&mut self, message: T) {
|
||||
for connection in self.connections() {
|
||||
self.connection_mgr
|
||||
.send(&connection.address, message.clone(), true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Send an unreliable message to every connection currently connected
|
||||
pub fn broadcast_unreliable(&mut self, message: T) {
|
||||
for connection in self.connections() {
|
||||
self.connection_mgr
|
||||
.send(&connection.address, message.clone(), false);
|
||||
}
|
||||
}
|
||||
|
||||
/// Close the Peer, disconnecting all connections.
|
||||
pub fn close(&mut self) {
|
||||
self.connection_mgr.close();
|
||||
}
|
||||
|
||||
/// List of all current connections
|
||||
pub fn connections(&self) -> Vec<Connection<T>> {
|
||||
self.connection_mgr.connections()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user