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 futures::StreamExt;
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 project::Project;
use std::{mem, os::unix::prelude::OsStrExt, sync::Arc};
@ -18,13 +18,8 @@ pub enum Event {
ParticipantLocationChanged {
participant_id: PeerId,
},
RemoteVideoTrackShared {
RemoteVideoTracksChanged {
participant_id: PeerId,
track_id: Sid,
},
RemoteVideoTrackUnshared {
peer_id: PeerId,
track_id: Sid,
},
RemoteProjectShared {
owner: Arc<User>,
@ -448,9 +443,8 @@ impl Room {
live_kit_track: track,
}),
);
cx.emit(Event::RemoteVideoTrackShared {
cx.emit(Event::RemoteVideoTracksChanged {
participant_id: peer_id,
track_id,
});
}
RemoteVideoTrackUpdate::Unsubscribed {
@ -463,7 +457,9 @@ impl Room {
.get_mut(&peer_id)
.ok_or_else(|| anyhow!("unsubscribed from track by unknown participant"))?;
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);
let event = events_b.borrow().first().unwrap().clone();
if let call::room::Event::RemoteVideoTrackShared {
participant_id,
track_id,
} = event
{
if let call::room::Event::RemoteVideoTracksChanged { participant_id } = event {
assert_eq!(participant_id, client_a.peer_id().unwrap());
room_b.read_with(cx_b, |room, _| {
assert!(room.remote_participants()[&client_a.peer_id().unwrap()]
.tracks
.contains_key(&track_id));
assert_eq!(
room.remote_participants()[&client_a.peer_id().unwrap()]
.tracks
.len(),
1
);
});
} else {
panic!("unexpected event")

View file

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