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.