# question about transport.on("connect")

**URL:** <https://mediasoup.discourse.group/t/question-about-transport-on-connect/4562>\
**Category:** mediasoup libraries\
**Created:** [September 15, 2022, 5:33am UTC](https://mediasoup.discourse.group/t/question-about-transport-on-connect/4562 "2022-09-15T05:33:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason-shen](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jason-shen/32/1419_2.png) [@jason-shen](https://mediasoup.discourse.group/u/jason-shen)\
**Post date:** [September 15, 2022, 5:33am UTC](https://mediasoup.discourse.group/t/question-about-transport-on-connect/4562/1 "2022-09-15T05:33:29Z")

</div>

i have producer and consumer on a different server, when i connect to consumer before pull any streams the transport.on(“connect”) don’t seems to get fired, my question here is, is there any way on how to be sure the transport is connected before i do the consume on the transport

thanks advance

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [September 15, 2022, 5:42am UTC](https://mediasoup.discourse.group/t/question-about-transport-on-connect/4562/2 "2022-09-15T05:42:58Z")

</div>

transport.on(connect) must fire, after you create transport. There seems to be some thing missing in signaling process at your side, proper debugging can help.

When you say 'you connect to consumer’s you mean you try to create transport on consumer server?

What do you mean by ‘without pulling any streams’?

---

<div class="post-metadata">

**Author:** ![jason-shen](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jason-shen/32/1419_2.png) [@jason-shen](https://mediasoup.discourse.group/u/jason-shen)\
**Post date:** [September 15, 2022, 5:49am UTC](https://mediasoup.discourse.group/t/question-about-transport-on-connect/4562/3 "2022-09-15T05:49:12Z")

</div>

sorry yeah maybe i didn’t explain it properly here, here is the flow

1. signal from client to server to create the transport
2. server sends back created message with the dtlsParameters
3. webRTCDevice.createRecvTransport
4. then on.(“connect”)

so 4 never fires unless i call a consume, but the consume will fail as the transport is not connected.

thanks for the help thats pretty much what the flow i have now, maybe i am missing something here

thanks again

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [September 15, 2022, 8:56am UTC](https://mediasoup.discourse.group/t/question-about-transport-on-connect/4562/4 "2022-09-15T08:56:31Z")

</div>

Ok the main issue is transport connection, kindly check chrome://webrtc-internals to check the peer connection state you will find all the details there about why connection is not being established. If possible share screenshot here.

Possible causes can be:

- You are not providing correct ip address in listen ips to mediasoup server.
- you are not passing ice servers on client side, needed of you are connecting out of network.

---

<div class="post-metadata">

**Author:** ![jason-shen](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jason-shen/32/1419_2.png) [@jason-shen](https://mediasoup.discourse.group/u/jason-shen)\
**Post date:** [September 15, 2022, 2:09pm UTC](https://mediasoup.discourse.group/t/question-about-transport-on-connect/4562/5 "2022-09-15T14:09:11Z")

</div>

already check those, this is like working, the issue is the connect event don’t trigger until its actually try to consume, so i don’t think its any of those you mention above

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [September 15, 2022, 3:42pm UTC](https://mediasoup.discourse.group/t/question-about-transport-on-connect/4562/6 "2022-09-15T15:42:51Z")

</div>

Can you show the screenshot of the peer connection from webrtc-internals?

What is the mediasoup client and server version you are using?

Does the mediasoup demo work on your local machine?

---

<div class="post-metadata">

**Author:** ![mango-martin](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/mango-martin/32/1684_2.png) [@mango-martin](https://mediasoup.discourse.group/u/mango-martin)\
**Post date:** [September 18, 2022, 10:32am UTC](https://mediasoup.discourse.group/t/question-about-transport-on-connect/4562/7 "2022-09-18T10:32:25Z")

</div>

It’s my understanding that this behavior is perfectly normal.

\_setupTransport internally is only called either on send or receive and if the Transport is not yet connected.

If you don’t send/receive anything, there is no need for an established PeerConnection.

Edit:  
From your post I think your problem might be that you misunderstand the on connect handler?!

You’re supposed to provide a callback for the connect event listener which must use your signaling to call the server .connect() method for the according Transport with the parameter provided by mediasoup-client in the callback.

---

<div class="post-metadata">

**Author:** ![mango-martin](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/mango-martin/32/1684_2.png) [@mango-martin](https://mediasoup.discourse.group/u/mango-martin)\
**Post date:** [September 19, 2022, 4:10pm UTC](https://mediasoup.discourse.group/t/question-about-transport-on-connect/4562/8 "2022-09-19T16:10:28Z")

</div>

I just want to add this in case someone else struggles with this (even though I think the docs are explaining this well enough)

This is a simplified version of how the ‘connect’ procedure should look like.

Mediasoup client:

```auto
transport.on(
  'connect',
  async ({ dtlsParameters }, callback, errback) => {
    try {
      await signaling.request('connect-transport', dtlsParameters)
      callback()
    } catch (error) {
      errback(error)
    }
  }
)

```

Mediasoup server:

```auto
mySignaling.on('connect-transport', (dtlsParameters) => {
  const transport = getCorrectTransport() // Up to you how you get the right transport
  try {
    await transport.connect({ dtlsParameters });
  } catch (error) {
    mySignaling.throwError()
  }
}

```

The ‘connect’ event is fired when you call `consume` or `produce` and will establish a PeerConnection to Mediasoup server.

After you have set up this procedure it should work. Any other issues with not seeing any video or whatever are probably related to failing ICE process. In this case make sure to double-check that you use correct listenIps for WebRtcTransport or, if you use it, WebRtcServer.

Edit: Adding our code line-by-line as a reference seeing that the minified example I posted does not cover transport identification

client

```auto
connectionCallback(id: string) {
  return async ({ dtlsParameters }: any, callback: any, errback: any) => {
    try {
      await this.socket.request('mediasoup', {
        type: 'connect-transport',
        data: {
          transportId: id,
          dtlsParameters,
        },
      })
      callback()
    } catch (error: any) {
      console.warn('ERROR CONNECTING TRANSPORT', error)
      errback(error)
    }
  }
}

```

server

```auto
async connectTransport({
  roomId,
  transportId,
  dtlsParameters,
}: IConnectTransportRequest) {
  const router = this._routerService.getRouterBy(
    'transportId',
    roomId,
    transportId,
  );
  if (!router) return; // < async fail-safe
  
  const transport = router.appData.transports.get(transportId);
  if (transport) {
    try {
      await transport.connect({ dtlsParameters });
      return 1;
    } catch {
      console.warn('Transport connection failed');
    }
  }
  return 0; // < will throw error in intermediate API layer
}

```
