forked from lavina/lavina
1
0
Fork 0

rename socket => connection for consistency

This commit is contained in:
Nikita Vilunov 2023-02-14 20:45:22 +01:00
parent 57ea2dd2d7
commit 4e5ccd604c
1 changed files with 9 additions and 9 deletions

View File

@ -79,7 +79,7 @@ impl PlayerHandle {
let (sender, receiver) = channel(32);
let (promise, deferred) = oneshot();
self.tx
.send(PlayerCommand::AddSocket { sender, promise })
.send(PlayerCommand::AddConnection { sender, promise })
.await;
let connection_id = deferred.await.unwrap();
PlayerConnection {
@ -126,7 +126,7 @@ impl PlayerHandle {
pub enum PlayerCommand {
/** Commands from connections */
AddSocket {
AddConnection {
sender: Sender<Updates>,
promise: OneshotSender<ConnectionId>,
},
@ -186,7 +186,7 @@ impl PlayerRegistry {
pub async fn get_or_create_player(&mut self, id: PlayerId) -> PlayerHandle {
let player = Player {
sockets: AnonTable::new(),
connections: AnonTable::new(),
};
let mut inner = self.0.write().unwrap();
if let Some((handle, _)) = inner.players.get(&id) {
@ -214,7 +214,7 @@ struct PlayerRegistryInner {
/// Player actor inner state representation.
struct Player {
sockets: AnonTable<Sender<Updates>>,
connections: AnonTable<Sender<Updates>>,
}
impl Player {
fn launch(
@ -229,8 +229,8 @@ impl Player {
let fiber = tokio::task::spawn(async move {
while let Some(cmd) = rx.recv().await {
match cmd {
PlayerCommand::AddSocket { sender, promise } => {
let connection_id = self.sockets.insert(sender);
PlayerCommand::AddConnection { sender, promise } => {
let connection_id = self.connections.insert(sender);
promise.send(ConnectionId(connection_id));
}
PlayerCommand::JoinRoom {
@ -275,10 +275,10 @@ impl Player {
PlayerCommand::Update(update) => {
log::info!(
"Player received an update, broadcasting to {} connections",
self.sockets.len()
self.connections.len()
);
for socket in &self.sockets {
socket.send(update.clone()).await;
for connection in &self.connections {
connection.send(update.clone()).await;
}
}
}