Browse Source

Merge pull request #280 from paullouisageneau/default-data-mid

Change default data mid
Paul-Louis Ageneau 4 years ago
parent
commit
684b7ba925
3 changed files with 12 additions and 16 deletions
  1. 8 9
      examples/client/main.cpp
  2. 4 1
      src/peerconnection.cpp
  3. 0 6
      test/capi_connectivity.cpp

+ 8 - 9
examples/client/main.cpp

@@ -36,7 +36,6 @@
 #include <thread>
 #include <thread>
 #include <unordered_map>
 #include <unordered_map>
 
 
-
 using namespace rtc;
 using namespace rtc;
 using namespace std;
 using namespace std;
 using namespace std::chrono_literals;
 using namespace std::chrono_literals;
@@ -167,12 +166,12 @@ int main(int argc, char **argv) try {
 
 
 		dc->onClosed([id]() { cout << "DataChannel from " << id << " closed" << endl; });
 		dc->onClosed([id]() { cout << "DataChannel from " << id << " closed" << endl; });
 
 
-		dc->onMessage([id, wdc = make_weak_ptr(dc)](const variant<binary, string> &message) {
-			if (holds_alternative<string>(message))
-				cout << "Message from " << id << " received: " << get<string>(message) << endl;
+		dc->onMessage([id, wdc = make_weak_ptr(dc)](variant<binary, string> data) {
+			if (holds_alternative<string>(data))
+				cout << "Message from " << id << " received: " << get<string>(data) << endl;
 			else
 			else
 				cout << "Binary message from " << id
 				cout << "Binary message from " << id
-				     << " received, size=" << get<binary>(message).size() << endl;
+				     << " received, size=" << get<binary>(data).size() << endl;
 		});
 		});
 
 
 		dataChannelMap.emplace(id, dc);
 		dataChannelMap.emplace(id, dc);
@@ -225,12 +224,12 @@ shared_ptr<PeerConnection> createPeerConnection(const Configuration &config,
 
 
 		dc->onClosed([id]() { cout << "DataChannel from " << id << " closed" << endl; });
 		dc->onClosed([id]() { cout << "DataChannel from " << id << " closed" << endl; });
 
 
-		dc->onMessage([id, wdc = make_weak_ptr(dc)](const variant<binary, string> &message) {
-			if (holds_alternative<string>(message))
-				cout << "Message from " << id << " received: " << get<string>(message) << endl;
+		dc->onMessage([id, wdc = make_weak_ptr(dc)](variant<binary, string> data) {
+			if (holds_alternative<string>(data))
+				cout << "Message from " << id << " received: " << get<string>(data) << endl;
 			else
 			else
 				cout << "Binary message from " << id
 				cout << "Binary message from " << id
-				     << " received, size=" << get<binary>(message).size() << endl;
+				     << " received, size=" << get<binary>(data).size() << endl;
 		});
 		});
 
 
 		dc->send("Hello from " + localId);
 		dc->send("Hello from " + localId);

+ 4 - 1
src/peerconnection.cpp

@@ -1014,7 +1014,10 @@ void PeerConnection::processLocalDescription(Description description) {
 		if (!description.hasApplication()) {
 		if (!description.hasApplication()) {
 			std::shared_lock lock(mDataChannelsMutex);
 			std::shared_lock lock(mDataChannelsMutex);
 			if (!mDataChannels.empty()) {
 			if (!mDataChannels.empty()) {
-				Description::Application app("data");
+				unsigned int m = 0;
+				while (description.hasMid(std::to_string(m)))
+					++m;
+				Description::Application app(std::to_string(m));
 				app.setSctpPort(DEFAULT_SCTP_PORT);
 				app.setSctpPort(DEFAULT_SCTP_PORT);
 				app.setMaxMessageSize(LOCAL_MAX_MESSAGE_SIZE);
 				app.setMaxMessageSize(LOCAL_MAX_MESSAGE_SIZE);
 
 

+ 0 - 6
test/capi_connectivity.cpp

@@ -227,12 +227,6 @@ int test_capi_connectivity_main() {
 		goto error;
 		goto error;
 	}
 	}
 
 
-	if (peer1->signalingState != RTC_SIGNALING_STABLE ||
-	    peer2->signalingState != RTC_SIGNALING_STABLE) {
-		fprintf(stderr, "Signaling state is not stable\n");
-		goto error;
-	}
-
 	if (!peer1->connected || !peer2->connected) {
 	if (!peer1->connected || !peer2->connected) {
 		fprintf(stderr, "DataChannel is not connected\n");
 		fprintf(stderr, "DataChannel is not connected\n");
 		goto error;
 		goto error;