浏览代码

Added ICE state in tests

Paul-Louis Ageneau 1 年之前
父节点
当前提交
8eb20ad7d0
共有 5 个文件被更改,包括 44 次插入4 次删除
  1. 14 0
      test/capi_connectivity.cpp
  2. 15 1
      test/connectivity.cpp
  3. 1 1
      test/negotiated.cpp
  4. 1 1
      test/track.cpp
  5. 13 1
      test/turn_connectivity.cpp

+ 14 - 0
test/capi_connectivity.cpp

@@ -23,6 +23,7 @@ static void sleep(unsigned int secs) { Sleep(secs * 1000); }
 
 typedef struct {
 	rtcState state;
+	rtcIceState iceState;
 	rtcGatheringState gatheringState;
 	rtcSignalingState signalingState;
 	int pc;
@@ -53,6 +54,12 @@ static void RTC_API stateChangeCallback(int pc, rtcState state, void *ptr) {
 	printf("State %d: %d\n", peer == peer1 ? 1 : 2, (int)state);
 }
 
+static void RTC_API iceStateChangeCallback(int pc, rtcIceState state, void *ptr) {
+	Peer *peer = (Peer *)ptr;
+	peer->iceState = state;
+	printf("ICE state %d: %d\n", peer == peer1 ? 1 : 2, (int)state);
+}
+
 static void RTC_API gatheringStateCallback(int pc, rtcGatheringState state, void *ptr) {
 	Peer *peer = (Peer *)ptr;
 	peer->gatheringState = state;
@@ -158,6 +165,7 @@ static Peer *createPeer(const rtcConfiguration *config) {
 	rtcSetLocalDescriptionCallback(peer->pc, descriptionCallback);
 	rtcSetLocalCandidateCallback(peer->pc, candidateCallback);
 	rtcSetStateChangeCallback(peer->pc, stateChangeCallback);
+	rtcSetIceStateChangeCallback(peer->pc, iceStateChangeCallback);
 	rtcSetGatheringStateChangeCallback(peer->pc, gatheringStateCallback);
 	rtcSetSignalingStateChangeCallback(peer->pc, signalingStateCallback);
 
@@ -246,6 +254,12 @@ int test_capi_connectivity_main() {
 		goto error;
 	}
 
+	if ((peer1->iceState != RTC_ICE_CONNECTED && peer1->iceState != RTC_ICE_COMPLETED) ||
+	    (peer2->iceState != RTC_ICE_CONNECTED && peer2->iceState != RTC_ICE_COMPLETED)) {
+		fprintf(stderr, "PeerConnection is not connected\n");
+		goto error;
+	}
+
 	if (!peer1->connected || !peer2->connected) {
 		fprintf(stderr, "DataChannel is not connected\n");
 		goto error;

+ 15 - 1
test/connectivity.cpp

@@ -68,6 +68,10 @@ void test_connectivity(bool signal_wrong_fingerprint) {
 
 	pc1.onStateChange([](PeerConnection::State state) { cout << "State 1: " << state << endl; });
 
+	pc1.onIceStateChange([](PeerConnection::IceState state) {
+		cout << "ICE state 1: " << state << endl;
+	});
+
 	pc1.onGatheringStateChange([](PeerConnection::GatheringState state) {
 		cout << "Gathering state 1: " << state << endl;
 	});
@@ -88,6 +92,10 @@ void test_connectivity(bool signal_wrong_fingerprint) {
 
 	pc2.onStateChange([](PeerConnection::State state) { cout << "State 2: " << state << endl; });
 
+	pc2.onIceStateChange([](PeerConnection::IceState state) {
+		cout << "ICE state 2: " << state << endl;
+	});
+
 	pc2.onGatheringStateChange([](PeerConnection::GatheringState state) {
 		cout << "Gathering state 2: " << state << endl;
 	});
@@ -144,10 +152,16 @@ void test_connectivity(bool signal_wrong_fingerprint) {
 	while ((!(adc2 = std::atomic_load(&dc2)) || !adc2->isOpen() || !dc1->isOpen()) && attempts--)
 		this_thread::sleep_for(1s);
 
-	if (pc1.state() != PeerConnection::State::Connected &&
+	if (pc1.state() != PeerConnection::State::Connected ||
 	    pc2.state() != PeerConnection::State::Connected)
 		throw runtime_error("PeerConnection is not connected");
 
+	if ((pc1.iceState() != PeerConnection::IceState::Connected &&
+	     pc1.iceState() != PeerConnection::IceState::Completed) ||
+	    (pc2.iceState() != PeerConnection::IceState::Connected &&
+	     pc2.iceState() != PeerConnection::IceState::Completed))
+		throw runtime_error("ICE is not connected");
+
 	if (!adc2 || !adc2->isOpen() || !dc1->isOpen())
 		throw runtime_error("DataChannel is not open");
 

+ 1 - 1
test/negotiated.cpp

@@ -64,7 +64,7 @@ void test_negotiated() {
 	while (!negotiated1->isOpen() || !negotiated2->isOpen() && attempts--)
 		this_thread::sleep_for(1s);
 
-	if (pc1.state() != PeerConnection::State::Connected &&
+	if (pc1.state() != PeerConnection::State::Connected ||
 	    pc2.state() != PeerConnection::State::Connected)
 		throw runtime_error("PeerConnection is not connected");
 

+ 1 - 1
test/track.cpp

@@ -104,7 +104,7 @@ void test_track() {
 	while ((!(at2 = std::atomic_load(&t2)) || !at2->isOpen() || !t1->isOpen()) && attempts--)
 		this_thread::sleep_for(1s);
 
-	if (pc1.state() != PeerConnection::State::Connected &&
+	if (pc1.state() != PeerConnection::State::Connected ||
 	    pc2.state() != PeerConnection::State::Connected)
 		throw runtime_error("PeerConnection is not connected");
 

+ 13 - 1
test/turn_connectivity.cpp

@@ -40,6 +40,9 @@ void test_turn_connectivity() {
 
 	pc1.onStateChange([](PeerConnection::State state) { cout << "State 1: " << state << endl; });
 
+	pc1.onIceStateChange(
+	    [](PeerConnection::IceState state) { cout << "ICE state 1: " << state << endl; });
+
 	pc1.onGatheringStateChange([&pc1, &pc2](PeerConnection::GatheringState state) {
 		cout << "Gathering state 1: " << state << endl;
 		if (state == PeerConnection::GatheringState::Complete) {
@@ -69,6 +72,9 @@ void test_turn_connectivity() {
 
 	pc2.onStateChange([](PeerConnection::State state) { cout << "State 2: " << state << endl; });
 
+	pc2.onIceStateChange(
+	    [](PeerConnection::IceState state) { cout << "ICE state 2: " << state << endl; });
+
 	pc2.onGatheringStateChange([](PeerConnection::GatheringState state) {
 		cout << "Gathering state 2: " << state << endl;
 	});
@@ -125,10 +131,16 @@ void test_turn_connectivity() {
 	while ((!(adc2 = std::atomic_load(&dc2)) || !adc2->isOpen() || !dc1->isOpen()) && attempts--)
 		this_thread::sleep_for(1s);
 
-	if (pc1.state() != PeerConnection::State::Connected &&
+	if (pc1.state() != PeerConnection::State::Connected ||
 	    pc2.state() != PeerConnection::State::Connected)
 		throw runtime_error("PeerConnection is not connected");
 
+	if ((pc1.iceState() != PeerConnection::IceState::Connected &&
+	     pc1.iceState() != PeerConnection::IceState::Completed) ||
+	    (pc2.iceState() != PeerConnection::IceState::Connected &&
+	     pc2.iceState() != PeerConnection::IceState::Completed))
+		throw runtime_error("ICE is not connected");
+
 	if (!adc2 || !adc2->isOpen() || !dc1->isOpen())
 		throw runtime_error("DataChannel is not open");