Produce event not fired

Hello there !

I will be quick. I’m creating a sendTransport correctly, and I’m trying to produce something with it.

Here is the code from creating my transport :

    const sendTransport: Transport = this.mediasoupDevice!.createSendTransport(
      producersTransportParams
    )

    if (sendTransport == null) {
      throw 'Could not cread producers transport'
    }

    // When we want to connect we need to fire a socket event to ask for ti
    sendTransport.on('connect', async () => {
      log.debug('[Mediasoup] - 📹 "connect" event for sendTransport')
      await connectTransport(TransportTypes.producer)
    })

    // When we want to produce some media, we need to send some data to the sever
    sendTransport.on(
      'produce',
      async ({ kind, rtpParameters, appData }, callback, errCallback) => {
        try {
          log.debug('[Mediasoup] - 📹 "produce" event for sendTransport')
          const id = await produceMedia(kind, rtpParameters)

          callback({ id })
        } catch (error) {
          errCallback(error)
        }
      }
    )

    const producer = await sendTransport.produce({
      track: webcamTrack,
      encodings,
      codecOptions: {
        videoGoogleStartBitrate: 1000
      }
    })

The “connect” event is raised correctly, and I’m connecting on the server side. But the produce event is never fired, and thus the produce() method never ends.

log.debug(sendTransport.listeners('produce')) indicates that the event has a listener, and the correct one.

So, can the produce() method fail silently before calling the event ? How can I debug that ?

Thanks !

I’m pretty sure the bug is here and such a connectTransport() method (whichever it does) never completes.

BTW you are wrongly using the transport connect event since, obviously, you are not reading the { dtlsParameters } object given as first argument in the event, nor you are calling the callback or errback second and third arguments.

Please, re-read the API doc about the transport connect event.

BTW you are wrongly using the transport connect event since, obviously, you are not reading the { dtlsParameters } object given as first argument in the event, nor you are calling the callback or errback second and third arguments.

I was naively using the ones I had stored server-side after creating the transport, is that wrong ?
Thanks, that was it => I needed to call the callbacks. Shame on me.

Extremely wrong :slight_smile:

1 Like