sendTransport.produce() not working

After creating a sendTransport and getting an audioTrack using getUserMedia, I am trying to have my sendTransport produce so that I can have a producer. However, I am not getting anything back.

Below is my debugging console and my code.

const {
                sctpParameters} = transportInfo;

            sendTransport = await device.createSendTransport({
                id: id,
                iceParameters: iceParameters,
                iceCandidates: iceCandidates,
                dtlsParameters: dtlsParameters,
                sctpParameters: sctpParameters

            console.log("sendTransport: ", sendTransport);

            let audioStream = await mediaDevices.getUserMedia({ audio: true });
            const audioTrack = audioStream.getAudioTracks()[0];
            console.log("audioTrack: ", audioTrack);

            producer = await sendTransport.produce({
                track: audioTrack,
                codecOptions :
                    opusStereo : 1,
                    opusDtx    : 1

            console.log("producer:", producer )

The documentation is there to read it:

Please, try to read the documentation before asking anything here. We have not time for explaining what is already documented.

I have read the documentation.
According to the documentation, it states that transport.on(‘connect’) will be emitted if it’s first time calling transport.produce() and transport.on(‘produce’) will be emitted if it’s not, in order to create Producer instance in the server-side.

However, when I call transport.produce(), let producer = await this.sendTransport.produce() to be exact, I am not getting anything. When I get rid of the await, I have transport.on('connect') emitted, but nothing further. I tried to look at the mediasoup-client source code, and I have found out that my code is not passing through safeEmitAsPromise

When I modified the example in mediasoup-demo, it worked perfectly fine, but I am getting this problem when I am trying to build my own.

Do you have any advice?

I am trying to build my project in ReactNative.

I don’t fully understand the problem. You must set the sendTransport.on("connect") and sendTransport.on("produce") event listeners before you call sendTransport.produce() .

And just once.

Thank you for your reply. I had actually previously set the event listeners after I call sendTransport.produce(). but it still does not work after I moved the event listeners after calling sendTransport.produce()

Not sure if it’s a typo in your reply, but you must set event listeners before calling produce().

oh shoot there was a typo. I have set the event handlers before calling produce() like you have said, but it is still not working properly.

---- update

I think I got it to work.
I am now calling produce() after sendTransport and recvTransport are created.
I see that sendTransport.on('connect') is firing, but I still cannot see the producer in the client side.
Below is my code;

const audioStream = await mediaDevices.getUserMedia({ audio: true });
    const audioTrack = audioStream.getAudioTracks()[0];
    this.producer = await this.sendTransport.produce({
      track: audioTrack,
        opusStereo: 1,
        opusDtx: 1

    console.log('producer: ', this.producer);

Is that because sendTransport.on('produce') must fire in order for produce() to complete?

Definitely yes.

great. thank you so much!