I am currently building a N:N group audio and video call using mediasoup.
I understand transport as a “path”. Therefore, when a new user enters the room, I tried to consume the producer of the new user to the receiving transport of the existing user, but the following error occurs:
Should I not recycle transports? If there are 3 users, does each user need to have 1 sending transport, 2 receiving transports, and the server needs to have 3 sending transports and 9 receiving transports accordingly? I think it is a waste of resources to create transports on the server every time a new user enters.
It depends how you use it. One user can consume the producers of the rest of users on single transport. Or you can consume each producer on different transport. Or you can have something like create 1 transport to consumer all producers of each user like his video, audio, sharescreen. It all depends how you want to use it.
When it comes to resources, number of transports doesn’t matter it is actually the number of producers, consumers. So 10 producers, consumers on 1 transport can almost have same effect as 10 producers, consumers on 10 transports as at the end we will have 10 producers, consumers. In case of multiple transports it can use a bit more resources in calculation but that is not of any worry in my opinion.
Regarding producers it is advised to always produce on single transport as it is more optimal for bandwidth estimation. So all producers from one users should go one one transport.
As for this error, it is self explanatory you are trying to connect transport which is already connected.
In fact, I don’t know why that error occurs. I am creating one producer and consumer transport on the server for each user in the following way:
private producerTransports = new Map< string, mediasoup.types.WebRtcTransport>();
private consumerTransports = new Map< string, mediasoup.types.WebRtcTransport>();
I am connecting users to these transports, and I suspect that the problem is occurring because I am trying to connect a new user to the same transport. So, I was wondering if I should create additional transports.
I understand that it is up to me, but if you have any other opinions, please let me know. Thank you for your reply.
You are calling connect() on a transport in which you already called connect() before. That’s the problem.
Of course you can call transport.consume() many times, but connect() must be called just once, so check your code because it’s not ok. And read the docs since this is perfectly explained in the documentation.
This is not right, keep the transports separated for each users, you shouldn’t be connecting multiple users on single transport. You can use one transport to consume, produce multiple times for one single user not for multiple users.
First, thank you for your answers. I am referring to the official documentation and various answers in this community, but I am having difficulty understanding because I am not good at English. I am still checking your answers while translating them.
I will write down what I understand, so please let me know if it is correct.
I know that when consume() is executed on the server side, recvTransport.on(“connect”) is automatically triggered on the client side. Is this correct?
If so, what does your “you can call transport.consume() many times, but connect() must be called just once” mean?
Then, as I mentioned earlier, is it good to keep one server-side transport per producer? So, the server also has 1 producer transport and n consumer transports for each user.
If you don’t mind can I show you a little bit of my code flow and expect an answer?
I had a question as I was implementing it according to your answer.
I am currently not receiving in the room when there is no one, and I start receiving when someone comes into the room.
User A joins: Since there are no existing users, server: consumer transport 0 User B joins: A creates recv transport for B, B creates recv transport for A, server: 2 User C joins: A->C, B->C, C->A,B, total of 4 recv transports are created, server: 6 User D joins: A->D, B->D, C->D, D->A,B,C, total of 6 recv transports are created, server: 12 …
Is this how the transport increases?
Isn’t this a mesh structure?
Does the mediasoup SFU server create transports in this way?
Is this the recommended way to proceed with development?
This look ok and the number of transports seems fine, do not worry about the number of transports as I mentioned the major things are producers, consumers. You can further verify it.
Here is another way to do the same: User A joins: Creates it’s producing transport and produce multiple tracks on it, creates consuming transports and will consume the future producers from User B, C on this transport. Total transports 2
User B joins: Creates it’s producing transport and produce multiple tracks on it, creates consuming transports and will consume the producer from User A and future producers from User C on this transport. Total transports 2
User C joins: Creates it’s producing transport and produce multiple tracks on it, creates consuming transports and will consume the producer from User A,B and future producers from User D etc on this transport. Total transports 2
And so on…
So each user is creating only 2 transports in this approach one for producing and one for consuming irrespective of the number of producers. As there are 3 users in this call so server will have 6 transports.
The important thing is that the number of producers, consumers in this approach and the approach you mentioned remains same which is the major thing contributing to resources.
So again it is up to you how you create the transports both of these approaches are fine, the one I mentioned can give benefit in bandwidth estimation etc but the other approach is fine as well.
You shouldn’t worry about the connected state before consuming, producing. Whenever you will try to consume, produce then mediasoup will automatically fire ‘connect’ event on transport if needed which is usually the first time you produce, consume on that specific transport. Whenever that ‘connect’ event fires you are supposed to signal the server and call connect() on server side as well, this is the rule of thumb whenever connect event fires just connect the transport. Consume, Produce without the worry of connection and mediasoup knows when you fire the connect event on transport and then if you have handled that connect event properly the connection will happen without any issue.
I perfectly understand it all. thanks to you guys.
I am really really grateful for your kind and helpful answer. This has been a tremendous help to me.
I’m so sorry that I can’t check multiple solution check boxes.
Thank you so much to both of you again.