PipeToRouter Events

Hi there,

I am using 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:

      // 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?

      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!

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 }).

1 Like

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?

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

1 Like