Re-connect a Producer to another Consumer

To balance and optimize usage of multiple Routers both with vertical and horizontal scaling, I’m planning to re-connect the Producers that receive data from another Consumers. I know you can use the Transport.connect() method to open a listening port and connect to the other endpoint, but I’m not sure if this can be done when a connection is already being done or if I need to close it first. Problem is, closing the Transport will close all its Consumers, all its Producers, and the Consumers connected to that Producers, and if you control correctly the events that can generate a chain reaction and close all the downstream Producers and Consumers.

Ideally, connect() method should do a reconnection with the new parameters if called twice, but I don’t know if that’s possible. If so, another alternative is to add a new reconnect() method that adjust the Transport internal state without dispatching the transportclose event, but don’t know how much difficult it can be.

Related to that, a Producer can have multiple Consumers since they are managed by the Mediasoup Router, but can a Consumer in a PipeTransport provide data to multiple Producers in the PipeTransports of other Routers?

“Reconnect” a transport is not that easy because lot of state must be restarted (SRTP keys, RTP port, optional RTCP port, etc). This is not even considered as a feature, specially because there is little benefit. You can just create another transport, consume producers in there and connect the transport to another Router or server via pipe mechanism. No benefit in having such a reconnect() method.

I suposed It would not be easy :slight_smile: I though It could be posible by splitting current Connect() Code to an internal one that doesn’t emit the events, so later could be implementes the reconnect() as a close + Connect, but seems it’s not posible :-/

So, let me check: are you proposing that I create a new transport, and propagate an aplication level message to notify about stop using the old one and start using the new one, specially for example when recording using RTP + ffmepg? Would’t that provoque cuts and interruptions in the stream? Maybe use pause + resume?