[libmediasoupclient] MySendTransportListener::OnConnect() And OnProduce() events not firing

Hi all,

This is my class MySendTransportListener

class MySendTransportListener:public mediasoupclient::SendTransport::Listener
{
public:
	MySendTransportListener(EchoClient *sigClient);
	std::future<void> OnConnect(mediasoupclient::Transport* transport, const nlohmann::json& dtlsParameters) override;
	std::future<std::string> OnProduce(
		mediasoupclient::SendTransport* transport,
		const std::string& kind,
		nlohmann::json rtpParameters,
		const nlohmann::json& appData) override;
	void OnConnectionStateChange(mediasoupclient::Transport* transport, const std::string& connectionState) override;
private:
	EchoClient *mySignaling;
};
MySendTransportListener::MySendTransportListener(EchoClient * sigClient)
	:mySignaling(sigClient)
{
}

std::future<void> MySendTransportListener::OnConnect(mediasoupclient::Transport * transport, const nlohmann::json & dtlsParameters)
{
	qDebug() << "enter MySendTransportListener::OnConnect()";
	std::promise<void> promise;

	Json body =
	{
		{ "transportId",    transport->GetId() },
		{ "dtlsParameters", dtlsParameters     }
	};

	// Signal local DTLS parameters to the server side transport.
	mySignaling->requestBy("connectWebRtcTransport", 4, body);

	// [...] Let's assume code execution continues once we get a success response
	// from the server.

	// Fullfill the promise and return its future.
	promise.set_value();

	return promise.get_future();
}

std::future<std::string> MySendTransportListener::OnProduce(
	mediasoupclient::SendTransport* transport,
	const std::string& kind,
	nlohmann::json rtpParameters,
	const nlohmann::json& appData)
{
	qDebug() << "enter MySendTransportListener::OnProduce()";
	std::promise<std::string> promise;

	Json body =
	{
		{ "transportId",   transport->GetId() },
		{ "kind",          kind               },
		{ "rtpParameters", rtpParameters      },
		{ "appData",       appData            }
	};

	mySignaling->requestBy("produce", 5, body);
	while (mySignaling->req_produce_res == NULL) {}
	Json response = mySignaling->req_produce_res;
	// [...] Let's assume code execution continues once we get a success response
	// from the server.

	// Read the id in the response.
	auto idIt = response.find("id");
	if (idIt == response.end() || !idIt->is_string())
	{
		promise.set_exception(
			std::make_exception_ptr("'id' missing/invalid in response"));
	}

	// Fullfill the promise with the id in the response and return its future.
	promise.set_value(idIt->get<std::string>());

	return promise.get_future();
}

and I create the _sendTransport

void ChatWindow::doReq1()
{
	qDebug() << "doReq1()";
	auto* sendTransportListener = new MySendTransportListener(sigClient);
	// This will block the current thread until completion.
	_sendTransport = _mediasoupDevice->CreateSendTransport(
		sendTransportListener,
		sigClient->transportInfo["id"],
		sigClient->transportInfo["iceParameters"],
		sigClient->transportInfo["iceCandidates"],
		sigClient->transportInfo["dtlsParameters"]);
	qDebug() << "doReq1() ok";
}

is Ok until now
then i produce

class MyProducerListener : public mediasoupclient::Producer::Listener
{
public:
	void OnTransportClose(mediasoupclient::Producer * producer);
};
void MyProducerListener::OnTransportClose(mediasoupclient::Producer* producer)
{
	qDebug() << "[MyProducerListener::OnTransportClose] transport closed";
}
void ChatWindow::prepareProduceAndConsume()
{
	Json codecOptions =
	{
		{ "opusStereo", true },
		{ "opusDtx",    true }
	};
	auto* audioProducerListener = new MyProducerListener();
	mediasoupclient::Producer *_micProducer = _sendTransport->Produce(
		audioProducerListener,
		sigClient->audio_track,
		nullptr,
		&codecOptions);

	qDebug() << "_micProducer Ready";

	std::vector<webrtc::RtpEncodingParameters> encodings;

	encodings.emplace_back(webrtc::RtpEncodingParameters());
	encodings.emplace_back(webrtc::RtpEncodingParameters());
	encodings.emplace_back(webrtc::RtpEncodingParameters());

	auto* videoProducerListener = new MyProducerListener();

	// This will block the current thread until completion.
	mediasoupclient::Producer *_webcamProducer = _sendTransport->Produce(
		videoProducerListener,
		sigClient->video_track_,
		&encodings,
		nullptr);
	qDebug() << "_webcamProducer Ready";
}

And No errors, just block, no debug message print which means no firing Onconnect or OnProduce Events
local audio and video track is ok, can show in the window
Any help would be greatly appreciated.

Hi,

Enable MEDIASOUPCLIENT_LOG_TRACE flag in libmediasoupclient and use the LOG_DEBUG log level in order to see where exactly the code stops.

Doc here: https://mediasoup.org/documentation/v3/libmediasoupclient/installation/#Building-Flags

Thanks a ton!

@hhhhqszka
I have the same issue (only difference is I am using the iOS ObjC wrapper but still under the hood the same library), did you figure it out?

@xplatsolutions, hi, it seems ibc has solved your problem, i refer to the mediasoup-broadcast-demo, and construct the peerconnection like this rather then pass nullptr to the first three parameters of webrtc::CreatePeerConnectionFactory, and it works, i don’t know why. But you seems to do work on different platform with me, maybe this can not help u. Maybe someone can answer me.

    networkThread   = rtc::Thread::Create().release();
	signalingThread = rtc::Thread::Create().release();
	workerThread    = rtc::Thread::Create().release();
	
	networkThread->SetName("network_thread", nullptr);
	signalingThread->SetName("signaling_thread", nullptr);
	workerThread->SetName("worker_thread", nullptr);

	factory = webrtc::CreatePeerConnectionFactory(
		networkThread,
		workerThread,
		signalingThread,
		nullptr,
		webrtc::CreateBuiltinAudioEncoderFactory(),
		webrtc::CreateBuiltinAudioDecoderFactory(),
		webrtc::CreateBuiltinVideoEncoderFactory(),
		webrtc::CreateBuiltinVideoDecoderFactory(),
		nullptr /*audio_mixer*/,
		nullptr /*audio_processing*/);

@hhhhqszka right I am working in different platform although libMediasoupClient is same under the hood. Unfortunately I don’t know what the problem you experiencing is, it looks like for me I have to work binding the actual device media stream to local Transport.Produce for the transport to star sending delegate events.

Yeah,you have not produced, connect event will be fired at the first time of Produce indeed. I guess my problem is i don’t know the underlying inplementation of threads’ constructing of webrtc::CreatePeerConnectionFactory, I need to learn more.