# transport.on('connect') not triggring the event

**URL:** <https://mediasoup.discourse.group/t/transport-on-connect-not-triggring-the-event/4497>\
**Category:** mediasoup libraries\
**Created:** [August 24, 2022, 10:14pm UTC](https://mediasoup.discourse.group/t/transport-on-connect-not-triggring-the-event/4497 "2022-08-24T22:14:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nashbe26](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nashbe26/32/1709_2.png) [@nashbe26](https://mediasoup.discourse.group/u/nashbe26)\
**Post date:** [August 24, 2022, 10:14pm UTC](https://mediasoup.discourse.group/t/transport-on-connect-not-triggring-the-event/4497/1 "2022-08-24T22:14:40Z")

</div>

Hello,

I am trying to connect to transport media and i am not getting any response from the backend and even while i log a message in the console

Front end code :

```auto
 async function getUserBroadcast(){
       
        let routerRtpCapabilities = await sendRequest('askRtpCapabilities',{})
 
        await device.load({routerRtpCapabilities});

        const data = await sendRequest('getCreateProducerTransport', {});
        console.log('transport params:', data);

        let newtransport = device.createSendTransport(data);
        
        newtransport.on("connect", async ({ dtlsParameters }, callback, errback) =>{
            try{
                console.log('transport is connected') 
                await sendRequest(
                "transport-connect",
                {
                    transportId : newtransport.id, 
                    dtlsParameters : dtlsParameters
                });

                // Tell the transport that parameters were transmitted.
                callback();
            }
            catch (error)
            {
                // Tell the transport that something was wrong.
                errback(error);
            }
            });
        

        newtransport.on('produce',async (
                { kind, rtpParameters },
                callback,
                errback
            ) => {
                console.log('--trasnport produce');
                try {
                    const { id } = await sendRequest('produce', {
                        transportId: transport.current.id,
                        kind,
                        rtpParameters,
                        
                    });
                    callback({ id });
                } catch (err) {
                    errback(err);
                }
            }
        );
        
 
        newtransport.on('connectionstatechange', (state) => {
            switch (state) {
                case 'connecting':
                    console.log('publishing...');
                    break;

                case 'connected':
                    console.log('published');
                    break;

                case 'failed':
                    console.log('failed');
                    transport.current.close();
                    break;

                default:
                    break;
            }
        });
    }

```

Backend code:

```auto
socket.on('transport-connect', async (data, callback) => {
    await transport_Producer.connect({
    dtlsParameters: data.dtlsParameters,
  });
  });

```

---

<div class="post-metadata">

**Author:** ![BronzedBroth](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@BronzedBroth](https://mediasoup.discourse.group/u/BronzedBroth)\
**Post date:** [August 25, 2022, 12:15pm UTC](https://mediasoup.discourse.group/t/transport-on-connect-not-triggring-the-event/4497/2 "2022-08-25T12:15:19Z")

</div>

The process for connecting DTLS is fairly straight forward and your front-end does demonstrate this in several steps but let’s summarize it.

1. Client requests transport creation,
2. Server creates transport and hands client DTLS and ICE;
3. Client takes the DTLS and ICE parameters and creates transport with this.
4. Client’s transport emit connect with responding DTLS to send to server
5. Server connects this transport with provided DTLS.
6. When all is finished server will emit dtlsstatechange and client will emit connectionstatechange

I would debug and determine if you’re stalling on steps and additionally check your network configurations as this will surely prevent connection from ever occurring if it’s wrong.

If you suspect code, trial a working demo.

---

<div class="post-metadata">

**Author:** ![nashbe26](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nashbe26/32/1709_2.png) [@nashbe26](https://mediasoup.discourse.group/u/nashbe26)\
**Post date:** [August 25, 2022, 12:30pm UTC](https://mediasoup.discourse.group/t/transport-on-connect-not-triggring-the-event/4497/3 "2022-08-25T12:30:45Z")

</div>

hi CosmosisT,

Thanks for your answer i made sure that all the setps are done. i logged the transport object it works but when it comes to on connect event and on produce events nothing happen.

I think i don’t have any problem with my connection settings because i tried an open source mediasoup project and it works.

Thanks

---

<div class="post-metadata">

**Author:** ![BronzedBroth](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@BronzedBroth](https://mediasoup.discourse.group/u/BronzedBroth)\
**Post date:** [August 25, 2022, 12:49pm UTC](https://mediasoup.discourse.group/t/transport-on-connect-not-triggring-the-event/4497/4 "2022-08-25T12:49:48Z")

</div>

The transport does not require you to produce to it to connect, produce event fires off when track is ready and transport is opened in other words it can occur before/after emit of connect.

If you’re getting to the step you connect the transport on both server/client and nothing is happening I would think server-configurations.

Confirm the mediasoup client isn’t halting somewhere awaiting a response, this issue can be common for custom developments that don’t follow the awaitqueue procedure.

* * *

Do a bit of logging/debugging to trace where things get stuck and report back.

---

<div class="post-metadata">

**Author:** ![nashbe26](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nashbe26/32/1709_2.png) [@nashbe26](https://mediasoup.discourse.group/u/nashbe26)\
**Post date:** [August 25, 2022, 10:15pm UTC](https://mediasoup.discourse.group/t/transport-on-connect-not-triggring-the-event/4497/5 "2022-08-25T22:15:04Z")

</div>

Hello,

I fixed the problem transport conncet event or produce event are triggered when there an audio or a video to produce when i got my media ready and produced the events triggred.

Thanks again.

---

<div class="post-metadata">

**Author:** ![BronzedBroth](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@BronzedBroth](https://mediasoup.discourse.group/u/BronzedBroth)\
**Post date:** [August 25, 2022, 11:00pm UTC](https://mediasoup.discourse.group/t/transport-on-connect-not-triggring-the-event/4497/6 "2022-08-25T23:00:01Z")

</div>

> [@nashbe26](#):
>
> transport conncet event or produce event are triggered when there an audio or a video to produce when i got my media ready

Connect should be established before/after produce order can vary however.

So it sounds like you’re fighting awaitQueue, you can modify client if it doesn’t comply properly to your app/client setup.
