Show shared screen as a pane item

This commit is contained in:
Antonio Scandurra 2022-10-24 10:04:08 +02:00
parent 7e411ae098
commit 476020ae84
10 changed files with 286 additions and 126 deletions

View file

@ -27,6 +27,7 @@ project = { path = "../project" }
util = { path = "../util" }
anyhow = "1.0.38"
async-broadcast = "0.4"
futures = "0.3"
postage = { version = "0.4.1", features = ["futures-traits"] }

View file

@ -1,4 +1,4 @@
mod participant;
pub mod participant;
pub mod room;
use anyhow::{anyhow, Result};

View file

@ -1,8 +1,8 @@
use anyhow::{anyhow, Result};
use client::{proto, User};
use collections::HashMap;
use gpui::{Task, WeakModelHandle};
use live_kit_client::Frame;
use gpui::WeakModelHandle;
pub use live_kit_client::Frame;
use project::Project;
use std::sync::Arc;
@ -41,18 +41,16 @@ pub struct RemoteParticipant {
pub user: Arc<User>,
pub projects: Vec<proto::ParticipantProject>,
pub location: ParticipantLocation,
pub tracks: HashMap<live_kit_client::Sid, RemoteVideoTrack>,
pub tracks: HashMap<live_kit_client::Sid, Arc<RemoteVideoTrack>>,
}
#[derive(Clone)]
pub struct RemoteVideoTrack {
pub(crate) frame: Option<Frame>,
pub(crate) _live_kit_track: Arc<live_kit_client::RemoteVideoTrack>,
pub(crate) _maintain_frame: Arc<Task<()>>,
pub(crate) live_kit_track: Arc<live_kit_client::RemoteVideoTrack>,
}
impl RemoteVideoTrack {
pub fn frame(&self) -> Option<&Frame> {
self.frame.as_ref()
pub fn frames(&self) -> async_broadcast::Receiver<Frame> {
self.live_kit_track.frames()
}
}

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};
use live_kit_client::{LocalTrackPublication, LocalVideoTrack, RemoteVideoTrackUpdate, Sid};
use postage::stream::Stream;
use project::Project;
use std::{mem, os::unix::prelude::OsStrExt, sync::Arc};
@ -15,9 +15,16 @@ use util::{post_inc, ResultExt};
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Event {
Frame {
ParticipantLocationChanged {
participant_id: PeerId,
track_id: live_kit_client::Sid,
},
RemoteVideoTrackShared {
participant_id: PeerId,
track_id: Sid,
},
RemoteVideoTrackUnshared {
peer_id: PeerId,
track_id: Sid,
},
RemoteProjectShared {
owner: Arc<User>,
@ -356,7 +363,12 @@ impl Room {
if let Some(remote_participant) = this.remote_participants.get_mut(&peer_id)
{
remote_participant.projects = participant.projects;
remote_participant.location = location;
if location != remote_participant.location {
remote_participant.location = location;
cx.emit(Event::ParticipantLocationChanged {
participant_id: peer_id,
});
}
} else {
this.remote_participants.insert(
peer_id,
@ -430,44 +442,16 @@ impl Room {
.remote_participants
.get_mut(&peer_id)
.ok_or_else(|| anyhow!("subscribed to track by unknown participant"))?;
let mut frames = track.frames();
participant.tracks.insert(
track_id.clone(),
RemoteVideoTrack {
frame: None,
_live_kit_track: track,
_maintain_frame: Arc::new(cx.spawn_weak(|this, mut cx| async move {
while let Some(frame) = frames.next().await {
let this = if let Some(this) = this.upgrade(&cx) {
this
} else {
break;
};
let done = this.update(&mut cx, |this, cx| {
if let Some(track) =
this.remote_participants.get_mut(&peer_id).and_then(
|participant| participant.tracks.get_mut(&track_id),
)
{
track.frame = Some(frame);
cx.emit(Event::Frame {
participant_id: peer_id,
track_id: track_id.clone(),
});
false
} else {
true
}
});
if done {
break;
}
}
})),
},
Arc::new(RemoteVideoTrack {
live_kit_track: track,
}),
);
cx.emit(Event::RemoteVideoTrackShared {
participant_id: peer_id,
track_id,
});
}
RemoteVideoTrackUpdate::Unsubscribed {
publisher_id,
@ -479,6 +463,7 @@ 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 });
}
}
@ -750,7 +735,7 @@ struct LiveKitRoom {
_maintain_tracks: Task<()>,
}
pub enum ScreenTrack {
enum ScreenTrack {
None,
Pending { publish_id: usize },
Published(LocalTrackPublication),