mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Introduce call infrastructure
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
ebb5ffcedc
commit
4a9bf8f4fe
@ -3,6 +3,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Call {
|
pub struct Call {
|
||||||
pub from: Vec<Arc<User>>,
|
|
||||||
pub room_id: u64,
|
pub room_id: u64,
|
||||||
|
pub from: Arc<User>,
|
||||||
|
pub participants: Vec<Arc<User>>,
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ impl ChannelMessage {
|
|||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let sender = user_store
|
let sender = user_store
|
||||||
.update(cx, |user_store, cx| {
|
.update(cx, |user_store, cx| {
|
||||||
user_store.fetch_user(message.sender_id, cx)
|
user_store.get_user(message.sender_id, cx)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
Ok(ChannelMessage {
|
Ok(ChannelMessage {
|
||||||
|
@ -422,6 +422,29 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_request_handler<M, E, H, F>(
|
||||||
|
self: &Arc<Self>,
|
||||||
|
model: ModelHandle<E>,
|
||||||
|
handler: H,
|
||||||
|
) -> Subscription
|
||||||
|
where
|
||||||
|
M: RequestMessage,
|
||||||
|
E: Entity,
|
||||||
|
H: 'static
|
||||||
|
+ Send
|
||||||
|
+ Sync
|
||||||
|
+ Fn(ModelHandle<E>, TypedEnvelope<M>, Arc<Self>, AsyncAppContext) -> F,
|
||||||
|
F: 'static + Future<Output = Result<M::Response>>,
|
||||||
|
{
|
||||||
|
self.add_message_handler(model, move |handle, envelope, this, cx| {
|
||||||
|
Self::respond_to_request(
|
||||||
|
envelope.receipt(),
|
||||||
|
handler(handle, envelope, this.clone(), cx),
|
||||||
|
this,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_view_message_handler<M, E, H, F>(self: &Arc<Self>, handler: H)
|
pub fn add_view_message_handler<M, E, H, F>(self: &Arc<Self>, handler: H)
|
||||||
where
|
where
|
||||||
M: EntityMessage,
|
M: EntityMessage,
|
||||||
|
@ -5,7 +5,7 @@ use anyhow::{anyhow, Context, Result};
|
|||||||
use collections::{hash_map::Entry, BTreeSet, HashMap, HashSet};
|
use collections::{hash_map::Entry, BTreeSet, HashMap, HashSet};
|
||||||
use futures::{channel::mpsc, future, AsyncReadExt, Future, Stream, StreamExt};
|
use futures::{channel::mpsc, future, AsyncReadExt, Future, Stream, StreamExt};
|
||||||
use gpui::{AsyncAppContext, Entity, ImageData, ModelContext, ModelHandle, Task};
|
use gpui::{AsyncAppContext, Entity, ImageData, ModelContext, ModelHandle, Task};
|
||||||
use postage::{broadcast, sink::Sink, watch};
|
use postage::{sink::Sink, watch};
|
||||||
use rpc::proto::{RequestMessage, UsersResponse};
|
use rpc::proto::{RequestMessage, UsersResponse};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use util::TryFutureExt as _;
|
use util::TryFutureExt as _;
|
||||||
@ -68,7 +68,7 @@ pub struct UserStore {
|
|||||||
outgoing_contact_requests: Vec<Arc<User>>,
|
outgoing_contact_requests: Vec<Arc<User>>,
|
||||||
pending_contact_requests: HashMap<u64, usize>,
|
pending_contact_requests: HashMap<u64, usize>,
|
||||||
invite_info: Option<InviteInfo>,
|
invite_info: Option<InviteInfo>,
|
||||||
incoming_calls: broadcast::Sender<Call>,
|
incoming_calls: Vec<mpsc::UnboundedSender<Call>>,
|
||||||
client: Weak<Client>,
|
client: Weak<Client>,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
_maintain_contacts: Task<()>,
|
_maintain_contacts: Task<()>,
|
||||||
@ -118,8 +118,8 @@ impl UserStore {
|
|||||||
client.add_message_handler(cx.handle(), Self::handle_update_contacts),
|
client.add_message_handler(cx.handle(), Self::handle_update_contacts),
|
||||||
client.add_message_handler(cx.handle(), Self::handle_update_invite_info),
|
client.add_message_handler(cx.handle(), Self::handle_update_invite_info),
|
||||||
client.add_message_handler(cx.handle(), Self::handle_show_contacts),
|
client.add_message_handler(cx.handle(), Self::handle_show_contacts),
|
||||||
|
client.add_request_handler(cx.handle(), Self::handle_incoming_call),
|
||||||
];
|
];
|
||||||
let (incoming_calls, _) = broadcast::channel(32);
|
|
||||||
Self {
|
Self {
|
||||||
users: Default::default(),
|
users: Default::default(),
|
||||||
current_user: current_user_rx,
|
current_user: current_user_rx,
|
||||||
@ -127,7 +127,7 @@ impl UserStore {
|
|||||||
incoming_contact_requests: Default::default(),
|
incoming_contact_requests: Default::default(),
|
||||||
outgoing_contact_requests: Default::default(),
|
outgoing_contact_requests: Default::default(),
|
||||||
invite_info: None,
|
invite_info: None,
|
||||||
incoming_calls,
|
incoming_calls: Default::default(),
|
||||||
client: Arc::downgrade(&client),
|
client: Arc::downgrade(&client),
|
||||||
update_contacts_tx,
|
update_contacts_tx,
|
||||||
http,
|
http,
|
||||||
@ -148,7 +148,7 @@ impl UserStore {
|
|||||||
Status::Connected { .. } => {
|
Status::Connected { .. } => {
|
||||||
if let Some((this, user_id)) = this.upgrade(&cx).zip(client.user_id()) {
|
if let Some((this, user_id)) = this.upgrade(&cx).zip(client.user_id()) {
|
||||||
let user = this
|
let user = this
|
||||||
.update(&mut cx, |this, cx| this.fetch_user(user_id, cx))
|
.update(&mut cx, |this, cx| this.get_user(user_id, cx))
|
||||||
.log_err()
|
.log_err()
|
||||||
.await;
|
.await;
|
||||||
current_user_tx.send(user).await.ok();
|
current_user_tx.send(user).await.ok();
|
||||||
@ -199,12 +199,41 @@ impl UserStore {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn handle_incoming_call(
|
||||||
|
this: ModelHandle<Self>,
|
||||||
|
envelope: TypedEnvelope<proto::IncomingCall>,
|
||||||
|
_: Arc<Client>,
|
||||||
|
mut cx: AsyncAppContext,
|
||||||
|
) -> Result<proto::Ack> {
|
||||||
|
let call = Call {
|
||||||
|
room_id: envelope.payload.room_id,
|
||||||
|
participants: this
|
||||||
|
.update(&mut cx, |this, cx| {
|
||||||
|
this.get_users(envelope.payload.participant_user_ids, cx)
|
||||||
|
})
|
||||||
|
.await?,
|
||||||
|
from: this
|
||||||
|
.update(&mut cx, |this, cx| {
|
||||||
|
this.get_user(envelope.payload.from_user_id, cx)
|
||||||
|
})
|
||||||
|
.await?,
|
||||||
|
};
|
||||||
|
this.update(&mut cx, |this, _| {
|
||||||
|
this.incoming_calls
|
||||||
|
.retain(|tx| tx.unbounded_send(call.clone()).is_ok());
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(proto::Ack {})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn invite_info(&self) -> Option<&InviteInfo> {
|
pub fn invite_info(&self) -> Option<&InviteInfo> {
|
||||||
self.invite_info.as_ref()
|
self.invite_info.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn incoming_calls(&self) -> impl 'static + Stream<Item = Call> {
|
pub fn incoming_calls(&mut self) -> impl 'static + Stream<Item = Call> {
|
||||||
self.incoming_calls.subscribe()
|
let (tx, rx) = mpsc::unbounded();
|
||||||
|
self.incoming_calls.push(tx);
|
||||||
|
rx
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_update_contacts(
|
async fn handle_update_contacts(
|
||||||
@ -266,9 +295,7 @@ impl UserStore {
|
|||||||
for request in message.incoming_requests {
|
for request in message.incoming_requests {
|
||||||
incoming_requests.push({
|
incoming_requests.push({
|
||||||
let user = this
|
let user = this
|
||||||
.update(&mut cx, |this, cx| {
|
.update(&mut cx, |this, cx| this.get_user(request.requester_id, cx))
|
||||||
this.fetch_user(request.requester_id, cx)
|
|
||||||
})
|
|
||||||
.await?;
|
.await?;
|
||||||
(user, request.should_notify)
|
(user, request.should_notify)
|
||||||
});
|
});
|
||||||
@ -277,7 +304,7 @@ impl UserStore {
|
|||||||
let mut outgoing_requests = Vec::new();
|
let mut outgoing_requests = Vec::new();
|
||||||
for requested_user_id in message.outgoing_requests {
|
for requested_user_id in message.outgoing_requests {
|
||||||
outgoing_requests.push(
|
outgoing_requests.push(
|
||||||
this.update(&mut cx, |this, cx| this.fetch_user(requested_user_id, cx))
|
this.update(&mut cx, |this, cx| this.get_user(requested_user_id, cx))
|
||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -518,19 +545,37 @@ impl UserStore {
|
|||||||
|
|
||||||
pub fn get_users(
|
pub fn get_users(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut user_ids: Vec<u64>,
|
user_ids: Vec<u64>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<Vec<Arc<User>>>> {
|
||||||
user_ids.retain(|id| !self.users.contains_key(id));
|
let mut user_ids_to_fetch = user_ids.clone();
|
||||||
if user_ids.is_empty() {
|
user_ids_to_fetch.retain(|id| !self.users.contains_key(id));
|
||||||
Task::ready(Ok(()))
|
|
||||||
} else {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let load = self.load_users(proto::GetUsers { user_ids }, cx);
|
if !user_ids_to_fetch.is_empty() {
|
||||||
cx.foreground().spawn(async move {
|
this.update(&mut cx, |this, cx| {
|
||||||
load.await?;
|
this.load_users(
|
||||||
Ok(())
|
proto::GetUsers {
|
||||||
|
user_ids: user_ids_to_fetch,
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.read_with(&cx, |this, _| {
|
||||||
|
user_ids
|
||||||
|
.iter()
|
||||||
|
.map(|user_id| {
|
||||||
|
this.users
|
||||||
|
.get(user_id)
|
||||||
|
.cloned()
|
||||||
|
.ok_or_else(|| anyhow!("user {} not found", user_id))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fuzzy_search_users(
|
pub fn fuzzy_search_users(
|
||||||
@ -541,7 +586,7 @@ impl UserStore {
|
|||||||
self.load_users(proto::FuzzySearchUsers { query }, cx)
|
self.load_users(proto::FuzzySearchUsers { query }, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_user(
|
pub fn get_user(
|
||||||
&mut self,
|
&mut self,
|
||||||
user_id: u64,
|
user_id: u64,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
@ -621,7 +666,7 @@ impl Contact {
|
|||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let user = user_store
|
let user = user_store
|
||||||
.update(cx, |user_store, cx| {
|
.update(cx, |user_store, cx| {
|
||||||
user_store.fetch_user(contact.user_id, cx)
|
user_store.get_user(contact.user_id, cx)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
let mut projects = Vec::new();
|
let mut projects = Vec::new();
|
||||||
@ -630,9 +675,7 @@ impl Contact {
|
|||||||
for participant_id in project.guests {
|
for participant_id in project.guests {
|
||||||
guests.insert(
|
guests.insert(
|
||||||
user_store
|
user_store
|
||||||
.update(cx, |user_store, cx| {
|
.update(cx, |user_store, cx| user_store.get_user(participant_id, cx))
|
||||||
user_store.fetch_user(participant_id, cx)
|
|
||||||
})
|
|
||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -100,16 +100,16 @@ async fn test_share_project_in_room(
|
|||||||
|
|
||||||
let mut incoming_calls_b = client_b
|
let mut incoming_calls_b = client_b
|
||||||
.user_store
|
.user_store
|
||||||
.read_with(cx_b, |user, _| user.incoming_calls());
|
.update(cx_b, |user, _| user.incoming_calls());
|
||||||
let user_b_joined = room_a.update(cx_a, |room, cx| {
|
room_a
|
||||||
room.invite(client_b.user_id().unwrap(), cx)
|
.update(cx_a, |room, cx| room.call(client_b.user_id().unwrap(), cx))
|
||||||
});
|
.await
|
||||||
|
.unwrap();
|
||||||
let call_b = incoming_calls_b.next().await.unwrap();
|
let call_b = incoming_calls_b.next().await.unwrap();
|
||||||
let room_b = cx_b
|
let room_b = cx_b
|
||||||
.update(|cx| Room::join(call_b.room_id, client_b.clone(), cx))
|
.update(|cx| Room::join(call_b.room_id, client_b.clone(), cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
user_b_joined.await.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test(iterations = 10)]
|
#[gpui::test(iterations = 10)]
|
||||||
@ -512,7 +512,7 @@ async fn test_cancel_join_request(
|
|||||||
let user_b = client_a
|
let user_b = client_a
|
||||||
.user_store
|
.user_store
|
||||||
.update(cx_a, |store, cx| {
|
.update(cx_a, |store, cx| {
|
||||||
store.fetch_user(client_b.user_id().unwrap(), cx)
|
store.get_user(client_b.user_id().unwrap(), cx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -152,6 +152,7 @@ impl Server {
|
|||||||
server
|
server
|
||||||
.add_request_handler(Server::ping)
|
.add_request_handler(Server::ping)
|
||||||
.add_request_handler(Server::create_room)
|
.add_request_handler(Server::create_room)
|
||||||
|
.add_request_handler(Server::call)
|
||||||
.add_request_handler(Server::register_project)
|
.add_request_handler(Server::register_project)
|
||||||
.add_request_handler(Server::unregister_project)
|
.add_request_handler(Server::unregister_project)
|
||||||
.add_request_handler(Server::join_project)
|
.add_request_handler(Server::join_project)
|
||||||
@ -604,6 +605,68 @@ impl Server {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn call(
|
||||||
|
self: Arc<Server>,
|
||||||
|
request: TypedEnvelope<proto::Call>,
|
||||||
|
response: Response<proto::Call>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let to_user_id = UserId::from_proto(request.payload.to_user_id);
|
||||||
|
let room_id = request.payload.room_id;
|
||||||
|
let (from_user_id, receiver_ids, room) =
|
||||||
|
self.store()
|
||||||
|
.await
|
||||||
|
.call(room_id, request.sender_id, to_user_id)?;
|
||||||
|
for participant in &room.participants {
|
||||||
|
self.peer
|
||||||
|
.send(
|
||||||
|
ConnectionId(participant.peer_id),
|
||||||
|
proto::RoomUpdated {
|
||||||
|
room: Some(room.clone()),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.trace_err();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut calls = receiver_ids
|
||||||
|
.into_iter()
|
||||||
|
.map(|receiver_id| {
|
||||||
|
self.peer.request(
|
||||||
|
receiver_id,
|
||||||
|
proto::IncomingCall {
|
||||||
|
room_id,
|
||||||
|
from_user_id: from_user_id.to_proto(),
|
||||||
|
participant_user_ids: room.participants.iter().map(|p| p.user_id).collect(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<FuturesUnordered<_>>();
|
||||||
|
|
||||||
|
while let Some(call_response) = calls.next().await {
|
||||||
|
match call_response.as_ref() {
|
||||||
|
Ok(_) => {
|
||||||
|
response.send(proto::Ack {})?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
call_response.trace_err();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let room = self.store().await.call_failed(room_id, to_user_id)?;
|
||||||
|
for participant in &room.participants {
|
||||||
|
self.peer
|
||||||
|
.send(
|
||||||
|
ConnectionId(participant.peer_id),
|
||||||
|
proto::RoomUpdated {
|
||||||
|
room: Some(room.clone()),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.trace_err();
|
||||||
|
}
|
||||||
|
Err(anyhow!("failed to ring call recipient"))?
|
||||||
|
}
|
||||||
|
|
||||||
async fn register_project(
|
async fn register_project(
|
||||||
self: Arc<Server>,
|
self: Arc<Server>,
|
||||||
request: TypedEnvelope<proto::RegisterProject>,
|
request: TypedEnvelope<proto::RegisterProject>,
|
||||||
|
@ -351,6 +351,45 @@ impl Store {
|
|||||||
Ok(room_id)
|
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(
|
pub fn register_project(
|
||||||
&mut self,
|
&mut self,
|
||||||
host_connection_id: ConnectionId,
|
host_connection_id: ConnectionId,
|
||||||
|
@ -4744,7 +4744,7 @@ impl Project {
|
|||||||
} else {
|
} else {
|
||||||
let user_store = this.read_with(&cx, |this, _| this.user_store.clone());
|
let user_store = this.read_with(&cx, |this, _| this.user_store.clone());
|
||||||
let user = user_store
|
let user = user_store
|
||||||
.update(&mut cx, |store, cx| store.fetch_user(user_id, cx))
|
.update(&mut cx, |store, cx| store.get_user(user_id, cx))
|
||||||
.await?;
|
.await?;
|
||||||
this.update(&mut cx, |_, cx| cx.emit(Event::ContactRequestedJoin(user)));
|
this.update(&mut cx, |_, cx| cx.emit(Event::ContactRequestedJoin(user)));
|
||||||
}
|
}
|
||||||
@ -4828,7 +4828,7 @@ impl Project {
|
|||||||
let user = this
|
let user = this
|
||||||
.update(&mut cx, |this, cx| {
|
.update(&mut cx, |this, cx| {
|
||||||
this.user_store.update(cx, |user_store, cx| {
|
this.user_store.update(cx, |user_store, cx| {
|
||||||
user_store.fetch_user(envelope.payload.requester_id, cx)
|
user_store.get_user(envelope.payload.requester_id, cx)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
@ -6258,7 +6258,7 @@ impl Collaborator {
|
|||||||
cx: &mut AsyncAppContext,
|
cx: &mut AsyncAppContext,
|
||||||
) -> impl Future<Output = Result<Self>> {
|
) -> impl Future<Output = Result<Self>> {
|
||||||
let user = user_store.update(cx, |user_store, cx| {
|
let user = user_store.update(cx, |user_store, cx| {
|
||||||
user_store.fetch_user(message.user_id, cx)
|
user_store.get_user(message.user_id, cx)
|
||||||
});
|
});
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
|
@ -12,6 +12,11 @@ pub enum Event {
|
|||||||
PeerChangedActiveProject,
|
PeerChangedActiveProject,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum CallResponse {
|
||||||
|
Accepted,
|
||||||
|
Rejected,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Room {
|
pub struct Room {
|
||||||
id: u64,
|
id: u64,
|
||||||
local_participant: LocalParticipant,
|
local_participant: LocalParticipant,
|
||||||
@ -43,7 +48,7 @@ impl Room {
|
|||||||
let response = client.request(proto::JoinRoom { id }).await?;
|
let response = client.request(proto::JoinRoom { id }).await?;
|
||||||
let room_proto = response.room.ok_or_else(|| anyhow!("invalid room"))?;
|
let room_proto = response.room.ok_or_else(|| anyhow!("invalid room"))?;
|
||||||
let room = cx.add_model(|cx| Self::new(id, client, cx));
|
let room = cx.add_model(|cx| Self::new(id, client, cx));
|
||||||
room.update(&mut cx, |room, cx| room.refresh(room_proto, cx))?;
|
room.update(&mut cx, |room, cx| room.apply_update(room_proto, cx))?;
|
||||||
Ok(room)
|
Ok(room)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -59,7 +64,7 @@ impl Room {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn refresh(&mut self, room: proto::Room, cx: &mut ModelContext<Self>) -> Result<()> {
|
fn apply_update(&mut self, room: proto::Room, cx: &mut ModelContext<Self>) -> Result<()> {
|
||||||
for participant in room.participants {
|
for participant in room.participants {
|
||||||
self.remote_participants.insert(
|
self.remote_participants.insert(
|
||||||
PeerId(participant.peer_id),
|
PeerId(participant.peer_id),
|
||||||
@ -70,11 +75,22 @@ impl Room {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
cx.notify();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invite(&mut self, user_id: u64, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
pub fn call(&mut self, to_user_id: u64, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
||||||
todo!()
|
let client = self.client.clone();
|
||||||
|
let room_id = self.id;
|
||||||
|
cx.foreground().spawn(async move {
|
||||||
|
client
|
||||||
|
.request(proto::Call {
|
||||||
|
room_id,
|
||||||
|
to_user_id,
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn publish_project(&mut self, project: ModelHandle<Project>) -> Result<()> {
|
pub async fn publish_project(&mut self, project: ModelHandle<Project>) -> Result<()> {
|
||||||
|
@ -16,7 +16,8 @@ message Envelope {
|
|||||||
JoinRoom join_room = 10;
|
JoinRoom join_room = 10;
|
||||||
JoinRoomResponse join_room_response = 11;
|
JoinRoomResponse join_room_response = 11;
|
||||||
Call call = 12;
|
Call call = 12;
|
||||||
CallResponse call_response = 13;
|
IncomingCall incoming_call = 1000;
|
||||||
|
RespondToCall respond_to_call = 13;
|
||||||
RoomUpdated room_updated = 14;
|
RoomUpdated room_updated = 14;
|
||||||
|
|
||||||
RegisterProject register_project = 15;
|
RegisterProject register_project = 15;
|
||||||
@ -149,6 +150,7 @@ message JoinRoomResponse {
|
|||||||
|
|
||||||
message Room {
|
message Room {
|
||||||
repeated Participant participants = 1;
|
repeated Participant participants = 1;
|
||||||
|
repeated uint64 pending_calls_to_user_ids = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Participant {
|
message Participant {
|
||||||
@ -171,9 +173,21 @@ message ParticipantLocation {
|
|||||||
message External {}
|
message External {}
|
||||||
}
|
}
|
||||||
|
|
||||||
message Call {}
|
message Call {
|
||||||
|
uint64 room_id = 1;
|
||||||
|
uint64 to_user_id = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message CallResponse {}
|
message IncomingCall {
|
||||||
|
uint64 room_id = 1;
|
||||||
|
uint64 from_user_id = 2;
|
||||||
|
repeated uint64 participant_user_ids = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RespondToCall {
|
||||||
|
uint64 room_id = 1;
|
||||||
|
bool accept = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message RoomUpdated {
|
message RoomUpdated {
|
||||||
Room room = 1;
|
Room room = 1;
|
||||||
|
@ -83,6 +83,7 @@ messages!(
|
|||||||
(ApplyCompletionAdditionalEditsResponse, Background),
|
(ApplyCompletionAdditionalEditsResponse, Background),
|
||||||
(BufferReloaded, Foreground),
|
(BufferReloaded, Foreground),
|
||||||
(BufferSaved, Foreground),
|
(BufferSaved, Foreground),
|
||||||
|
(Call, Foreground),
|
||||||
(ChannelMessageSent, Foreground),
|
(ChannelMessageSent, Foreground),
|
||||||
(CopyProjectEntry, Foreground),
|
(CopyProjectEntry, Foreground),
|
||||||
(CreateBufferForPeer, Foreground),
|
(CreateBufferForPeer, Foreground),
|
||||||
@ -117,6 +118,7 @@ messages!(
|
|||||||
(GetProjectSymbols, Background),
|
(GetProjectSymbols, Background),
|
||||||
(GetProjectSymbolsResponse, Background),
|
(GetProjectSymbolsResponse, Background),
|
||||||
(GetUsers, Foreground),
|
(GetUsers, Foreground),
|
||||||
|
(IncomingCall, Foreground),
|
||||||
(UsersResponse, Foreground),
|
(UsersResponse, Foreground),
|
||||||
(JoinChannel, Foreground),
|
(JoinChannel, Foreground),
|
||||||
(JoinChannelResponse, Foreground),
|
(JoinChannelResponse, Foreground),
|
||||||
@ -151,6 +153,7 @@ messages!(
|
|||||||
(RequestJoinProject, Foreground),
|
(RequestJoinProject, Foreground),
|
||||||
(RespondToContactRequest, Foreground),
|
(RespondToContactRequest, Foreground),
|
||||||
(RespondToJoinProjectRequest, Foreground),
|
(RespondToJoinProjectRequest, Foreground),
|
||||||
|
(RoomUpdated, Foreground),
|
||||||
(SaveBuffer, Foreground),
|
(SaveBuffer, Foreground),
|
||||||
(SearchProject, Background),
|
(SearchProject, Background),
|
||||||
(SearchProjectResponse, Background),
|
(SearchProjectResponse, Background),
|
||||||
@ -179,6 +182,7 @@ request_messages!(
|
|||||||
ApplyCompletionAdditionalEdits,
|
ApplyCompletionAdditionalEdits,
|
||||||
ApplyCompletionAdditionalEditsResponse
|
ApplyCompletionAdditionalEditsResponse
|
||||||
),
|
),
|
||||||
|
(Call, Ack),
|
||||||
(CopyProjectEntry, ProjectEntryResponse),
|
(CopyProjectEntry, ProjectEntryResponse),
|
||||||
(CreateProjectEntry, ProjectEntryResponse),
|
(CreateProjectEntry, ProjectEntryResponse),
|
||||||
(CreateRoom, CreateRoomResponse),
|
(CreateRoom, CreateRoomResponse),
|
||||||
@ -200,6 +204,7 @@ request_messages!(
|
|||||||
(JoinChannel, JoinChannelResponse),
|
(JoinChannel, JoinChannelResponse),
|
||||||
(JoinProject, JoinProjectResponse),
|
(JoinProject, JoinProjectResponse),
|
||||||
(JoinRoom, JoinRoomResponse),
|
(JoinRoom, JoinRoomResponse),
|
||||||
|
(IncomingCall, Ack),
|
||||||
(OpenBufferById, OpenBufferResponse),
|
(OpenBufferById, OpenBufferResponse),
|
||||||
(OpenBufferByPath, OpenBufferResponse),
|
(OpenBufferByPath, OpenBufferResponse),
|
||||||
(OpenBufferForSymbol, OpenBufferForSymbolResponse),
|
(OpenBufferForSymbol, OpenBufferForSymbolResponse),
|
||||||
|
Loading…
Reference in New Issue
Block a user