# PipeToRouter Events

**URL:** <https://mediasoup.discourse.group/t/pipetorouter-events/1569>\
**Category:** mediasoup libraries\
**Created:** [August 12, 2020, 7:05pm UTC](https://mediasoup.discourse.group/t/pipetorouter-events/1569 "2020-08-12T19:05:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cat](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@cat](https://mediasoup.discourse.group/u/cat)\
**Post date:** [August 12, 2020, 7:05pm UTC](https://mediasoup.discourse.group/t/pipetorouter-events/1569/1 "2020-08-12T19:05:24Z")

</div>

Hi there,

I am using [`router.pipeToRouter()`](https://mediasoup.org/documentation/v3/mediasoup/api/#router-pipeToRouter) to copy a producer from one router to another, and having some difficultly understanding what the events refer in the context of a pipeConsumer. I am trying to ensure that I am reading the documentation correctly and handling all of the events appropriately.

I am creating the pipeConsumer and pipeProducer as follows:

```auto
      // pipeConsumer is in the origin router
      // pipeProducer is in the target router
      const { pipeConsumer, pipeProducer } = await originRouter.pipeToRouter({
        producerId: originalProducer.id,
        router: targetRouter,
      });

```

**Is my understanding of what the pipeConsumer events refer to (and what an appropriate response would be) correct in the following snippet?**

```auto
      pipeConsumer.on("transportclose", () => {
        // event: the pipeTransport between this pipeConsumer and its corresponding pipeProducer has closed
        // action: close both accordingly
      });

      pipeConsumer.on("producerclose", () => {
        // event: the originalProducer has closed 
        // action: close both this pipeConsumer and the corresponding pipeProducer
      });

      pipeConsumer.on("producerpause", () => {
        // event: the originalProducer has paused
        // action: pause the pipeProducer
      });

      pipeConsumer.on("producerresume", () => {
        // event: the originalProducer has resumed
        // action: resume the pipeProducer
      });

```

My confusion stems from the fact that ‘transportclose’ _seems_ like it could refer to either the underlying pipeTransport between the pipeConsumer and pipeProducer _or_ the originalProducer’s transport having closed.

Thanks for your time!

---

<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:** [August 12, 2020, 7:23pm UTC](https://mediasoup.discourse.group/t/pipetorouter-events/1569/2 "2020-08-12T19:23:43Z")

</div>

Forget about the pipe consumer. You usually just need access to the pipe producer, specifically its id. With it, you can consume it in target router by calling someTransport.consume({ producerId }).

---

<div class="post-metadata">

**Author:** ![cat](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@cat](https://mediasoup.discourse.group/u/cat)\
**Post date:** [August 12, 2020, 7:29pm UTC](https://mediasoup.discourse.group/t/pipetorouter-events/1569/3 "2020-08-12T19:29:01Z")

</div>

Thank you for the quick response.

Are you saying that it is not necessary to set up these event handlers? When the `originalProducer` closes or fails, will the pipeProducer automatically close or will it just continue producing empty video?

---

<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:** [August 12, 2020, 7:34pm UTC](https://mediasoup.discourse.group/t/pipetorouter-events/1569/4 "2020-08-12T19:34:27Z")

</div>

It will close according. You just need to read its id in order to consume it, nothing else.
