From 516236e044ac380697c2e590f640b6acc17099d2 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 26 Oct 2023 17:11:51 +0200 Subject: [PATCH] Disable livekit on zed2 --- crates/call/src/room.rs | 11 +- crates/call2/src/participant.rs | 6 +- crates/call2/src/room.rs | 909 ++++++++++++++++---------------- 3 files changed, 470 insertions(+), 456 deletions(-) diff --git a/crates/call/src/room.rs b/crates/call/src/room.rs index a3cd71c523..a550624761 100644 --- a/crates/call/src/room.rs +++ b/crates/call/src/room.rs @@ -1481,12 +1481,11 @@ impl Room { #[cfg(any(test, feature = "test-support"))] pub fn set_display_sources(&self, sources: Vec) { - todo!() - // self.live_kit - // .as_ref() - // .unwrap() - // .room - // .set_display_sources(sources); + self.live_kit + .as_ref() + .unwrap() + .room + .set_display_sources(sources); } } diff --git a/crates/call2/src/participant.rs b/crates/call2/src/participant.rs index 3f594ac944..c5c873a78a 100644 --- a/crates/call2/src/participant.rs +++ b/crates/call2/src/participant.rs @@ -1,10 +1,8 @@ use anyhow::{anyhow, Result}; use client2::ParticipantIndex; use client2::{proto, User}; -use collections::HashMap; use gpui2::WeakHandle; pub use live_kit_client::Frame; -use live_kit_client::RemoteAudioTrack; use project2::Project; use std::{fmt, sync::Arc}; @@ -47,8 +45,8 @@ pub struct RemoteParticipant { pub participant_index: ParticipantIndex, pub muted: bool, pub speaking: bool, - pub video_tracks: HashMap>, - pub audio_tracks: HashMap>, + // pub video_tracks: HashMap>, + // pub audio_tracks: HashMap>, } #[derive(Clone)] diff --git a/crates/call2/src/room.rs b/crates/call2/src/room.rs index 9aa91153d3..639191123f 100644 --- a/crates/call2/src/room.rs +++ b/crates/call2/src/room.rs @@ -1,3 +1,6 @@ +#![allow(dead_code, unused)] +// todo!() + use crate::{ call_settings::CallSettings, participant::{LocalParticipant, ParticipantLocation, RemoteParticipant, RemoteVideoTrack}, @@ -16,15 +19,12 @@ use gpui2::{ AppContext, AsyncAppContext, Context, EventEmitter, Handle, ModelContext, Task, WeakHandle, }; use language2::LanguageRegistry; -use live_kit_client::{ - LocalAudioTrack, LocalTrackPublication, LocalVideoTrack, RemoteAudioTrackUpdate, - RemoteVideoTrackUpdate, -}; +use live_kit_client::{LocalTrackPublication, RemoteAudioTrackUpdate, RemoteVideoTrackUpdate}; use postage::{sink::Sink, stream::Stream, watch}; use project2::Project; use settings2::Settings; -use std::{future::Future, mem, sync::Arc, time::Duration}; -use util::{post_inc, ResultExt, TryFutureExt}; +use std::{future::Future, sync::Arc, time::Duration}; +use util::{ResultExt, TryFutureExt}; pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(30); @@ -59,7 +59,7 @@ pub enum Event { pub struct Room { id: u64, channel_id: Option, - live_kit: Option, + // live_kit: Option, status: RoomStatus, shared_projects: HashSet>, joined_projects: HashSet>, @@ -95,14 +95,15 @@ impl Room { #[cfg(any(test, feature = "test-support"))] pub fn is_connected(&self) -> bool { - if let Some(live_kit) = self.live_kit.as_ref() { - matches!( - *live_kit.room.status().borrow(), - live_kit_client::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( @@ -113,124 +114,125 @@ impl Room { user_store: Handle, cx: &mut ModelContext, ) -> Self { - let live_kit_room = if let Some(connection_info) = live_kit_connection_info { - let room = live_kit_client::Room::new(); - let mut status = room.status(); - // Consume the initial status of the room. - let _ = status.try_recv(); - let _maintain_room = cx.spawn(|this, mut cx| async move { - while let Some(status) = status.next().await { - let this = if let Some(this) = this.upgrade() { - this - } else { - break; - }; + todo!() + // let _live_kit_room = if let Some(connection_info) = live_kit_connection_info { + // let room = live_kit_client::Room::new(); + // let mut status = room.status(); + // // Consume the initial status of the room. + // let _ = status.try_recv(); + // let _maintain_room = cx.spawn(|this, mut cx| async move { + // while let Some(status) = status.next().await { + // let this = if let Some(this) = this.upgrade() { + // this + // } else { + // break; + // }; - if status == live_kit_client::ConnectionState::Disconnected { - this.update(&mut cx, |this, cx| this.leave(cx).log_err()) - .ok(); - break; - } - } - }); + // if status == live_kit_client::ConnectionState::Disconnected { + // this.update(&mut cx, |this, cx| this.leave(cx).log_err()) + // .ok(); + // break; + // } + // } + // }); - let mut track_video_changes = room.remote_video_track_updates(); - let _maintain_video_tracks = cx.spawn(|this, mut cx| async move { - while let Some(track_change) = track_video_changes.next().await { - let this = if let Some(this) = this.upgrade() { - this - } else { - break; - }; + // let mut track_video_changes = room.remote_video_track_updates(); + // let _maintain_video_tracks = cx.spawn(|this, mut cx| async move { + // while let Some(track_change) = track_video_changes.next().await { + // let this = if let Some(this) = this.upgrade() { + // this + // } else { + // break; + // }; - this.update(&mut cx, |this, cx| { - this.remote_video_track_updated(track_change, cx).log_err() - }) - .ok(); - } - }); + // this.update(&mut cx, |this, cx| { + // this.remote_video_track_updated(track_change, cx).log_err() + // }) + // .ok(); + // } + // }); - let mut track_audio_changes = room.remote_audio_track_updates(); - let _maintain_audio_tracks = cx.spawn(|this, mut cx| async move { - while let Some(track_change) = track_audio_changes.next().await { - let this = if let Some(this) = this.upgrade() { - this - } else { - break; - }; + // let mut track_audio_changes = room.remote_audio_track_updates(); + // let _maintain_audio_tracks = cx.spawn(|this, mut cx| async move { + // while let Some(track_change) = track_audio_changes.next().await { + // let this = if let Some(this) = this.upgrade() { + // this + // } else { + // break; + // }; - this.update(&mut cx, |this, cx| { - this.remote_audio_track_updated(track_change, cx).log_err() - }) - .ok(); - } - }); + // this.update(&mut cx, |this, cx| { + // this.remote_audio_track_updated(track_change, cx).log_err() + // }) + // .ok(); + // } + // }); - let connect = room.connect(&connection_info.server_url, &connection_info.token); - cx.spawn(|this, mut cx| async move { - connect.await?; + // let connect = room.connect(&connection_info.server_url, &connection_info.token); + // cx.spawn(|this, mut cx| async move { + // connect.await?; - if !cx.update(|cx| Self::mute_on_join(cx))? { - this.update(&mut cx, |this, cx| this.share_microphone(cx))? - .await?; - } + // if !cx.update(|cx| Self::mute_on_join(cx))? { + // this.update(&mut cx, |this, cx| this.share_microphone(cx))? + // .await?; + // } - anyhow::Ok(()) - }) - .detach_and_log_err(cx); + // anyhow::Ok(()) + // }) + // .detach_and_log_err(cx); - Some(LiveKitRoom { - room, - screen_track: LocalTrack::None, - microphone_track: LocalTrack::None, - next_publish_id: 0, - muted_by_user: false, - deafened: false, - speaking: false, - _maintain_room, - _maintain_tracks: [_maintain_video_tracks, _maintain_audio_tracks], - }) - } else { - None - }; + // Some(LiveKitRoom { + // room, + // screen_track: LocalTrack::None, + // microphone_track: LocalTrack::None, + // next_publish_id: 0, + // muted_by_user: false, + // deafened: false, + // speaking: false, + // _maintain_room, + // _maintain_tracks: [_maintain_video_tracks, _maintain_audio_tracks], + // }) + // } else { + // None + // }; - let maintain_connection = cx.spawn({ - let client = client.clone(); - move |this, cx| Self::maintain_connection(this, client.clone(), cx).log_err() - }); + // let maintain_connection = cx.spawn({ + // let client = client.clone(); + // move |this, cx| Self::maintain_connection(this, client.clone(), cx).log_err() + // }); - Audio::play_sound(Sound::Joined, cx); + // Audio::play_sound(Sound::Joined, cx); - let (room_update_completed_tx, room_update_completed_rx) = watch::channel(); + // let (room_update_completed_tx, room_update_completed_rx) = watch::channel(); - Self { - id, - channel_id, - live_kit: live_kit_room, - status: RoomStatus::Online, - shared_projects: Default::default(), - joined_projects: Default::default(), - participant_user_ids: Default::default(), - local_participant: Default::default(), - remote_participants: Default::default(), - pending_participants: Default::default(), - pending_call_count: 0, - client_subscriptions: vec![ - client.add_message_handler(cx.weak_handle(), Self::handle_room_updated) - ], - _subscriptions: vec![ - cx.on_release(Self::released), - cx.on_app_quit(Self::app_will_quit), - ], - leave_when_empty: false, - pending_room_update: None, - client, - user_store, - follows_by_leader_id_project_id: Default::default(), - maintain_connection: Some(maintain_connection), - room_update_completed_tx, - room_update_completed_rx, - } + // Self { + // id, + // channel_id, + // // live_kit: live_kit_room, + // status: RoomStatus::Online, + // shared_projects: Default::default(), + // joined_projects: Default::default(), + // participant_user_ids: Default::default(), + // local_participant: Default::default(), + // remote_participants: Default::default(), + // pending_participants: Default::default(), + // pending_call_count: 0, + // client_subscriptions: vec![ + // client.add_message_handler(cx.weak_handle(), Self::handle_room_updated) + // ], + // _subscriptions: vec![ + // cx.on_release(Self::released), + // cx.on_app_quit(Self::app_will_quit), + // ], + // leave_when_empty: false, + // pending_room_update: None, + // client, + // user_store, + // follows_by_leader_id_project_id: Default::default(), + // maintain_connection: Some(maintain_connection), + // room_update_completed_tx, + // room_update_completed_rx, + // } } pub(crate) fn create( @@ -416,7 +418,7 @@ impl Room { self.pending_participants.clear(); self.participant_user_ids.clear(); self.client_subscriptions.clear(); - self.live_kit.take(); + // self.live_kit.take(); self.pending_room_update.take(); self.maintain_connection.take(); } @@ -792,43 +794,43 @@ impl Room { location, muted: true, speaking: false, - video_tracks: Default::default(), - audio_tracks: Default::default(), + // video_tracks: Default::default(), + // audio_tracks: Default::default(), }, ); Audio::play_sound(Sound::Joined, cx); - if let Some(live_kit) = this.live_kit.as_ref() { - let video_tracks = - live_kit.room.remote_video_tracks(&user.id.to_string()); - let audio_tracks = - live_kit.room.remote_audio_tracks(&user.id.to_string()); - let publications = live_kit - .room - .remote_audio_track_publications(&user.id.to_string()); + // if let Some(live_kit) = this.live_kit.as_ref() { + // let video_tracks = + // live_kit.room.remote_video_tracks(&user.id.to_string()); + // let audio_tracks = + // live_kit.room.remote_audio_tracks(&user.id.to_string()); + // let publications = live_kit + // .room + // .remote_audio_track_publications(&user.id.to_string()); - for track in video_tracks { - this.remote_video_track_updated( - RemoteVideoTrackUpdate::Subscribed(track), - cx, - ) - .log_err(); - } + // for track in video_tracks { + // this.remote_video_track_updated( + // RemoteVideoTrackUpdate::Subscribed(track), + // cx, + // ) + // .log_err(); + // } - for (track, publication) in - audio_tracks.iter().zip(publications.iter()) - { - this.remote_audio_track_updated( - RemoteAudioTrackUpdate::Subscribed( - track.clone(), - publication.clone(), - ), - cx, - ) - .log_err(); - } - } + // for (track, publication) in + // audio_tracks.iter().zip(publications.iter()) + // { + // this.remote_audio_track_updated( + // RemoteAudioTrackUpdate::Subscribed( + // track.clone(), + // publication.clone(), + // ), + // cx, + // ) + // .log_err(); + // } + // } } } @@ -916,6 +918,7 @@ impl Room { change: RemoteVideoTrackUpdate, cx: &mut ModelContext, ) -> Result<()> { + todo!(); match change { RemoteVideoTrackUpdate::Subscribed(track) => { let user_id = track.publisher_id().parse()?; @@ -924,12 +927,12 @@ impl Room { .remote_participants .get_mut(&user_id) .ok_or_else(|| anyhow!("subscribed to track by unknown participant"))?; - participant.video_tracks.insert( - track_id.clone(), - Arc::new(RemoteVideoTrack { - live_kit_track: track, - }), - ); + // participant.video_tracks.insert( + // track_id.clone(), + // Arc::new(RemoteVideoTrack { + // live_kit_track: track, + // }), + // ); cx.emit(Event::RemoteVideoTracksChanged { participant_id: participant.peer_id, }); @@ -943,7 +946,7 @@ impl Room { .remote_participants .get_mut(&user_id) .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 { participant_id: participant.peer_id, }); @@ -973,62 +976,65 @@ impl Room { participant.speaking = false; } } - if let Some(id) = self.client.user_id() { - if let Some(room) = &mut self.live_kit { - if let Ok(_) = speaker_ids.binary_search(&id) { - room.speaking = true; - } else { - room.speaking = false; - } - } - } + // todo!() + // if let Some(id) = self.client.user_id() { + // if let Some(room) = &mut self.live_kit { + // if let Ok(_) = speaker_ids.binary_search(&id) { + // room.speaking = true; + // } else { + // room.speaking = false; + // } + // } + // } cx.notify(); } RemoteAudioTrackUpdate::MuteChanged { track_id, muted } => { - let mut found = false; - for participant in &mut self.remote_participants.values_mut() { - for track in participant.audio_tracks.values() { - if track.sid() == track_id { - found = true; - break; - } - } - if found { - participant.muted = muted; - break; - } - } + // todo!() + // let mut found = false; + // for participant in &mut self.remote_participants.values_mut() { + // for track in participant.audio_tracks.values() { + // if track.sid() == track_id { + // found = true; + // break; + // } + // } + // if found { + // participant.muted = muted; + // break; + // } + // } cx.notify(); } RemoteAudioTrackUpdate::Subscribed(track, publication) => { - let user_id = track.publisher_id().parse()?; - let track_id = track.sid().to_string(); - let participant = self - .remote_participants - .get_mut(&user_id) - .ok_or_else(|| anyhow!("subscribed to track by unknown participant"))?; + // todo!() + // let user_id = track.publisher_id().parse()?; + // let track_id = track.sid().to_string(); + // let participant = self + // .remote_participants + // .get_mut(&user_id) + // .ok_or_else(|| anyhow!("subscribed to track by unknown participant"))?; + // // participant.audio_tracks.insert(track_id.clone(), track); + // participant.muted = publication.is_muted(); - participant.audio_tracks.insert(track_id.clone(), track); - participant.muted = publication.is_muted(); - - cx.emit(Event::RemoteAudioTracksChanged { - participant_id: participant.peer_id, - }); + // cx.emit(Event::RemoteAudioTracksChanged { + // participant_id: participant.peer_id, + // }); } RemoteAudioTrackUpdate::Unsubscribed { publisher_id, track_id, } => { - let user_id = publisher_id.parse()?; - let participant = self - .remote_participants - .get_mut(&user_id) - .ok_or_else(|| anyhow!("unsubscribed from track by unknown participant"))?; - participant.audio_tracks.remove(&track_id); - cx.emit(Event::RemoteAudioTracksChanged { - participant_id: participant.peer_id, - }); + // todo!() + // let user_id = publisher_id.parse()?; + // let participant = self + // .remote_participants + // .get_mut(&user_id) + // .ok_or_else(|| anyhow!("unsubscribed from track by unknown participant"))?; + // participant.audio_tracks.remove(&track_id); + // cx.emit(Event::RemoteAudioTracksChanged { + // participant_id: participant.peer_id, + // }); } } @@ -1209,269 +1215,278 @@ impl Room { } pub fn is_screen_sharing(&self) -> bool { - self.live_kit.as_ref().map_or(false, |live_kit| { - !matches!(live_kit.screen_track, LocalTrack::None) - }) + todo!() + // self.live_kit.as_ref().map_or(false, |live_kit| { + // !matches!(live_kit.screen_track, LocalTrack::None) + // }) } pub fn is_sharing_mic(&self) -> bool { - self.live_kit.as_ref().map_or(false, |live_kit| { - !matches!(live_kit.microphone_track, LocalTrack::None) - }) + todo!() + // self.live_kit.as_ref().map_or(false, |live_kit| { + // !matches!(live_kit.microphone_track, LocalTrack::None) + // }) } pub fn is_muted(&self, cx: &AppContext) -> bool { - self.live_kit - .as_ref() - .and_then(|live_kit| match &live_kit.microphone_track { - LocalTrack::None => Some(Self::mute_on_join(cx)), - LocalTrack::Pending { muted, .. } => Some(*muted), - LocalTrack::Published { muted, .. } => Some(*muted), - }) - .unwrap_or(false) + todo!() + // self.live_kit + // .as_ref() + // .and_then(|live_kit| match &live_kit.microphone_track { + // LocalTrack::None => Some(Self::mute_on_join(cx)), + // LocalTrack::Pending { muted, .. } => Some(*muted), + // LocalTrack::Published { muted, .. } => Some(*muted), + // }) + // .unwrap_or(false) } pub fn is_speaking(&self) -> bool { - self.live_kit - .as_ref() - .map_or(false, |live_kit| live_kit.speaking) + todo!() + // self.live_kit + // .as_ref() + // .map_or(false, |live_kit| live_kit.speaking) } pub fn is_deafened(&self) -> Option { - 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] pub fn share_microphone(&mut self, cx: &mut ModelContext) -> Task> { - if self.status.is_offline() { - return Task::ready(Err(anyhow!("room is offline"))); - } else if self.is_sharing_mic() { - return Task::ready(Err(anyhow!("microphone was already shared"))); - } + todo!() + // if self.status.is_offline() { + // return Task::ready(Err(anyhow!("room is offline"))); + // } else if self.is_sharing_mic() { + // 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 = post_inc(&mut live_kit.next_publish_id); - live_kit.microphone_track = LocalTrack::Pending { - publish_id, - muted: false, - }; - cx.notify(); - publish_id - } else { - return Task::ready(Err(anyhow!("live-kit was not initialized"))); - }; + // let publish_id = if let Some(live_kit) = self.live_kit.as_mut() { + // let publish_id = post_inc(&mut live_kit.next_publish_id); + // live_kit.microphone_track = LocalTrack::Pending { + // publish_id, + // muted: false, + // }; + // cx.notify(); + // publish_id + // } else { + // return Task::ready(Err(anyhow!("live-kit was not initialized"))); + // }; - cx.spawn(move |this, mut cx| async move { - let publish_track = async { - let track = LocalAudioTrack::create(); - this.upgrade() - .ok_or_else(|| anyhow!("room was dropped"))? - .update(&mut cx, |this, _| { - this.live_kit - .as_ref() - .map(|live_kit| live_kit.room.publish_audio_track(track)) - })? - .ok_or_else(|| anyhow!("live-kit was not initialized"))? - .await - }; + // cx.spawn(move |this, mut cx| async move { + // let publish_track = async { + // let track = LocalAudioTrack::create(); + // this.upgrade() + // .ok_or_else(|| anyhow!("room was dropped"))? + // .update(&mut cx, |this, _| { + // this.live_kit + // .as_ref() + // .map(|live_kit| live_kit.room.publish_audio_track(track)) + // })? + // .ok_or_else(|| anyhow!("live-kit was not initialized"))? + // .await + // }; - let publication = publish_track.await; - this.upgrade() - .ok_or_else(|| anyhow!("room was dropped"))? - .update(&mut cx, |this, cx| { - let live_kit = this - .live_kit - .as_mut() - .ok_or_else(|| anyhow!("live-kit was not initialized"))?; + // let publication = publish_track.await; + // this.upgrade() + // .ok_or_else(|| anyhow!("room was dropped"))? + // .update(&mut cx, |this, cx| { + // let live_kit = this + // .live_kit + // .as_mut() + // .ok_or_else(|| anyhow!("live-kit was not initialized"))?; - let (canceled, muted) = if let LocalTrack::Pending { - publish_id: cur_publish_id, - muted, - } = &live_kit.microphone_track - { - (*cur_publish_id != publish_id, *muted) - } else { - (true, false) - }; + // let (canceled, muted) = if let LocalTrack::Pending { + // publish_id: cur_publish_id, + // muted, + // } = &live_kit.microphone_track + // { + // (*cur_publish_id != publish_id, *muted) + // } else { + // (true, false) + // }; - match publication { - Ok(publication) => { - if canceled { - live_kit.room.unpublish_track(publication); - } else { - if muted { - cx.executor().spawn(publication.set_mute(muted)).detach(); - } - live_kit.microphone_track = LocalTrack::Published { - track_publication: publication, - muted, - }; - cx.notify(); - } - Ok(()) - } - Err(error) => { - if canceled { - Ok(()) - } else { - live_kit.microphone_track = LocalTrack::None; - cx.notify(); - Err(error) - } - } - } - })? - }) + // match publication { + // Ok(publication) => { + // if canceled { + // live_kit.room.unpublish_track(publication); + // } else { + // if muted { + // cx.executor().spawn(publication.set_mute(muted)).detach(); + // } + // live_kit.microphone_track = LocalTrack::Published { + // track_publication: publication, + // muted, + // }; + // cx.notify(); + // } + // Ok(()) + // } + // Err(error) => { + // if canceled { + // Ok(()) + // } else { + // live_kit.microphone_track = LocalTrack::None; + // cx.notify(); + // Err(error) + // } + // } + // } + // })? + // }) } pub fn share_screen(&mut self, cx: &mut ModelContext) -> Task> { - if self.status.is_offline() { - return Task::ready(Err(anyhow!("room is offline"))); - } else if self.is_screen_sharing() { - return Task::ready(Err(anyhow!("screen was already shared"))); - } + todo!() + // if self.status.is_offline() { + // return Task::ready(Err(anyhow!("room is offline"))); + // } else if self.is_screen_sharing() { + // return Task::ready(Err(anyhow!("screen was already shared"))); + // } - 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); - live_kit.screen_track = LocalTrack::Pending { - publish_id, - muted: false, - }; - cx.notify(); - (live_kit.room.display_sources(), publish_id) - } else { - return Task::ready(Err(anyhow!("live-kit was not initialized"))); - }; + // 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); + // live_kit.screen_track = LocalTrack::Pending { + // publish_id, + // muted: false, + // }; + // cx.notify(); + // (live_kit.room.display_sources(), publish_id) + // } else { + // return Task::ready(Err(anyhow!("live-kit was not initialized"))); + // }; - cx.spawn(move |this, mut cx| async move { - let publish_track = async { - let displays = displays.await?; - let display = displays - .first() - .ok_or_else(|| anyhow!("no display found"))?; - let track = LocalVideoTrack::screen_share_for_display(&display); - this.upgrade() - .ok_or_else(|| anyhow!("room was dropped"))? - .update(&mut cx, |this, _| { - this.live_kit - .as_ref() - .map(|live_kit| live_kit.room.publish_video_track(track)) - })? - .ok_or_else(|| anyhow!("live-kit was not initialized"))? - .await - }; + // cx.spawn(move |this, mut cx| async move { + // let publish_track = async { + // let displays = displays.await?; + // let display = displays + // .first() + // .ok_or_else(|| anyhow!("no display found"))?; + // let track = LocalVideoTrack::screen_share_for_display(&display); + // this.upgrade() + // .ok_or_else(|| anyhow!("room was dropped"))? + // .update(&mut cx, |this, _| { + // this.live_kit + // .as_ref() + // .map(|live_kit| live_kit.room.publish_video_track(track)) + // })? + // .ok_or_else(|| anyhow!("live-kit was not initialized"))? + // .await + // }; - let publication = publish_track.await; - this.upgrade() - .ok_or_else(|| anyhow!("room was dropped"))? - .update(&mut cx, |this, cx| { - let live_kit = this - .live_kit - .as_mut() - .ok_or_else(|| anyhow!("live-kit was not initialized"))?; + // let publication = publish_track.await; + // this.upgrade() + // .ok_or_else(|| anyhow!("room was dropped"))? + // .update(&mut cx, |this, cx| { + // let live_kit = this + // .live_kit + // .as_mut() + // .ok_or_else(|| anyhow!("live-kit was not initialized"))?; - let (canceled, muted) = if let LocalTrack::Pending { - publish_id: cur_publish_id, - muted, - } = &live_kit.screen_track - { - (*cur_publish_id != publish_id, *muted) - } else { - (true, false) - }; + // let (canceled, muted) = if let LocalTrack::Pending { + // publish_id: cur_publish_id, + // muted, + // } = &live_kit.screen_track + // { + // (*cur_publish_id != publish_id, *muted) + // } else { + // (true, false) + // }; - match publication { - Ok(publication) => { - if canceled { - live_kit.room.unpublish_track(publication); - } else { - if muted { - cx.executor().spawn(publication.set_mute(muted)).detach(); - } - live_kit.screen_track = LocalTrack::Published { - track_publication: publication, - muted, - }; - cx.notify(); - } + // match publication { + // Ok(publication) => { + // if canceled { + // live_kit.room.unpublish_track(publication); + // } else { + // if muted { + // cx.executor().spawn(publication.set_mute(muted)).detach(); + // } + // live_kit.screen_track = LocalTrack::Published { + // track_publication: publication, + // muted, + // }; + // cx.notify(); + // } - Audio::play_sound(Sound::StartScreenshare, cx); + // Audio::play_sound(Sound::StartScreenshare, cx); - Ok(()) - } - Err(error) => { - if canceled { - Ok(()) - } else { - live_kit.screen_track = LocalTrack::None; - cx.notify(); - Err(error) - } - } - } - })? - }) + // Ok(()) + // } + // Err(error) => { + // if canceled { + // Ok(()) + // } else { + // live_kit.screen_track = LocalTrack::None; + // cx.notify(); + // Err(error) + // } + // } + // } + // })? + // }) } pub fn toggle_mute(&mut self, cx: &mut ModelContext) -> Result>> { - let should_mute = !self.is_muted(cx); - if let Some(live_kit) = self.live_kit.as_mut() { - if matches!(live_kit.microphone_track, LocalTrack::None) { - return Ok(self.share_microphone(cx)); - } + todo!() + // let should_mute = !self.is_muted(cx); + // if let Some(live_kit) = self.live_kit.as_mut() { + // if matches!(live_kit.microphone_track, LocalTrack::None) { + // return Ok(self.share_microphone(cx)); + // } - let (ret_task, old_muted) = live_kit.set_mute(should_mute, cx)?; - live_kit.muted_by_user = should_mute; + // let (ret_task, old_muted) = live_kit.set_mute(should_mute, cx)?; + // live_kit.muted_by_user = should_mute; - if old_muted == true && live_kit.deafened == true { - if let Some(task) = self.toggle_deafen(cx).ok() { - task.detach(); - } - } + // if old_muted == true && live_kit.deafened == true { + // if let Some(task) = self.toggle_deafen(cx).ok() { + // task.detach(); + // } + // } - Ok(ret_task) - } else { - Err(anyhow!("LiveKit not started")) - } + // Ok(ret_task) + // } else { + // Err(anyhow!("LiveKit not started")) + // } } pub fn toggle_deafen(&mut self, cx: &mut ModelContext) -> Result>> { - if let Some(live_kit) = self.live_kit.as_mut() { - (*live_kit).deafened = !live_kit.deafened; + todo!() + // if let Some(live_kit) = self.live_kit.as_mut() { + // (*live_kit).deafened = !live_kit.deafened; - let mut tasks = Vec::with_capacity(self.remote_participants.len()); - // Context notification is sent within set_mute itself. - let mut mute_task = None; - // When deafening, mute user's mic as well. - // When undeafening, unmute user's mic unless it was manually muted prior to deafening. - if live_kit.deafened || !live_kit.muted_by_user { - mute_task = Some(live_kit.set_mute(live_kit.deafened, cx)?.0); - }; - for participant in self.remote_participants.values() { - for track in live_kit - .room - .remote_audio_track_publications(&participant.user.id.to_string()) - { - let deafened = live_kit.deafened; - tasks.push( - cx.executor() - .spawn_on_main(move || track.set_enabled(!deafened)), - ); - } - } + // let mut tasks = Vec::with_capacity(self.remote_participants.len()); + // // Context notification is sent within set_mute itself. + // let mut mute_task = None; + // // When deafening, mute user's mic as well. + // // When undeafening, unmute user's mic unless it was manually muted prior to deafening. + // if live_kit.deafened || !live_kit.muted_by_user { + // mute_task = Some(live_kit.set_mute(live_kit.deafened, cx)?.0); + // }; + // for participant in self.remote_participants.values() { + // for track in live_kit + // .room + // .remote_audio_track_publications(&participant.user.id.to_string()) + // { + // let deafened = live_kit.deafened; + // tasks.push( + // cx.executor() + // .spawn_on_main(move || track.set_enabled(!deafened)), + // ); + // } + // } - Ok(cx.executor().spawn_on_main(|| async { - if let Some(mute_task) = mute_task { - mute_task.await?; - } - for task in tasks { - task.await?; - } - Ok(()) - })) - } else { - Err(anyhow!("LiveKit not started")) - } + // Ok(cx.executor().spawn_on_main(|| async { + // if let Some(mute_task) = mute_task { + // mute_task.await?; + // } + // for task in tasks { + // task.await?; + // } + // Ok(()) + // })) + // } else { + // Err(anyhow!("LiveKit not started")) + // } } pub fn unshare_screen(&mut self, cx: &mut ModelContext) -> Result<()> { @@ -1479,35 +1494,37 @@ impl Room { return Err(anyhow!("room is offline")); } - let live_kit = self - .live_kit - .as_mut() - .ok_or_else(|| anyhow!("live-kit was not initialized"))?; - match mem::take(&mut live_kit.screen_track) { - LocalTrack::None => Err(anyhow!("screen was not shared")), - LocalTrack::Pending { .. } => { - cx.notify(); - Ok(()) - } - LocalTrack::Published { - track_publication, .. - } => { - live_kit.room.unpublish_track(track_publication); - cx.notify(); + todo!() + // let live_kit = self + // .live_kit + // .as_mut() + // .ok_or_else(|| anyhow!("live-kit was not initialized"))?; + // match mem::take(&mut live_kit.screen_track) { + // LocalTrack::None => Err(anyhow!("screen was not shared")), + // LocalTrack::Pending { .. } => { + // cx.notify(); + // Ok(()) + // } + // LocalTrack::Published { + // track_publication, .. + // } => { + // live_kit.room.unpublish_track(track_publication); + // cx.notify(); - Audio::play_sound(Sound::StopScreenshare, cx); - Ok(()) - } - } + // Audio::play_sound(Sound::StopScreenshare, cx); + // Ok(()) + // } + // } } #[cfg(any(test, feature = "test-support"))] pub fn set_display_sources(&self, sources: Vec) { - self.live_kit - .as_ref() - .unwrap() - .room - .set_display_sources(sources); + todo!() + // self.live_kit + // .as_ref() + // .unwrap() + // .room + // .set_display_sources(sources); } }