Clean up screenshare (#44945)

Conrad Irwin created

Release Notes:

- Fixed a bug where screen-share tabs would persist after the sender (or
receiver) had left the call.

Change summary

crates/call/src/call_impl/room.rs     | 12 ++++++++++++
crates/workspace/src/shared_screen.rs |  5 +++++
2 files changed, 17 insertions(+)

Detailed changes

crates/call/src/call_impl/room.rs 🔗

@@ -305,6 +305,7 @@ impl Room {
 
     pub(crate) fn leave(&mut self, cx: &mut Context<Self>) -> Task<Result<()>> {
         cx.notify();
+        self.emit_video_track_unsubscribed_events(cx);
         self.leave_internal(cx)
     }
 
@@ -352,6 +353,14 @@ impl Room {
         self.maintain_connection.take();
     }
 
+    fn emit_video_track_unsubscribed_events(&self, cx: &mut Context<Self>) {
+        for participant in self.remote_participants.values() {
+            for sid in participant.video_tracks.keys() {
+                cx.emit(Event::RemoteVideoTrackUnsubscribed { sid: sid.clone() });
+            }
+        }
+    }
+
     async fn maintain_connection(
         this: WeakEntity<Self>,
         client: Arc<Client>,
@@ -882,6 +891,9 @@ impl Room {
                                     project_id: project.id,
                                 });
                             }
+                            for sid in participant.video_tracks.keys() {
+                                cx.emit(Event::RemoteVideoTrackUnsubscribed { sid: sid.clone() });
+                            }
                             false
                         }
                     });

crates/workspace/src/shared_screen.rs 🔗

@@ -42,6 +42,11 @@ impl SharedScreen {
         })
         .detach();
 
+        cx.observe_release(&room, |_, _, cx| {
+            cx.emit(Event::Close);
+        })
+        .detach();
+
         let view = cx.new(|cx| RemoteVideoTrackView::new(track.clone(), window, cx));
         cx.subscribe(&view, |_, _, ev, cx| match ev {
             call::RemoteVideoTrackViewEvent::Close => cx.emit(Event::Close),