ActiveSpeakerObserver: "dominantspeaker" listener does not work properly if I immediately add a fresh Producer.
The “dominantspeaker” listener does not work if I add a fresh Producer to an ActiveSpeakerObserver. To make it work I must give it some time by wrapping it with setTimeout. See example below
This code doesn’t work:
const producer = await transport.produce(...);
activeSpeakerObserver.on('dominantspeaker', (dominantSpeaker) => {
console.log('Called');
});
activeSpeakerObserver.addProducer({ producerId: producer.id });
Result
-> "Called" is printed only once as soon as activeSpeakerObserver.addProducer({ producerId: producer.id }) but later it will never work.
This code work:
const producer = await transport.produce(...);
activeSpeakerObserver.on('dominantspeaker', (dominantSpeaker) => {
console.log('Called');
});
setTimeout(() => {
activeSpeakerObserver.addProducer({ producerId: producer.id });
}, 3000);
Result
-> "Called"
-> "Called"
-> ....
Environment
- mediasoup version: 3.10.0
const producer = transport.produce(...);
Why aren't you awaiting for transport.produce()? It returns a Promise, not a Producer.
const producer = await transport.produce(...);
const producer = transport.produce(...);Why aren't you awaiting for
transport.produce()? It returns a Promise, not a Producer.
const producer = await transport.produce(...);
Oh sorry, my actual code has await. I'll edit the issue.
I just did a quick test and for me it works even when adding producer to the activeSpeakerObserver immediately after the "await transport.produce()" is done.
I'm assuming you have multiple producers in your test, right? Can you try muting and unmuting them to see if you get the "Called" log in that case. It is how I tested it now.
I just did a quick test and for me it works even when adding producer to the activeSpeakerObserver immediately after the "await transport.produce()" is done.
I'm assuming you have multiple producers in your test, right? Can you try muting and unmuting them to see if you get the "Called" log in that case. It is how I tested it now.
Hi @ggarber , By the word mute did you refer to pausing producer? Yes, I have multiple producers. I tested with 2 audio producers of PeerA and PeerB. I paused producer on PeerA and speak on PeerB and switched turn between these 2 users but it doesn't work. What mediasoup-client platform that you are testing on? My mediasoup-client is flutter version.
Guys let's not mandate pause/resume actions for it to work. It shouldn't be needed. If the only way to work when immediately adding the created Producer to the ActiveSpeakerObserver is by pausing and resuming it, then there is a bug.
Any update to this?
Confirmed that the issue doesn't happen. Tested same code than in the description. The 'dominantspeaker' events is fired immediately without having to wait any loop cycle.