what are the cases where the track subscribed migh...
# ask-ai
b
what are the cases where the track subscribed might not be raised, basically in one use case (without agents) ideally in the flow track subscribed should be raised as the front end publishes a track but in one case we did not get the track subscribed, trying to figure out what might have happened
t
Thanks for reaching out, Mohammed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! I wanted to share some insights about why the 'track subscribed' event might not be raised in certain situations. Here are a few possibilities to consider: • AutoSubscribe Disabled: If
autoSubscribe
is set to
false
, the SDK won’t automatically subscribe to new tracks, so the event won’t trigger unless you manually subscribe. • Subscription Failure: Sometimes, if a subscription attempt doesn’t succeed, the 'track subscribed' event won’t fire. Instead, you might see a 'track subscription failed' event. • Tracks Published Before Joining: This event only fires for tracks you subscribe to after joining the room. If the tracks were published and subscribed to before you joined, the event won’t trigger. • Metadata Not Received: In some SDKs, if the track metadata isn’t received before the media track subscription, the event might not be emitted because of a timeout. • Unsupported Track Type: If the client doesn’t support the track type, the event may not be triggered. I hope this helps clarify things! Please feel free to reach out if you’d like me to explain any of these points further or if there’s anything else I can assist you with. I’m here to help! Sources: Rooms, participants, and tracks | LiveKit Docs | src/room/events.ts | livekit-android-sdk/src/main/java/io/livekit/android/events/RoomEvent.kt | lib/src/participant/remote.dart
b
in livekit room is there any way of getting the track from the participants apart from the track subscribed event?
t
Absolutely, you can access tracks from participants in a LiveKit room without having to rely solely on the 'track subscribed' event. Let me walk you through some helpful methods: • TrackPublication: Each participant has
TrackPublication
objects that represent their published tracks. These give you useful metadata like kind, source, and name even before you subscribe. • RoomEvent.TrackPublished: This event triggers when a new track is published to the room after your local participant joins. It gives you access to the
RemoteTrackPublication
and the participant associated with it. • React Hook: The
useTracks
hook returns an array of
TrackReference
objects, which include both participants and their
TrackPublication
. It updates in response to events like
TrackPublished
and
ParticipantConnected
. • trackReferencesObservable: In JavaScript/TypeScript, this function keeps an eye on track publications and sends updates whenever tracks are published or participants join. • SDK-Specific Methods: For Python, you can check out the
track_publications
dictionary on a participant. For Swift, the
participant(_:didPublishTrack:)
delegate method is your friend. These options give you the flexibility to work with tracks and their metadata without waiting for the subscription process. If you'd like, I’m here to help with more details on any of these approaches—just let me know! Sources: livekit-compose-components/src/main/java/io/livekit/android/compose/state/R... | Rooms, participants, and tracks | LiveKit Docs | packages/react/src/hooks/useTracks.test.ts | src/room/events.ts | examples/room_example.py