transport.produce() triggers successful "connect" but not "produce" event

Sorry to ask this, as I know there have been a few similar threads, but nothing helped me work it out.

I’ve used mediasoup successfully in the past, but I seem to be stuck just trying to make a simple producer connection now, and I don’t know how to debug it.

Simplified version of my code:

producerTransport.on("connect", async ({ dtlsParameters }) => {
          socket.emit("connectProducerTransport", { dtlsParameters }, () => {
            console.log("this is logged and debug logs say connection succeeded");
          });
      });

producerTransport.on(
        "produce",
        async (clientProduceParameters, callback) => {
          console.log("this is never logged")
          socket.emit("produce", clientProduceParameters, ({ id }) => {
            callback({ id });
            console.log("so this is never logged")
          });
        }
      );

await producerTransport.produce({
          track,
          ...params,
        });
console.log("this is never logged")

I hope this makes the issue clear. Originally I was running the server in a docker container, and the front end was react native, but I’ve simplified everything so it’s just a node server running locally and react in a web browser and I still have the same problem.

I guessed it could be an ssl issue, so I’m running the frontend as https with trusted certs via mkcert, but that hasn’t fixed it. I also tried using my generated server certs in mediasoup’s dtlsCertificateFile / dtlsPrivateKeyFile but no change.

I’ve tried various ip settings, such as:

{
    ip: "0.0.0.0", announcedIp: "127.0.0.1"
},

And:

{
    ip: "127.0.0.1", announcedIp: null
},

And even getting the ip via os.networkInterfaces() etc.
I’m not really sure where to go from here. The documentation here says: “The transport will emit “produce” so the application will transmit the event parameters to the server and will create a Producer instance in server side.” but I’m not sure what to do if it doesn’t.

I’ve turned on the debugging with DEBUG="mediasoup*" but this is the last bit of info I get:

[Node] 2022-11-17T19:16:12.251Z mediasoup:WebRtcTransport connect()
[Node] 2022-11-17T19:16:12.252Z mediasoup:Channel request() [method:transport.connect, id:4]
[Node] 2022-11-17T19:16:12.255Z mediasoup:Channel request succeeded [method:transport.connect, id:4]

I’d be really glad of any suggestions for other things to try, or if there’s a more concrete method of working out what’s wrong that I should be following. If it makes any difference, I’m on an M1 mac, but had no problems installing, and like I say, I’ve tried docker as well. I’m using chrome://webrtc-internals/ but maybe I’m missing something?

Could you put a log line in the produce event, but before the socket.emit? Does it fire? Do you respond properly to your produce request on the server?

I would determine a user is connected to media server when DTLS is connected. If I see track they are ready to be produced. If they take to long to show DTLS and track connected then it’s destroyed. No issues thus far.

Your client should just request ICE if they have disconnections on their end but with some added delay cause recovery can occur on its own.

Thanks for the idea - I’ve updated my code with another console log to show that produce doesn’t fire at all.

On the server I respond to the “connect” like this:

socket.on('connectProducerTransport', async (data, callback) => {
    console.log("connecting producer transport", { data })
    await producerTransport.connect({ dtlsParameters: data.dtlsParameters });
    console.log("connected")
    callback();
  });

I just realised I wasn’t calling the callback in the “connect” event, only “produce”.
This seems to have fixed things and the produce event is called as expected. Here is what my first line of code should have looked like for the “connect” event:

producerTransport.on("connect", async ({ dtlsParameters }, callback, errback) => {
    //socket stuff
    callback()
    //catch errors and call errback()
}

Of course, this was in the documentation: mediasoup :: API but I’d been looking for the error everywhere except “connect”, because “connect” was working. Hope this helps someone else. Thanks for the suggestions!