Mediasoup Transport on("connect") Event Not Firing – What Could Be Missing?

0

I tried consumerTransport.current.on('connect', but the following console log doesn’t appear at all, and there’s no error either. It’s strange because no errors are coming up. The status of consumerTransport.current is new. What might be the issue?

  socketRef.current.emit(
      'createConsumerTransport',
      { consumer: true },
      (params: any) => {
        console.log('createConsumerTransport params:', params);
        if (!device.current) {
          console.error('Device is null');
          return;
        }
        // check params
        if (
          !params.id ||
          !params.iceParameters ||
          !params.iceCandidates ||
          !params.dtlsParameters
        ) {
          console.error('Invalid params for createRecvTransport:', params);
          return;
        }

        try {
          // consumerTransport create
          consumerTransport.current =
            device.current.createRecvTransport(params);
          console.log('Consumer transport created:', consumerTransport.current);
        } catch (error) {
          console.error('Failed to create consumer transport:', error);
          return;
        }

        consumerTransport.current = device.current.createRecvTransport(params);
        console.log('consumerTransport==========:', consumerTransport);

        if (!consumerTransport.current) {
          console.error(
            'Failed to create consumer transport:',
            consumerTransport.current,
          );
          return;
        }
        consumerTransport.current.on('connectionstatechange', (state) => {
          console.log('Consumer transport connection state:', state);
        });

        consumerTransport.current.on(
          'connect',
          async ({ dtlsParameters }, callback, errback) => {
            console.log(
              'consumerTransport connect event with dtlsParameters:',
              dtlsParameters,
            );
            try {
              await socketRef.current?.emit('connectConsumerTransport', {
                dtlsParameters,
              });
              callback();
            } catch (err) {
              console.error('Failed to connect consumer transport:', err);
            }
          },
        );

As documented in the API documentation “connect” event fires after first Producer or Consumer or DataProducer or DataConsumer is created.