In order to receive a SpeakersChanged event, conta...
# ask-ai
c
In order to receive a SpeakersChanged event, containing a specific remote participant, do you have to be subscribed to his microphone publication?
t
Thanks for reaching out, Daniele. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Just so you know, you don’t have to subscribe to a remote participant’s microphone publication to get the SpeakersChanged event. This event happens on its own, thanks to the server detecting audio activity in the room. That said, if you want to actually hear and play back the audio from someone’s microphone, you’ll need to subscribe to their microphone track separately. Sources: Subscribing to tracks | LiveKit Docs | src/room/Room.ts | lib/src/events.dart | livekit-rtc/livekit/rtc/room.py
c
What if i don't want to include in that speaking event remote participants which i am not subscribed to their microphone publication?
t
If you want to exclude remote participants from the SpeakersChanged event when you're not subscribed to their microphone publication, you can simply filter the event data based on subscription status. Here’s a straightforward way to do that: 1. Keep Track of Subscriptions: Use the
TrackPublished
and
TrackSubscribed
events to manage microphone subscriptions. For instance, subscribe to a participant’s microphone track as soon as it’s published. 2. Filter Active Speakers: When the
ActiveSpeakersChanged
event fires, filter out participants who don’t have an active microphone subscription. You can check each participant’s microphone track subscription status to do this. Here’s a simple example to get you started:
Copy code
// Keep track of participants with subscribed microphone tracks
const subscribedMicParticipants = new Set();

// Handle track subscriptions
room.on(RoomEvent.TrackSubscribed, (track, publication, participant) => {
    if (participant.isRemote && track.source === Track.Source.Microphone) {
        subscribedMicParticipants.add(participant);
    }
});

room.on(RoomEvent.TrackUnsubscribed, (track, publication, participant) => {
    if (participant.isRemote && track.source === Track.Source.Microphone) {
        subscribedMicParticipants.delete(participant);
    }
});

// Filter speakers based on microphone subscription
room.on(RoomEvent.ActiveSpeakersChanged, (speakers) => {
    const filteredSpeakers = speakers.filter(participant => {
        if (participant.isLocal) return true;
        return subscribedMicParticipants.has(participant);
    });
    // Use filteredSpeakers in your application
});
This way, you’ll only include participants with subscribed microphone tracks in the SpeakersChanged event. Hope this helps make your app feel more connected and responsive! Sources: JavaScript & React Components | livekit/livekit_composite | DeepWiki | Subscribing to tracks | LiveKit Docs
c
In order to trigger
ActiveSpeakersChanged
a participant need to speak with his microphone publication or any audio change in any generic publication of Kind == Audio triggers it?
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!