Event subscription status how to check intermitten...
# ask-ai
l
Event subscription status how to check intermittently.
t
Thanks for reaching out, Piyush. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To keep an eye on your event subscription status from time to time, you have a couple of friendly options: an event-driven approach or manual polling. Let’s walk through them together! Event-Driven Monitoring (Recommended): This is a great way to stay updated effortlessly. You can listen to events emitted by LiveKit, like the
TrackSubscriptionStatusChanged
event, which automatically notifies you whenever the subscription status changes. It’s efficient and keeps you in the loop right away. Manual Polling: If you prefer, you can also check the subscription status yourself at regular intervals using the client SDKs: • JavaScript SDK: Look at the
isSubscribed
property or the
subscriptionStatus
getter on
RemoteTrackPublication
. • Android SDK: Check out the
subscriptionStatus
property on
RemoteTrackPublication
. • Rust SDK: Use the
subscription_status()
method on
RemoteTrackPublication
. • Swift SDK: Take a peek at the
subscriptionState
property on
RemoteTrackPublication
. Here’s a simple example in JavaScript to help you get started with polling:
Copy code
setInterval(() => {
  trackPublication.subscriptionStatus; // Check current status
}, 5000); // Check every 5 seconds
If you have any questions or if there’s a particular scenario you’re working on, please don’t hesitate to reach out. I’m here to help you every step of the way! Sources: Sources/LiveKit/TrackPublications/RemoteTrackPublication.swift | pkg/telemetry/events_test.go | src/room/track/RemoteTrackPublication.ts | agent-console/lib/event-definitions.tsx | livekit-android-sdk/src/main/java/io/livekit/android/room/track/RemoteTrack...
l
i am subscribed to events but in one case i did not receive any such event.
t
I'm sorry to hear that you didn't receive an event even though you were subscribed. Let's work through some steps together to help you figure this out: 1. Check Connection States: Sometimes network hiccups can interrupt event delivery. It’s a good idea to make sure your application is set up to handle
Reconnecting
and
Reconnected
events so it can smoothly re-establish listeners when the connection comes back. 2. Verify Event Subscription: Double-check that you’re properly subscribed to the event. For example, in JavaScript, you want to make sure your listener is registered like this:
Copy code
room.on(RoomEvent.TrackSubscribed, (track, publication, participant) => {
    // handle track subscription
});
1. Handle Subscription Failures: Keep an eye out for the
TrackSubscriptionFailed
event, which can alert you to issues like permission problems or if a track isn’t available. 2. Review Track Subscription Process: It’s important that the subscription negotiation with the server completes successfully. If it doesn’t, the
TrackSubscribed
event won’t be triggered. 3. Examine Client SDK Implementation: Just a heads-up—events like
TrackPublished
or
TrackSubscribed
won’t fire for tracks that were already there before you joined. To catch all tracks, you’ll want to query the room’s state right after joining. Please feel free to reach out if you want me to walk you through any of these steps or if you have more questions. I’m here to help! Sources: Connecting to LiveKit | LiveKit Docs | src/room/events.ts | livekit-android-sdk/src/main/java/io/livekit/android/room/track/RemoteTrack... | Webhooks | LiveKit Docs | Subscribing to tracks | LiveKit Docs
l
subscribed and handled them, did not work.
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!