Introduce call infrastructure
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
ebb5ffcedc
commit
4a9bf8f4fe
11 changed files with 249 additions and 45 deletions
|
@ -351,6 +351,45 @@ impl Store {
|
|||
Ok(room_id)
|
||||
}
|
||||
|
||||
pub fn call(
|
||||
&mut self,
|
||||
room_id: RoomId,
|
||||
from_connection_id: ConnectionId,
|
||||
to_user_id: UserId,
|
||||
) -> Result<(UserId, Vec<ConnectionId>, proto::Room)> {
|
||||
let from_user_id = self.user_id_for_connection(from_connection_id)?;
|
||||
let to_connection_ids = self.connection_ids_for_user(to_user_id).collect::<Vec<_>>();
|
||||
let room = self
|
||||
.rooms
|
||||
.get_mut(&room_id)
|
||||
.ok_or_else(|| anyhow!("no such room"))?;
|
||||
anyhow::ensure!(
|
||||
room.participants
|
||||
.iter()
|
||||
.any(|participant| participant.peer_id == from_connection_id.0),
|
||||
"no such room"
|
||||
);
|
||||
anyhow::ensure!(
|
||||
room.pending_calls_to_user_ids
|
||||
.iter()
|
||||
.all(|user_id| UserId::from_proto(*user_id) != to_user_id),
|
||||
"cannot call the same user more than once"
|
||||
);
|
||||
room.pending_calls_to_user_ids.push(to_user_id.to_proto());
|
||||
|
||||
Ok((from_user_id, to_connection_ids, room.clone()))
|
||||
}
|
||||
|
||||
pub fn call_failed(&mut self, room_id: RoomId, to_user_id: UserId) -> Result<proto::Room> {
|
||||
let room = self
|
||||
.rooms
|
||||
.get_mut(&room_id)
|
||||
.ok_or_else(|| anyhow!("no such room"))?;
|
||||
room.pending_calls_to_user_ids
|
||||
.retain(|user_id| UserId::from_proto(*user_id) != to_user_id);
|
||||
Ok(room.clone())
|
||||
}
|
||||
|
||||
pub fn register_project(
|
||||
&mut self,
|
||||
host_connection_id: ConnectionId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue