This message was deleted.
# helpdesk
s
This message was deleted.
p
hi! there’s no built in way in the components framework to retrieve tracks based on publication time. Could you elaborate a bit on your usecase, maybe there are some workarounds to achieve what you’re trying to do
g
So i have usecase where i want to show only one camera/screen share track. 1. User 1 and User 2 is there and User 1 is rendring its video . When the user 2 try to start its video rendenring the user1 video rendring should stop and user 2 video should render only
p
thanks, I guess one option would be to track the order of tracks within a custom hook that wraps
useHooks
and returns the “newest” one only.
g
The order of tracks is not consistent. Let's suppose we have an array of camera tracks 1. User 1 starts camera. CameraArray[user1]. If I close it the camera track of that users doesn't remove from the array.it is working good in terms of screen share
p
you’ll want to manage the order yourself with something like (pseudo code)
Copy code
useOrderedTracks() {
  const [orderedTracks, setOrderedTracks] = React.useState([]);
  const unOrderedTracks = useTracks();
  unOrderedTracks.forEach(track => if(!orderedTracks.includes(track)) setOrderedTracks(tracks => [...tracks, track]));
  return orderedTracks[orderedTracks.length-1];
}
g
Let me see. Thank you for your suggestion
p
no problem, I think the solution is very incomplete right now, sounds like you also want to add handling for
mute
events here, so that you always re-order the array in a way that the latest track that has been
unmuted
is chosen
g
Did you know.I you use LiveKitURl component in NExt js and inside this get the room from const room =useRoom() and attach the events. like room.on(RoomEvent.trackPublishesd,(track)=>{console.log(track}) why these events dont work. Any idea
p
two things here: on initial room connection no
trackPublished
events are emitted for publications that are already present on the room. You’ll have to loop over
room.participants.foreach(p => p.tracks.forEach))
to handle those. For locally published tracks you’ll additionally want to handle
RoomEvent.LocalTrackPublished
, too
g
room.participants.foreach(p => p.tracks.forEach)) in this i will get 4 camera tracks let's suppose how to distinguish which camera track is active or not. Becuase if the camera track is inactive it doesn't remove from the camera tracks array. Whereas schreenshare tracks got removed when you stop sharing. so at least we know if the screen share contains only active tracks
p
you can check whether or not they are muted by looking at trackPub.isMuted
g
Got the things. Thanks for the help.