Simplify room events

This commit is contained in:
Antonio Scandurra 2022-10-24 10:53:44 +02:00
parent f99d70500c
commit a8bd234aa4
3 changed files with 16 additions and 27 deletions

View file

@ -7,7 +7,7 @@ use client::{proto, Client, PeerId, TypedEnvelope, User, UserStore};
use collections::{BTreeMap, HashSet}; use collections::{BTreeMap, HashSet};
use futures::StreamExt; use futures::StreamExt;
use gpui::{AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task}; use gpui::{AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task};
use live_kit_client::{LocalTrackPublication, LocalVideoTrack, RemoteVideoTrackUpdate, Sid}; use live_kit_client::{LocalTrackPublication, LocalVideoTrack, RemoteVideoTrackUpdate};
use postage::stream::Stream; use postage::stream::Stream;
use project::Project; use project::Project;
use std::{mem, os::unix::prelude::OsStrExt, sync::Arc}; use std::{mem, os::unix::prelude::OsStrExt, sync::Arc};
@ -18,13 +18,8 @@ pub enum Event {
ParticipantLocationChanged { ParticipantLocationChanged {
participant_id: PeerId, participant_id: PeerId,
}, },
RemoteVideoTrackShared { RemoteVideoTracksChanged {
participant_id: PeerId, participant_id: PeerId,
track_id: Sid,
},
RemoteVideoTrackUnshared {
peer_id: PeerId,
track_id: Sid,
}, },
RemoteProjectShared { RemoteProjectShared {
owner: Arc<User>, owner: Arc<User>,
@ -448,9 +443,8 @@ impl Room {
live_kit_track: track, live_kit_track: track,
}), }),
); );
cx.emit(Event::RemoteVideoTrackShared { cx.emit(Event::RemoteVideoTracksChanged {
participant_id: peer_id, participant_id: peer_id,
track_id,
}); });
} }
RemoteVideoTrackUpdate::Unsubscribed { RemoteVideoTrackUpdate::Unsubscribed {
@ -463,7 +457,9 @@ impl Room {
.get_mut(&peer_id) .get_mut(&peer_id)
.ok_or_else(|| anyhow!("unsubscribed from track by unknown participant"))?; .ok_or_else(|| anyhow!("unsubscribed from track by unknown participant"))?;
participant.tracks.remove(&track_id); participant.tracks.remove(&track_id);
cx.emit(Event::RemoteVideoTrackUnshared { peer_id, track_id }); cx.emit(Event::RemoteVideoTracksChanged {
participant_id: peer_id,
});
} }
} }

View file

@ -203,16 +203,15 @@ async fn test_basic_calls(
assert_eq!(events_b.borrow().len(), 1); assert_eq!(events_b.borrow().len(), 1);
let event = events_b.borrow().first().unwrap().clone(); let event = events_b.borrow().first().unwrap().clone();
if let call::room::Event::RemoteVideoTrackShared { if let call::room::Event::RemoteVideoTracksChanged { participant_id } = event {
participant_id,
track_id,
} = event
{
assert_eq!(participant_id, client_a.peer_id().unwrap()); assert_eq!(participant_id, client_a.peer_id().unwrap());
room_b.read_with(cx_b, |room, _| { room_b.read_with(cx_b, |room, _| {
assert!(room.remote_participants()[&client_a.peer_id().unwrap()] assert_eq!(
.tracks room.remote_participants()[&client_a.peer_id().unwrap()]
.contains_key(&track_id)); .tracks
.len(),
1
);
}); });
} else { } else {
panic!("unexpected event") panic!("unexpected event")

View file

@ -2621,15 +2621,9 @@ impl Workspace {
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
match event { match event {
call::room::Event::ParticipantLocationChanged { call::room::Event::ParticipantLocationChanged { participant_id }
participant_id: peer_id, | call::room::Event::RemoteVideoTracksChanged { participant_id } => {
} self.leader_updated(*participant_id, cx);
| call::room::Event::RemoteVideoTrackShared {
participant_id: peer_id,
..
}
| call::room::Event::RemoteVideoTrackUnshared { peer_id, .. } => {
self.leader_updated(*peer_id, cx);
} }
_ => {} _ => {}
} }