Paul-Louis Ageneau 3 سال پیش
والد
کامیت
f1fe243270
3فایلهای تغییر یافته به همراه41 افزوده شده و 2 حذف شده
  1. 15 2
      test/capi_track.cpp
  2. 14 0
      test/connectivity.cpp
  3. 12 0
      test/turn_connectivity.cpp

+ 15 - 2
test/capi_track.cpp

@@ -78,6 +78,7 @@ static void RTC_API openCallback(int id, void *ptr) {
 static void RTC_API closedCallback(int id, void *ptr) {
 	Peer *peer = (Peer *)ptr;
 	peer->connected = false;
+	printf("Track %d: Closed\n", peer == peer1 ? 1 : 2);
 }
 
 static void RTC_API trackCallback(int pc, int tr, void *ptr) {
@@ -89,16 +90,25 @@ static void RTC_API trackCallback(int pc, int tr, void *ptr) {
 	char buffer[1024];
 	if (rtcGetTrackDescription(tr, buffer, 1024) >= 0)
 		printf("Track %d: Received with media description: \n%s\n", peer == peer1 ? 1 : 2, buffer);
+	else
+		fprintf(stderr, "rtcGetTrackDescription failed\n");
 }
 
 static Peer *createPeer(const rtcConfiguration *config) {
 	Peer *peer = (Peer *)malloc(sizeof(Peer));
 	if (!peer)
 		return nullptr;
+
 	memset(peer, 0, sizeof(Peer));
 
 	// Create peer connection
 	peer->pc = rtcCreatePeerConnection(config);
+	if (peer->pc < 0) {
+		fprintf(stderr, "PeerConnection creation failed\n");
+		free(peer);
+		return nullptr;
+	}
+
 	rtcSetUserPointer(peer->pc, peer);
 	rtcSetTrackCallback(peer->pc, trackCallback);
 	rtcSetLocalDescriptionCallback(peer->pc, descriptionCallback);
@@ -106,15 +116,18 @@ static Peer *createPeer(const rtcConfiguration *config) {
 	rtcSetStateChangeCallback(peer->pc, stateChangeCallback);
 	rtcSetGatheringStateChangeCallback(peer->pc, gatheringStateCallback);
 
+	peer->tr = -1;
 	return peer;
 }
 
 static void deletePeer(Peer *peer) {
 	if (peer) {
-		if (peer->tr)
+		if (peer->tr >= 0)
 			rtcDeleteTrack(peer->tr);
-		if (peer->pc)
+
+		if (peer->pc >= 0)
 			rtcDeletePeerConnection(peer->pc);
+
 		free(peer);
 	}
 }

+ 14 - 0
test/connectivity.cpp

@@ -112,6 +112,10 @@ void test_connectivity() {
 				dc->send("Hello from 2");
 		});
 
+		dc->onClosed([]() {
+			cout << "DataChannel 2: Closed" << endl;
+		});
+
 		dc->onMessage([](variant<binary, string> message) {
 			if (holds_alternative<string>(message)) {
 				cout << "Message 2: " << get<string>(message) << endl;
@@ -130,6 +134,10 @@ void test_connectivity() {
 		}
 	});
 
+	dc1->onClosed([]() {
+		cout << "DataChannel 1: Closed" << endl;
+	});
+
 	dc1->onMessage([](const variant<binary, string> &message) {
 		if (holds_alternative<string>(message)) {
 			cout << "Message 1: " << get<string>(message) << endl;
@@ -195,12 +203,18 @@ void test_connectivity() {
 	});
 
 	auto second1 = pc1.createDataChannel("second");
+
 	second1->onOpen([wsecond1 = make_weak_ptr(second1)]() {
 		if (auto second1 = wsecond1.lock()) {
 			cout << "Second DataChannel 1: Open" << endl;
 			second1->send("Second hello from 1");
 		}
 	});
+
+	second1->onClosed([]() {
+		cout << "Second DataChannel 1: Closed" << endl;
+	});
+
 	second1->onMessage([](const variant<binary, string> &message) {
 		if (holds_alternative<string>(message)) {
 			cout << "Second Message 1: " << get<string>(message) << endl;

+ 12 - 0
test/turn_connectivity.cpp

@@ -127,6 +127,12 @@ void test_turn_connectivity() {
 		cout << "DataChannel 1: Open" << endl;
 		dc1->send("Hello from 1");
 	});
+
+
+	dc1->onClosed([]() {
+		cout << "DataChannel 1: Closed" << endl;
+	});
+
 	dc1->onMessage([](const variant<binary, string> &message) {
 		if (holds_alternative<string>(message)) {
 			cout << "Message 1: " << get<string>(message) << endl;
@@ -198,6 +204,7 @@ void test_turn_connectivity() {
 	});
 
 	auto second1 = pc1.createDataChannel("second");
+
 	second1->onOpen([wsecond1 = make_weak_ptr(second1)]() {
 		auto second1 = wsecond1.lock();
 		if (!second1)
@@ -206,6 +213,11 @@ void test_turn_connectivity() {
 		cout << "Second DataChannel 1: Open" << endl;
 		second1->send("Second hello from 1");
 	});
+
+	second1->onClosed([]() {
+		cout << "Second DataChannel 1: Closed" << endl;
+	});
+
 	second1->onMessage([](const variant<binary, string> &message) {
 		if (holds_alternative<string>(message)) {
 			cout << "Second Message 1: " << get<string>(message) << endl;