# Feature suggestion: producer.on("consumerpause", fn) and producer.on("consumerresume", fn) events

**URL:** <https://mediasoup.discourse.group/t/feature-suggestion-producer-on-consumerpause-fn-and-producer-on-consumerresume-fn-events/1109>\
**Category:** mediasoup libraries\
**Created:** [May 28, 2020, 3:30pm UTC](https://mediasoup.discourse.group/t/feature-suggestion-producer-on-consumerpause-fn-and-producer-on-consumerresume-fn-events/1109 "2020-05-28T15:30:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![copiltembel](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@copiltembel](https://mediasoup.discourse.group/u/copiltembel)\
**Post date:** [May 28, 2020, 3:30pm UTC](https://mediasoup.discourse.group/t/feature-suggestion-producer-on-consumerpause-fn-and-producer-on-consumerresume-fn-events/1109/1 "2020-05-28T15:30:28Z")

</div>

Analogous to [consumer.on(“producerpause”, fn())](https://mediasoup.org/documentation/v3/mediasoup/api/#consumer-on-producerpause) and consumer.on(“producerresume”, fn())

I think it would be:

1. A more consistent API across producers and consumers.
2. Easier to maintain for application developers on top of mediasoup.

Please let me know what you think. I could try to implement this if it’s of interest.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [May 28, 2020, 3:35pm UTC](https://mediasoup.discourse.group/t/feature-suggestion-producer-on-consumerpause-fn-and-producer-on-consumerresume-fn-events/1109/2 "2020-05-28T15:35:50Z")

</div>

A `Producer` has many associated `Consumer`, not just one.

---

<div class="post-metadata">

**Author:** ![copiltembel](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@copiltembel](https://mediasoup.discourse.group/u/copiltembel)\
**Post date:** [May 28, 2020, 3:38pm UTC](https://mediasoup.discourse.group/t/feature-suggestion-producer-on-consumerpause-fn-and-producer-on-consumerresume-fn-events/1109/3 "2020-05-28T15:38:02Z")

</div>

Yes, so we would pass the consumer(Id) in the fn as a parameter.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [May 28, 2020, 3:45pm UTC](https://mediasoup.discourse.group/t/feature-suggestion-producer-on-consumerpause-fn-and-producer-on-consumerresume-fn-events/1109/4 "2020-05-28T15:45:56Z")

</div>

I see. However I do not see the benefit of this and if we do this we should also emit `producer.on('consumerclose')`, `producer.on('consumerlayerschange')`, etc etc.

We need to emit `producerpause` in a `Consumer` because when a `Producer` is paused it affects to its `Consumers`. The opposite is not true.

So if you want to do something in the `Producer` when one of its `Consumers` is paused, you can do it at JS level within your application. No need to add it to mediasoup.

---

<div class="post-metadata">

**Author:** ![copiltembel](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@copiltembel](https://mediasoup.discourse.group/u/copiltembel)\
**Post date:** [May 28, 2020, 3:59pm UTC](https://mediasoup.discourse.group/t/feature-suggestion-producer-on-consumerpause-fn-and-producer-on-consumerresume-fn-events/1109/5 "2020-05-28T15:59:18Z")

</div>

Indeed, they would be just convenience events that are definitely doable at app level.

But I could argue that the same is true for `producerpause` and `producerresume` not only because they are also doable at app level, but also because one needs to call `producer.pause()` and `producer.resume()` in order to trigger them. But I do agree that it’s not exactly the same case.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [May 28, 2020, 4:08pm UTC](https://mediasoup.discourse.group/t/feature-suggestion-producer-on-consumerpause-fn-and-producer-on-consumerresume-fn-events/1109/6 "2020-05-28T16:08:13Z")

</div>

> [@copiltembel](#):
>
> one needs to call `producer.pause()` and `producer.resume()` in order to trigger them

Right, good point. Consider that an exception. We try to **never** generate events that are triggered due to user actions. However, when the action is done on an entity and it affects other entities, we do generate events in those other entities.

---

<div class="post-metadata">

**Author:** ![copiltembel](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@copiltembel](https://mediasoup.discourse.group/u/copiltembel)\
**Post date:** [May 28, 2020, 4:44pm UTC](https://mediasoup.discourse.group/t/feature-suggestion-producer-on-consumerpause-fn-and-producer-on-consumerresume-fn-events/1109/7 "2020-05-28T16:44:13Z")

</div>

OK, cool!
