mediasoup icon indicating copy to clipboard operation
mediasoup copied to clipboard

ActiveSpeakerObserver: "dominantspeaker" listener does not work properly if I immediately add a fresh Producer.

Open un-hongly opened this issue 3 years ago • 5 comments

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

un-hongly avatar Sep 06 '22 06:09 un-hongly

const producer = transport.produce(...);

Why aren't you awaiting for transport.produce()? It returns a Promise, not a Producer.

const producer = await transport.produce(...);

jmillan avatar Sep 06 '22 08:09 jmillan

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.

un-hongly avatar Sep 06 '22 08:09 un-hongly

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.

ggarber avatar Sep 06 '22 14:09 ggarber

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.

un-hongly avatar Sep 07 '22 08:09 un-hongly

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.

ibc avatar Sep 08 '22 19:09 ibc

Any update to this?

ibc avatar Nov 03 '22 17:11 ibc

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.

ibc avatar Nov 03 '22 18:11 ibc