Mediasoup connection steps

Good Morning, im a really noob programmer inside the WebRTC world and im trying to make a basic conferencing app, im using this to create a base so i can develop once i get it and understand it , a voice chat for a vr multiplayer app based in babylon, but thats not important. The point is , im using console log to see the steps the server and client do to get the connection, cant get the connection done correctly, these are the steps i can get: i get the Routercapabilities, i create the producertransport, connect it and even produce, i get to show my webcam on screen without i problem, but when i ā€œsubscribeā€ to it by a consumer the transport element has a problem with consume, i have a doubt, when does the client receive transport.on(ā€˜produceā€™ ā€¦ , what makes that activate, and also if that doesnt activate, the transport canā€™t consume anything, right?
Server has a produce and a broadcast, but it doesnt seem to activate the transport.on(ā€˜produceā€™).
Thanks in advance.

The sending transport will connect and produce whether there is someone consuming or not.

For producer:

  • you create send transport
  • you hit produce() on transport,
  • which causes ā€˜connectā€™, ā€˜produceā€™ events to fire then you can do signalling on these events.

For consumer:

  • you create receiving transport
  • you hit consume() on transport
  • which causes ā€˜connectā€™ event to fire then you can do signalling on it.

for producer to produce it doesnā€™t require the consumer to consume to make the produce process complete, but for consumer to consume a producer a producer must be available so that we can consume it.

I think i got it , im having a problem with ā€œCannot read properties of undefined (reading ā€˜consumeā€™)ā€
And i was looking for errors cause transport.on(ā€˜connectā€™ wasnt activating, so i was getting crazy with the consumer but it might be the producer that doesnt produce correctly.
Iā€™ll try that way, thanks for the response so fast.

This states that the transport is not made properly as the consume method is of transport, somehow that transport variable is undefined, you need to see the process.

The best way to start is with mediasoup-demo, you can use it as your base, understand it and build your app on top of it.

Sorry for bothering but i dont get how transport.on(ā€˜produceā€™ā€¦ fires , i get that connect launches but i dont seem to find how to signal produce, i found the function in my code that makes the producer to not work but im not sure how can i get inside it:
transport.on(ā€˜produceā€™, async ({kind, rtpParameters}, callback, errback) => {
const message = {
type: ā€˜produceā€™,
transportId: transport.id,
kind,
rtpParameters
};
const resp = JSON.stringify(message);
socket.send(resp);
socket.addEventListener(ā€˜produceā€™, (resp) => {
console.log(ā€œProducer id=======ā€, resp.data.id)
callback(resp.data.id);
});
});
literally above that i have a on(ā€˜connectā€™ that works perfectly,
i understand visually when i send ā€œsome textā€ and then the client has a socket.onmessage and i can case it , but im not sure how transport works i guess.

transport.on(ā€˜produceā€™) is firing or not? you can check with some console message to see if it is firing, but if it is firing and still it is not getting produced property then there should be some socket signalling issue on your side. You will have to debug it. Also check the connectionstate of transport whether it is being connected or not.

I just got when the mistake is done , the produce signal is made here right?
producer = await producerTransport.produce({kind, rtpParameters});
But the client doesnt seem to get that produce , ill check the signaling , thanks for the responses

After this the transport ā€˜produceā€™ event is triggered in which you then signal your server to create the producer on server and send itā€™s id back to client which is then passed to the callback function on transport ā€˜produceā€™ event, that finishes the process

Yeah , thanks i just understand it correctly, still there is something that doesnt seem to signal it well , but really thanks you made me understand the comunication much better.

1 Like

And just curiosity , how does the connectionstatechange fire?
I have it working well , but now that i learnt that the .connect signals connect , and .produce signals produce i have some curiosity on the connectionstatechange.

there is an event ā€™ connectionstatechangeā€™ you can listen on it as mentioned here: mediasoup :: API

.connect() doesnā€™t trigger transport ā€˜connectā€™ event infect there is no connect() method of transport, .produce() triggers both ā€˜connectā€™, ā€˜produceā€™ events. on both these events you signal data to your server.