Use participant identity and track sid everywhere

Antonio Scandurra created

Change summary

crates/call/src/room.rs                                                        | 48 
crates/live_kit_client/LiveKitBridge/Sources/LiveKitBridge/LiveKitBridge.swift |  4 
2 files changed, 28 insertions(+), 24 deletions(-)

Detailed changes

crates/call/src/room.rs 🔗

@@ -318,28 +318,32 @@ impl Room {
                             });
                         }
 
-                        this.remote_participants.insert(
-                            peer_id,
-                            RemoteParticipant {
-                                user: user.clone(),
-                                projects: participant.projects,
-                                location: ParticipantLocation::from_proto(participant.location)
-                                    .unwrap_or(ParticipantLocation::External),
-                                tracks: Default::default(),
-                            },
-                        );
-
-                        if let Some((room, _)) = this.live_kit_room.as_ref() {
-                            println!("getting video tracks for peer id {}", peer_id.0.to_string());
-                            let tracks = room.remote_video_tracks(&peer_id.0.to_string());
-                            dbg!(tracks.len());
-                            for track in tracks {
-                                dbg!(track.sid(), track.publisher_id());
-                                this.remote_video_track_updated(
-                                    RemoteVideoTrackUpdate::Subscribed(track),
-                                    cx,
-                                )
-                                .log_err();
+                        let location = ParticipantLocation::from_proto(participant.location)
+                            .unwrap_or(ParticipantLocation::External);
+                        if let Some(remote_participant) = this.remote_participants.get_mut(&peer_id)
+                        {
+                            remote_participant.projects = participant.projects;
+                            remote_participant.location = location;
+                        } else {
+                            this.remote_participants.insert(
+                                peer_id,
+                                RemoteParticipant {
+                                    user: user.clone(),
+                                    projects: participant.projects,
+                                    location,
+                                    tracks: Default::default(),
+                                },
+                            );
+
+                            if let Some((room, _)) = this.live_kit_room.as_ref() {
+                                let tracks = room.remote_video_tracks(&peer_id.0.to_string());
+                                for track in tracks {
+                                    this.remote_video_track_updated(
+                                        RemoteVideoTrackUpdate::Subscribed(track),
+                                        cx,
+                                    )
+                                    .log_err();
+                                }
                             }
                         }
                     }

crates/live_kit_client/LiveKitBridge/Sources/LiveKitBridge/LiveKitBridge.swift 🔗

@@ -15,13 +15,13 @@ class LKRoomDelegate: RoomDelegate {
 
     func room(_ room: Room, participant: RemoteParticipant, didSubscribe publication: RemoteTrackPublication, track: Track) {
         if track.kind == .video {
-            self.onDidSubscribeToRemoteVideoTrack(self.data, participant.identity as CFString, track.id as CFString, Unmanaged.passUnretained(track).toOpaque())
+            self.onDidSubscribeToRemoteVideoTrack(self.data, participant.identity as CFString, track.sid! as CFString, Unmanaged.passUnretained(track).toOpaque())
         }
     }
     
     func room(_ room: Room, participant: RemoteParticipant, didUnsubscribe publication: RemoteTrackPublication, track: Track) {
         if track.kind == .video {
-            self.onDidUnsubscribeFromRemoteVideoTrack(self.data, participant.sid as CFString, track.id as CFString)
+            self.onDidUnsubscribeFromRemoteVideoTrack(self.data, participant.identity as CFString, track.sid! as CFString)
         }
     }
 }