Add back room code to call2

This commit is contained in:
Mikayla 2023-11-01 09:29:54 -07:00
parent 51fa80ef06
commit 1568ecbe1e
No known key found for this signature in database
4 changed files with 350 additions and 383 deletions

View file

@ -1,10 +1,12 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use client2::ParticipantIndex; use client2::ParticipantIndex;
use client2::{proto, User}; use client2::{proto, User};
use collections::HashMap;
use gpui2::WeakModel; use gpui2::WeakModel;
pub use live_kit_client2::Frame; pub use live_kit_client2::Frame;
use live_kit_client2::{RemoteAudioTrack, RemoteVideoTrack};
use project2::Project; use project2::Project;
use std::{fmt, sync::Arc}; use std::sync::Arc;
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ParticipantLocation { pub enum ParticipantLocation {
@ -45,27 +47,6 @@ pub struct RemoteParticipant {
pub participant_index: ParticipantIndex, pub participant_index: ParticipantIndex,
pub muted: bool, pub muted: bool,
pub speaking: bool, pub speaking: bool,
// pub video_tracks: HashMap<live_kit_client::Sid, Arc<RemoteVideoTrack>>, pub video_tracks: HashMap<live_kit_client2::Sid, Arc<RemoteVideoTrack>>,
// pub audio_tracks: HashMap<live_kit_client::Sid, Arc<RemoteAudioTrack>>, pub audio_tracks: HashMap<live_kit_client2::Sid, Arc<RemoteAudioTrack>>,
}
#[derive(Clone)]
pub struct RemoteVideoTrack {
pub(crate) live_kit_track: Arc<live_kit_client2::RemoteVideoTrack>,
}
unsafe impl Send for RemoteVideoTrack {}
// todo!("remove this sync because it's not legit")
unsafe impl Sync for RemoteVideoTrack {}
impl fmt::Debug for RemoteVideoTrack {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RemoteVideoTrack").finish()
}
}
impl RemoteVideoTrack {
pub fn frames(&self) -> async_broadcast::Receiver<Frame> {
self.live_kit_track.frames()
}
} }

View file

@ -1,9 +1,6 @@
#![allow(dead_code, unused)]
// todo!()
use crate::{ use crate::{
call_settings::CallSettings, call_settings::CallSettings,
participant::{LocalParticipant, ParticipantLocation, RemoteParticipant, RemoteVideoTrack}, participant::{LocalParticipant, ParticipantLocation, RemoteParticipant},
IncomingCall, IncomingCall,
}; };
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
@ -19,12 +16,15 @@ use gpui2::{
AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task, WeakModel, AppContext, AsyncAppContext, Context, EventEmitter, Model, ModelContext, Task, WeakModel,
}; };
use language2::LanguageRegistry; use language2::LanguageRegistry;
use live_kit_client2::{LocalTrackPublication, RemoteAudioTrackUpdate, RemoteVideoTrackUpdate}; use live_kit_client2::{
LocalAudioTrack, LocalTrackPublication, LocalVideoTrack, RemoteAudioTrackUpdate,
RemoteVideoTrackUpdate,
};
use postage::{sink::Sink, stream::Stream, watch}; use postage::{sink::Sink, stream::Stream, watch};
use project2::Project; use project2::Project;
use settings2::Settings; use settings2::Settings;
use std::{future::Future, sync::Arc, time::Duration}; use std::{future::Future, mem, sync::Arc, time::Duration};
use util::{ResultExt, TryFutureExt}; use util::{post_inc, ResultExt, TryFutureExt};
pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(30); pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(30);
@ -95,15 +95,14 @@ impl Room {
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
pub fn is_connected(&self) -> bool { pub fn is_connected(&self) -> bool {
if let Some(live_kit) = self.live_kit.as_ref() {
matches!(
*live_kit.room.status().borrow(),
live_kit_client2::ConnectionState::Connected { .. }
)
} else {
false false
// if let Some(live_kit) = self.live_kit.as_ref() { }
// matches!(
// *live_kit.room.status().borrow(),
// live_kit_client::ConnectionState::Connected { .. }
// )
// } else {
// false
// }
} }
fn new( fn new(
@ -423,7 +422,7 @@ impl Room {
self.pending_participants.clear(); self.pending_participants.clear();
self.participant_user_ids.clear(); self.participant_user_ids.clear();
self.client_subscriptions.clear(); self.client_subscriptions.clear();
// self.live_kit.take(); self.live_kit.take();
self.pending_room_update.take(); self.pending_room_update.take();
self.maintain_connection.take(); self.maintain_connection.take();
} }
@ -799,43 +798,43 @@ impl Room {
location, location,
muted: true, muted: true,
speaking: false, speaking: false,
// video_tracks: Default::default(), video_tracks: Default::default(),
// audio_tracks: Default::default(), audio_tracks: Default::default(),
}, },
); );
Audio::play_sound(Sound::Joined, cx); Audio::play_sound(Sound::Joined, cx);
// if let Some(live_kit) = this.live_kit.as_ref() { if let Some(live_kit) = this.live_kit.as_ref() {
// let video_tracks = let video_tracks =
// live_kit.room.remote_video_tracks(&user.id.to_string()); live_kit.room.remote_video_tracks(&user.id.to_string());
// let audio_tracks = let audio_tracks =
// live_kit.room.remote_audio_tracks(&user.id.to_string()); live_kit.room.remote_audio_tracks(&user.id.to_string());
// let publications = live_kit let publications = live_kit
// .room .room
// .remote_audio_track_publications(&user.id.to_string()); .remote_audio_track_publications(&user.id.to_string());
// for track in video_tracks { for track in video_tracks {
// this.remote_video_track_updated( this.remote_video_track_updated(
// RemoteVideoTrackUpdate::Subscribed(track), RemoteVideoTrackUpdate::Subscribed(track),
// cx, cx,
// ) )
// .log_err(); .log_err();
// } }
// for (track, publication) in for (track, publication) in
// audio_tracks.iter().zip(publications.iter()) audio_tracks.iter().zip(publications.iter())
// { {
// this.remote_audio_track_updated( this.remote_audio_track_updated(
// RemoteAudioTrackUpdate::Subscribed( RemoteAudioTrackUpdate::Subscribed(
// track.clone(), track.clone(),
// publication.clone(), publication.clone(),
// ), ),
// cx, cx,
// ) )
// .log_err(); .log_err();
// } }
// } }
} }
} }
@ -923,7 +922,6 @@ impl Room {
change: RemoteVideoTrackUpdate, change: RemoteVideoTrackUpdate,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
todo!();
match change { match change {
RemoteVideoTrackUpdate::Subscribed(track) => { RemoteVideoTrackUpdate::Subscribed(track) => {
let user_id = track.publisher_id().parse()?; let user_id = track.publisher_id().parse()?;
@ -932,12 +930,7 @@ impl Room {
.remote_participants .remote_participants
.get_mut(&user_id) .get_mut(&user_id)
.ok_or_else(|| anyhow!("subscribed to track by unknown participant"))?; .ok_or_else(|| anyhow!("subscribed to track by unknown participant"))?;
// participant.video_tracks.insert( participant.video_tracks.insert(track_id.clone(), track);
// track_id.clone(),
// Arc::new(RemoteVideoTrack {
// live_kit_track: track,
// }),
// );
cx.emit(Event::RemoteVideoTracksChanged { cx.emit(Event::RemoteVideoTracksChanged {
participant_id: participant.peer_id, participant_id: participant.peer_id,
}); });
@ -951,7 +944,7 @@ impl Room {
.remote_participants .remote_participants
.get_mut(&user_id) .get_mut(&user_id)
.ok_or_else(|| anyhow!("unsubscribed from track by unknown participant"))?; .ok_or_else(|| anyhow!("unsubscribed from track by unknown participant"))?;
// participant.video_tracks.remove(&track_id); participant.video_tracks.remove(&track_id);
cx.emit(Event::RemoteVideoTracksChanged { cx.emit(Event::RemoteVideoTracksChanged {
participant_id: participant.peer_id, participant_id: participant.peer_id,
}); });
@ -981,65 +974,61 @@ impl Room {
participant.speaking = false; participant.speaking = false;
} }
} }
// todo!() if let Some(id) = self.client.user_id() {
// if let Some(id) = self.client.user_id() { if let Some(room) = &mut self.live_kit {
// if let Some(room) = &mut self.live_kit { if let Ok(_) = speaker_ids.binary_search(&id) {
// if let Ok(_) = speaker_ids.binary_search(&id) { room.speaking = true;
// room.speaking = true; } else {
// } else { room.speaking = false;
// room.speaking = false; }
// } }
// } }
// }
cx.notify(); cx.notify();
} }
RemoteAudioTrackUpdate::MuteChanged { track_id, muted } => { RemoteAudioTrackUpdate::MuteChanged { track_id, muted } => {
// todo!() let mut found = false;
// let mut found = false; for participant in &mut self.remote_participants.values_mut() {
// for participant in &mut self.remote_participants.values_mut() { for track in participant.audio_tracks.values() {
// for track in participant.audio_tracks.values() { if track.sid() == track_id {
// if track.sid() == track_id { found = true;
// found = true; break;
// break; }
// } }
// } if found {
// if found { participant.muted = muted;
// participant.muted = muted; break;
// break; }
// } }
// }
cx.notify(); cx.notify();
} }
RemoteAudioTrackUpdate::Subscribed(track, publication) => { RemoteAudioTrackUpdate::Subscribed(track, publication) => {
// todo!() let user_id = track.publisher_id().parse()?;
// let user_id = track.publisher_id().parse()?; let track_id = track.sid().to_string();
// let track_id = track.sid().to_string(); let participant = self
// let participant = self .remote_participants
// .remote_participants .get_mut(&user_id)
// .get_mut(&user_id) .ok_or_else(|| anyhow!("subscribed to track by unknown participant"))?;
// .ok_or_else(|| anyhow!("subscribed to track by unknown participant"))?; participant.audio_tracks.insert(track_id.clone(), track);
// // participant.audio_tracks.insert(track_id.clone(), track); participant.muted = publication.is_muted();
// participant.muted = publication.is_muted();
// cx.emit(Event::RemoteAudioTracksChanged { cx.emit(Event::RemoteAudioTracksChanged {
// participant_id: participant.peer_id, participant_id: participant.peer_id,
// }); });
} }
RemoteAudioTrackUpdate::Unsubscribed { RemoteAudioTrackUpdate::Unsubscribed {
publisher_id, publisher_id,
track_id, track_id,
} => { } => {
// todo!() let user_id = publisher_id.parse()?;
// let user_id = publisher_id.parse()?; let participant = self
// let participant = self .remote_participants
// .remote_participants .get_mut(&user_id)
// .get_mut(&user_id) .ok_or_else(|| anyhow!("unsubscribed from track by unknown participant"))?;
// .ok_or_else(|| anyhow!("unsubscribed from track by unknown participant"))?; participant.audio_tracks.remove(&track_id);
// participant.audio_tracks.remove(&track_id); cx.emit(Event::RemoteAudioTracksChanged {
// cx.emit(Event::RemoteAudioTracksChanged { participant_id: participant.peer_id,
// participant_id: participant.peer_id, });
// });
} }
} }
@ -1220,278 +1209,269 @@ impl Room {
} }
pub fn is_screen_sharing(&self) -> bool { pub fn is_screen_sharing(&self) -> bool {
todo!() self.live_kit.as_ref().map_or(false, |live_kit| {
// self.live_kit.as_ref().map_or(false, |live_kit| { !matches!(live_kit.screen_track, LocalTrack::None)
// !matches!(live_kit.screen_track, LocalTrack::None) })
// })
} }
pub fn is_sharing_mic(&self) -> bool { pub fn is_sharing_mic(&self) -> bool {
todo!() self.live_kit.as_ref().map_or(false, |live_kit| {
// self.live_kit.as_ref().map_or(false, |live_kit| { !matches!(live_kit.microphone_track, LocalTrack::None)
// !matches!(live_kit.microphone_track, LocalTrack::None) })
// })
} }
pub fn is_muted(&self, cx: &AppContext) -> bool { pub fn is_muted(&self, cx: &AppContext) -> bool {
todo!() self.live_kit
// self.live_kit .as_ref()
// .as_ref() .and_then(|live_kit| match &live_kit.microphone_track {
// .and_then(|live_kit| match &live_kit.microphone_track { LocalTrack::None => Some(Self::mute_on_join(cx)),
// LocalTrack::None => Some(Self::mute_on_join(cx)), LocalTrack::Pending { muted, .. } => Some(*muted),
// LocalTrack::Pending { muted, .. } => Some(*muted), LocalTrack::Published { muted, .. } => Some(*muted),
// LocalTrack::Published { muted, .. } => Some(*muted), })
// }) .unwrap_or(false)
// .unwrap_or(false)
} }
pub fn is_speaking(&self) -> bool { pub fn is_speaking(&self) -> bool {
todo!() self.live_kit
// self.live_kit .as_ref()
// .as_ref() .map_or(false, |live_kit| live_kit.speaking)
// .map_or(false, |live_kit| live_kit.speaking)
} }
pub fn is_deafened(&self) -> Option<bool> { pub fn is_deafened(&self) -> Option<bool> {
// self.live_kit.as_ref().map(|live_kit| live_kit.deafened) self.live_kit.as_ref().map(|live_kit| live_kit.deafened)
todo!()
} }
#[track_caller] #[track_caller]
pub fn share_microphone(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> { pub fn share_microphone(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
todo!() if self.status.is_offline() {
// if self.status.is_offline() { return Task::ready(Err(anyhow!("room is offline")));
// return Task::ready(Err(anyhow!("room is offline"))); } else if self.is_sharing_mic() {
// } else if self.is_sharing_mic() { return Task::ready(Err(anyhow!("microphone was already shared")));
// return Task::ready(Err(anyhow!("microphone was already shared"))); }
// }
// let publish_id = if let Some(live_kit) = self.live_kit.as_mut() { let publish_id = if let Some(live_kit) = self.live_kit.as_mut() {
// let publish_id = post_inc(&mut live_kit.next_publish_id); let publish_id = post_inc(&mut live_kit.next_publish_id);
// live_kit.microphone_track = LocalTrack::Pending { live_kit.microphone_track = LocalTrack::Pending {
// publish_id, publish_id,
// muted: false, muted: false,
// }; };
// cx.notify(); cx.notify();
// publish_id publish_id
// } else { } else {
// return Task::ready(Err(anyhow!("live-kit was not initialized"))); return Task::ready(Err(anyhow!("live-kit was not initialized")));
// }; };
// cx.spawn(move |this, mut cx| async move { cx.spawn(move |this, mut cx| async move {
// let publish_track = async { let publish_track = async {
// let track = LocalAudioTrack::create(); let track = LocalAudioTrack::create();
// this.upgrade() this.upgrade()
// .ok_or_else(|| anyhow!("room was dropped"))? .ok_or_else(|| anyhow!("room was dropped"))?
// .update(&mut cx, |this, _| { .update(&mut cx, |this, _| {
// this.live_kit this.live_kit
// .as_ref() .as_ref()
// .map(|live_kit| live_kit.room.publish_audio_track(track)) .map(|live_kit| live_kit.room.publish_audio_track(track))
// })? })?
// .ok_or_else(|| anyhow!("live-kit was not initialized"))? .ok_or_else(|| anyhow!("live-kit was not initialized"))?
// .await .await
// }; };
// let publication = publish_track.await; let publication = publish_track.await;
// this.upgrade() this.upgrade()
// .ok_or_else(|| anyhow!("room was dropped"))? .ok_or_else(|| anyhow!("room was dropped"))?
// .update(&mut cx, |this, cx| { .update(&mut cx, |this, cx| {
// let live_kit = this let live_kit = this
// .live_kit .live_kit
// .as_mut() .as_mut()
// .ok_or_else(|| anyhow!("live-kit was not initialized"))?; .ok_or_else(|| anyhow!("live-kit was not initialized"))?;
// let (canceled, muted) = if let LocalTrack::Pending { let (canceled, muted) = if let LocalTrack::Pending {
// publish_id: cur_publish_id, publish_id: cur_publish_id,
// muted, muted,
// } = &live_kit.microphone_track } = &live_kit.microphone_track
// { {
// (*cur_publish_id != publish_id, *muted) (*cur_publish_id != publish_id, *muted)
// } else { } else {
// (true, false) (true, false)
// }; };
// match publication { match publication {
// Ok(publication) => { Ok(publication) => {
// if canceled { if canceled {
// live_kit.room.unpublish_track(publication); live_kit.room.unpublish_track(publication);
// } else { } else {
// if muted { if muted {
// cx.executor().spawn(publication.set_mute(muted)).detach(); cx.executor().spawn(publication.set_mute(muted)).detach();
// } }
// live_kit.microphone_track = LocalTrack::Published { live_kit.microphone_track = LocalTrack::Published {
// track_publication: publication, track_publication: publication,
// muted, muted,
// }; };
// cx.notify(); cx.notify();
// } }
// Ok(()) Ok(())
// } }
// Err(error) => { Err(error) => {
// if canceled { if canceled {
// Ok(()) Ok(())
// } else { } else {
// live_kit.microphone_track = LocalTrack::None; live_kit.microphone_track = LocalTrack::None;
// cx.notify(); cx.notify();
// Err(error) Err(error)
// } }
// } }
// } }
// })? })?
// }) })
} }
pub fn share_screen(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> { pub fn share_screen(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
todo!() if self.status.is_offline() {
// if self.status.is_offline() { return Task::ready(Err(anyhow!("room is offline")));
// return Task::ready(Err(anyhow!("room is offline"))); } else if self.is_screen_sharing() {
// } else if self.is_screen_sharing() { return Task::ready(Err(anyhow!("screen was already shared")));
// return Task::ready(Err(anyhow!("screen was already shared"))); }
// }
// let (displays, publish_id) = if let Some(live_kit) = self.live_kit.as_mut() { let (displays, publish_id) = if let Some(live_kit) = self.live_kit.as_mut() {
// let publish_id = post_inc(&mut live_kit.next_publish_id); let publish_id = post_inc(&mut live_kit.next_publish_id);
// live_kit.screen_track = LocalTrack::Pending { live_kit.screen_track = LocalTrack::Pending {
// publish_id, publish_id,
// muted: false, muted: false,
// }; };
// cx.notify(); cx.notify();
// (live_kit.room.display_sources(), publish_id) (live_kit.room.display_sources(), publish_id)
// } else { } else {
// return Task::ready(Err(anyhow!("live-kit was not initialized"))); return Task::ready(Err(anyhow!("live-kit was not initialized")));
// }; };
// cx.spawn(move |this, mut cx| async move { cx.spawn_on_main(move |this, mut cx| async move {
// let publish_track = async { let publish_track = async {
// let displays = displays.await?; let displays = displays.await?;
// let display = displays let display = displays
// .first() .first()
// .ok_or_else(|| anyhow!("no display found"))?; .ok_or_else(|| anyhow!("no display found"))?;
// let track = LocalVideoTrack::screen_share_for_display(&display); let track = LocalVideoTrack::screen_share_for_display(&display);
// this.upgrade() this.upgrade()
// .ok_or_else(|| anyhow!("room was dropped"))? .ok_or_else(|| anyhow!("room was dropped"))?
// .update(&mut cx, |this, _| { .update(&mut cx, |this, _| {
// this.live_kit this.live_kit
// .as_ref() .as_ref()
// .map(|live_kit| live_kit.room.publish_video_track(track)) .map(|live_kit| live_kit.room.publish_video_track(track))
// })? })?
// .ok_or_else(|| anyhow!("live-kit was not initialized"))? .ok_or_else(|| anyhow!("live-kit was not initialized"))?
// .await .await
// }; };
// let publication = publish_track.await; let publication = publish_track.await;
// this.upgrade() this.upgrade()
// .ok_or_else(|| anyhow!("room was dropped"))? .ok_or_else(|| anyhow!("room was dropped"))?
// .update(&mut cx, |this, cx| { .update(&mut cx, |this, cx| {
// let live_kit = this let live_kit = this
// .live_kit .live_kit
// .as_mut() .as_mut()
// .ok_or_else(|| anyhow!("live-kit was not initialized"))?; .ok_or_else(|| anyhow!("live-kit was not initialized"))?;
// let (canceled, muted) = if let LocalTrack::Pending { let (canceled, muted) = if let LocalTrack::Pending {
// publish_id: cur_publish_id, publish_id: cur_publish_id,
// muted, muted,
// } = &live_kit.screen_track } = &live_kit.screen_track
// { {
// (*cur_publish_id != publish_id, *muted) (*cur_publish_id != publish_id, *muted)
// } else { } else {
// (true, false) (true, false)
// }; };
// match publication { match publication {
// Ok(publication) => { Ok(publication) => {
// if canceled { if canceled {
// live_kit.room.unpublish_track(publication); live_kit.room.unpublish_track(publication);
// } else { } else {
// if muted { if muted {
// cx.executor().spawn(publication.set_mute(muted)).detach(); cx.executor().spawn(publication.set_mute(muted)).detach();
// } }
// live_kit.screen_track = LocalTrack::Published { live_kit.screen_track = LocalTrack::Published {
// track_publication: publication, track_publication: publication,
// muted, muted,
// }; };
// cx.notify(); cx.notify();
// } }
// Audio::play_sound(Sound::StartScreenshare, cx); Audio::play_sound(Sound::StartScreenshare, cx);
// Ok(()) Ok(())
// } }
// Err(error) => { Err(error) => {
// if canceled { if canceled {
// Ok(()) Ok(())
// } else { } else {
// live_kit.screen_track = LocalTrack::None; live_kit.screen_track = LocalTrack::None;
// cx.notify(); cx.notify();
// Err(error) Err(error)
// } }
// } }
// } }
// })? })?
// }) })
} }
pub fn toggle_mute(&mut self, cx: &mut ModelContext<Self>) -> Result<Task<Result<()>>> { pub fn toggle_mute(&mut self, cx: &mut ModelContext<Self>) -> Result<Task<Result<()>>> {
todo!() let should_mute = !self.is_muted(cx);
// let should_mute = !self.is_muted(cx); if let Some(live_kit) = self.live_kit.as_mut() {
// if let Some(live_kit) = self.live_kit.as_mut() { if matches!(live_kit.microphone_track, LocalTrack::None) {
// if matches!(live_kit.microphone_track, LocalTrack::None) { return Ok(self.share_microphone(cx));
// return Ok(self.share_microphone(cx)); }
// }
// let (ret_task, old_muted) = live_kit.set_mute(should_mute, cx)?; let (ret_task, old_muted) = live_kit.set_mute(should_mute, cx)?;
// live_kit.muted_by_user = should_mute; live_kit.muted_by_user = should_mute;
// if old_muted == true && live_kit.deafened == true { if old_muted == true && live_kit.deafened == true {
// if let Some(task) = self.toggle_deafen(cx).ok() { if let Some(task) = self.toggle_deafen(cx).ok() {
// task.detach(); task.detach();
// } }
// } }
// Ok(ret_task) Ok(ret_task)
// } else { } else {
// Err(anyhow!("LiveKit not started")) Err(anyhow!("LiveKit not started"))
// } }
} }
pub fn toggle_deafen(&mut self, cx: &mut ModelContext<Self>) -> Result<Task<Result<()>>> { pub fn toggle_deafen(&mut self, cx: &mut ModelContext<Self>) -> Result<Task<Result<()>>> {
todo!() if let Some(live_kit) = self.live_kit.as_mut() {
// if let Some(live_kit) = self.live_kit.as_mut() { (*live_kit).deafened = !live_kit.deafened;
// (*live_kit).deafened = !live_kit.deafened;
// let mut tasks = Vec::with_capacity(self.remote_participants.len()); let mut tasks = Vec::with_capacity(self.remote_participants.len());
// // Context notification is sent within set_mute itself. // Context notification is sent within set_mute itself.
// let mut mute_task = None; let mut mute_task = None;
// // When deafening, mute user's mic as well. // When deafening, mute user's mic as well.
// // When undeafening, unmute user's mic unless it was manually muted prior to deafening. // When undeafening, unmute user's mic unless it was manually muted prior to deafening.
// if live_kit.deafened || !live_kit.muted_by_user { if live_kit.deafened || !live_kit.muted_by_user {
// mute_task = Some(live_kit.set_mute(live_kit.deafened, cx)?.0); mute_task = Some(live_kit.set_mute(live_kit.deafened, cx)?.0);
// }; };
// for participant in self.remote_participants.values() { for participant in self.remote_participants.values() {
// for track in live_kit for track in live_kit
// .room .room
// .remote_audio_track_publications(&participant.user.id.to_string()) .remote_audio_track_publications(&participant.user.id.to_string())
// { {
// let deafened = live_kit.deafened; let deafened = live_kit.deafened;
// tasks.push( tasks.push(
// cx.executor() cx.executor()
// .spawn_on_main(move || track.set_enabled(!deafened)), .spawn_on_main(move || track.set_enabled(!deafened)),
// ); );
// } }
// } }
// Ok(cx.executor().spawn_on_main(|| async { Ok(cx.executor().spawn_on_main(|| async {
// if let Some(mute_task) = mute_task { if let Some(mute_task) = mute_task {
// mute_task.await?; mute_task.await?;
// } }
// for task in tasks { for task in tasks {
// task.await?; task.await?;
// } }
// Ok(()) Ok(())
// })) }))
// } else { } else {
// Err(anyhow!("LiveKit not started")) Err(anyhow!("LiveKit not started"))
// } }
} }
pub fn unshare_screen(&mut self, cx: &mut ModelContext<Self>) -> Result<()> { pub fn unshare_screen(&mut self, cx: &mut ModelContext<Self>) -> Result<()> {
@ -1499,37 +1479,35 @@ impl Room {
return Err(anyhow!("room is offline")); return Err(anyhow!("room is offline"));
} }
todo!() let live_kit = self
// let live_kit = self .live_kit
// .live_kit .as_mut()
// .as_mut() .ok_or_else(|| anyhow!("live-kit was not initialized"))?;
// .ok_or_else(|| anyhow!("live-kit was not initialized"))?; match mem::take(&mut live_kit.screen_track) {
// match mem::take(&mut live_kit.screen_track) { LocalTrack::None => Err(anyhow!("screen was not shared")),
// LocalTrack::None => Err(anyhow!("screen was not shared")), LocalTrack::Pending { .. } => {
// LocalTrack::Pending { .. } => { cx.notify();
// cx.notify(); Ok(())
// Ok(()) }
// } LocalTrack::Published {
// LocalTrack::Published { track_publication, ..
// track_publication, .. } => {
// } => { live_kit.room.unpublish_track(track_publication);
// live_kit.room.unpublish_track(track_publication); cx.notify();
// cx.notify();
// Audio::play_sound(Sound::StopScreenshare, cx); Audio::play_sound(Sound::StopScreenshare, cx);
// Ok(()) Ok(())
// } }
// } }
} }
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
pub fn set_display_sources(&self, sources: Vec<live_kit_client2::MacOSDisplay>) { pub fn set_display_sources(&self, sources: Vec<live_kit_client2::MacOSDisplay>) {
todo!() self.live_kit
// self.live_kit .as_ref()
// .as_ref() .unwrap()
// .unwrap() .room
// .room .set_display_sources(sources);
// .set_display_sources(sources);
} }
} }

View file

@ -499,6 +499,10 @@ impl Room {
rx, rx,
) )
} }
pub fn set_display_sources(&self, _: Vec<MacOSDisplay>) {
unreachable!("This is a test-only function")
}
} }
impl Drop for Room { impl Drop for Room {

View file

@ -1,4 +1,4 @@
use anyhow::{anyhow, Result, Context}; use anyhow::{anyhow, Context, Result};
use async_trait::async_trait; use async_trait::async_trait;
use collections::{BTreeMap, HashMap}; use collections::{BTreeMap, HashMap};
use futures::Stream; use futures::Stream;
@ -364,7 +364,10 @@ impl Room {
let token = token.to_string(); let token = token.to_string();
async move { async move {
let server = TestServer::get(&url)?; let server = TestServer::get(&url)?;
server.join_room(token.clone(), this.clone()).await.context("room join")?; server
.join_room(token.clone(), this.clone())
.await
.context("room join")?;
*this.0.lock().connection.0.borrow_mut() = ConnectionState::Connected { url, token }; *this.0.lock().connection.0.borrow_mut() = ConnectionState::Connected { url, token };
Ok(()) Ok(())
} }
@ -547,6 +550,7 @@ impl LocalAudioTrack {
} }
} }
#[derive(Debug)]
pub struct RemoteVideoTrack { pub struct RemoteVideoTrack {
sid: Sid, sid: Sid,
publisher_id: Sid, publisher_id: Sid,