Quellcode durchsuchen

Removed addDataChannel method from API

Paul-Louis Ageneau vor 4 Jahren
Ursprung
Commit
40a29fbd55
5 geänderte Dateien mit 28 neuen und 45 gelöschten Zeilen
  1. 2 2
      examples/streamer/main.cpp
  2. 4 7
      include/rtc/peerconnection.hpp
  3. 0 4
      include/rtc/rtc.h
  4. 5 13
      src/capi.cpp
  5. 17 19
      src/peerconnection.cpp

+ 2 - 2
examples/streamer/main.cpp

@@ -316,8 +316,8 @@ shared_ptr<Client> createPeerConnection(const Configuration &config,
         cout << "Audio from " << id << " opened" << endl;
     });
 
-    auto dc = pc->addDataChannel("ping-pong");
-    dc->onOpen([id, wdc = make_weak_ptr(dc)]() {
+	auto dc = pc->createDataChannel("ping-pong");
+	dc->onOpen([id, wdc = make_weak_ptr(dc)]() {
         if (auto dc = wdc.lock()) {
             dc->send("Ping");
         }

+ 4 - 7
include/rtc/peerconnection.hpp

@@ -96,12 +96,13 @@ public:
 	void setRemoteDescription(Description description);
 	void addRemoteCandidate(Candidate candidate);
 
-	std::shared_ptr<DataChannel> addDataChannel(string label, DataChannelInit init = {});
-
-	// Equivalent to calling addDataChannel() and setLocalDescription()
 	std::shared_ptr<DataChannel> createDataChannel(string label, DataChannelInit init = {});
 
 	void onDataChannel(std::function<void(std::shared_ptr<DataChannel> dataChannel)> callback);
+
+	std::shared_ptr<Track> addTrack(Description::Media description);
+	void onTrack(std::function<void(std::shared_ptr<Track> track)> callback);
+
 	void onLocalDescription(std::function<void(Description description)> callback);
 	void onLocalCandidate(std::function<void(Candidate candidate)> callback);
 	void onStateChange(std::function<void(State state)> callback);
@@ -113,10 +114,6 @@ public:
 	size_t bytesSent();
 	size_t bytesReceived();
 	std::optional<std::chrono::milliseconds> rtt();
-
-	// Track media support requires compiling with libSRTP
-	std::shared_ptr<Track> addTrack(Description::Media description);
-	void onTrack(std::function<void(std::shared_ptr<Track> track)> callback);
 };
 
 } // namespace rtc

+ 0 - 4
include/rtc/rtc.h

@@ -193,10 +193,6 @@ RTC_EXPORT int rtcGetSelectedCandidatePair(int pc, char *local, int localSize, c
 
 // DataChannel
 RTC_EXPORT int rtcSetDataChannelCallback(int pc, rtcDataChannelCallbackFunc cb);
-RTC_EXPORT int rtcAddDataChannel(int pc, const char *label); // returns dc id
-RTC_EXPORT int rtcAddDataChannelEx(int pc, const char *label,
-                                   const rtcDataChannelInit *init); // returns dc id
-// Equivalent to calling rtcAddDataChannel() and rtcSetLocalDescription()
 RTC_EXPORT int rtcCreateDataChannel(int pc, const char *label); // returns dc id
 RTC_EXPORT int rtcCreateDataChannelEx(int pc, const char *label,
                                       const rtcDataChannelInit *init); // returns dc id

+ 5 - 13
src/capi.cpp

@@ -381,9 +381,11 @@ int rtcDeletePeerConnection(int pc) {
 	});
 }
 
-int rtcAddDataChannel(int pc, const char *label) { return rtcAddDataChannelEx(pc, label, nullptr); }
+int rtcCreateDataChannel(int pc, const char *label) {
+	return rtcCreateDataChannelEx(pc, label, nullptr);
+}
 
-int rtcAddDataChannelEx(int pc, const char *label, const rtcDataChannelInit *init) {
+int rtcCreateDataChannelEx(int pc, const char *label, const rtcDataChannelInit *init) {
 	return wrap([&] {
 		DataChannelInit dci = {};
 		if (init) {
@@ -408,7 +410,7 @@ int rtcAddDataChannelEx(int pc, const char *label, const rtcDataChannelInit *ini
 
 		auto peerConnection = getPeerConnection(pc);
 		int dc = emplaceDataChannel(
-		    peerConnection->addDataChannel(string(label ? label : ""), std::move(dci)));
+		    peerConnection->createDataChannel(string(label ? label : ""), std::move(dci)));
 
 		if (auto ptr = getUserPointer(pc))
 			rtcSetUserPointer(dc, *ptr);
@@ -417,16 +419,6 @@ int rtcAddDataChannelEx(int pc, const char *label, const rtcDataChannelInit *ini
 	});
 }
 
-int rtcCreateDataChannel(int pc, const char *label) {
-	return rtcCreateDataChannelEx(pc, label, nullptr);
-}
-
-int rtcCreateDataChannelEx(int pc, const char *label, const rtcDataChannelInit *init) {
-	int dc = rtcAddDataChannelEx(pc, label, init);
-	rtcSetLocalDescription(pc, NULL);
-	return dc;
-}
-
 int rtcDeleteDataChannel(int dc) {
 	return wrap([dc] {
 		auto dataChannel = getDataChannel(dc);

+ 17 - 19
src/peerconnection.cpp

@@ -259,7 +259,7 @@ std::optional<string> PeerConnection::remoteAddress() const {
 	return iceTransport ? iceTransport->getRemoteAddress() : nullopt;
 }
 
-shared_ptr<DataChannel> PeerConnection::addDataChannel(string label, DataChannelInit init) {
+shared_ptr<DataChannel> PeerConnection::createDataChannel(string label, DataChannelInit init) {
 	// RFC 5763: The answerer MUST use either a setup attribute value of setup:active or
 	// setup:passive. [...] Thus, setup:active is RECOMMENDED.
 	// See https://tools.ietf.org/html/rfc5763#section-5
@@ -268,6 +268,7 @@ shared_ptr<DataChannel> PeerConnection::addDataChannel(string label, DataChannel
 	auto role = iceTransport ? iceTransport->role() : Description::Role::Passive;
 
 	auto channelImpl = impl()->emplaceDataChannel(role, std::move(label), std::move(init));
+	auto channel = std::make_shared<DataChannel>(channelImpl);
 
 	if (auto transport = impl()->getSctpTransport())
 		if (transport->state() == impl::SctpTransport::State::Connected)
@@ -278,12 +279,8 @@ shared_ptr<DataChannel> PeerConnection::addDataChannel(string label, DataChannel
 	if (!local || !local->hasApplication())
 		impl()->negotiationNeeded = true;
 
-	return std::make_shared<DataChannel>(channelImpl);
-}
-
-shared_ptr<DataChannel> PeerConnection::createDataChannel(string label, DataChannelInit init) {
-	auto channel = addDataChannel(std::move(label), std::move(init));
 	setLocalDescription();
+
 	return channel;
 }
 
@@ -292,6 +289,20 @@ void PeerConnection::onDataChannel(
 	impl()->dataChannelCallback = callback;
 }
 
+std::shared_ptr<Track> PeerConnection::addTrack(Description::Media description) {
+	auto trackImpl = impl()->emplaceTrack(std::move(description));
+	auto track = std::make_shared<Track>(trackImpl);
+
+	// Renegotiation is needed for the new or updated track
+	impl()->negotiationNeeded = true;
+
+	return track;
+}
+
+void PeerConnection::onTrack(std::function<void(std::shared_ptr<Track>)> callback) {
+	impl()->trackCallback = callback;
+}
+
 void PeerConnection::onLocalDescription(std::function<void(Description description)> callback) {
 	impl()->localDescriptionCallback = callback;
 }
@@ -312,19 +323,6 @@ void PeerConnection::onSignalingStateChange(std::function<void(SignalingState st
 	impl()->signalingStateChangeCallback = callback;
 }
 
-std::shared_ptr<Track> PeerConnection::addTrack(Description::Media description) {
-	auto trackImpl = impl()->emplaceTrack(std::move(description));
-
-	// Renegotiation is needed for the new or updated track
-	impl()->negotiationNeeded = true;
-
-	return std::make_shared<Track>(trackImpl);
-}
-
-void PeerConnection::onTrack(std::function<void(std::shared_ptr<Track>)> callback) {
-	impl()->trackCallback = callback;
-}
-
 bool PeerConnection::getSelectedCandidatePair(Candidate *local, Candidate *remote) {
 	auto iceTransport = impl()->getIceTransport();
 	return iceTransport ? iceTransport->getSelectedCandidatePair(local, remote) : false;