Introduced onOpen() callback on receiving side in tests

This commit is contained in:
Paul-Louis Ageneau
2021-04-14 21:51:36 +02:00
parent d86de619dc
commit 5346d31cc1
4 changed files with 32 additions and 22 deletions

View File

@ -137,11 +137,11 @@ static void RTC_API dataChannelCallback(int pc, int dc, void *ptr) {
return;
}
rtcSetOpenCallback(dc, openCallback);
rtcSetClosedCallback(dc, closedCallback);
rtcSetMessageCallback(dc, messageCallback);
peer->dc = dc;
peer->connected = true;
const char *message = peer == peer1 ? "Hello from 1" : "Hello from 2";
rtcSendMessage(peer->dc, message, -1); // negative size indicates a null-terminated string

View File

@ -83,7 +83,7 @@ static void RTC_API closedCallback(int id, void *ptr) {
static void RTC_API trackCallback(int pc, int tr, void *ptr) {
Peer *peer = (Peer *)ptr;
peer->tr = tr;
peer->connected = true;
rtcSetOpenCallback(tr, openCallback);
rtcSetClosedCallback(tr, closedCallback);
char buffer[1024];

View File

@ -107,26 +107,29 @@ void test_connectivity() {
return;
}
dc->onOpen([wdc = make_weak_ptr(dc)]() {
if (auto dc = wdc.lock())
dc->send("Hello from 2");
});
dc->onMessage([](variant<binary, string> message) {
if (holds_alternative<string>(message)) {
cout << "Message 2: " << get<string>(message) << endl;
}
});
dc->send("Hello from 2");
std::atomic_store(&dc2, dc);
});
auto dc1 = pc1.createDataChannel("test");
dc1->onOpen([wdc1 = make_weak_ptr(dc1)]() {
auto dc1 = wdc1.lock();
if (!dc1)
return;
cout << "DataChannel 1: Open" << endl;
dc1->send("Hello from 1");
dc1->onOpen([wdc1 = make_weak_ptr(dc1)]() {
if (auto dc1 = wdc1.lock()) {
cout << "DataChannel 1: Open" << endl;
dc1->send("Hello from 1");
}
});
dc1->onMessage([](const variant<binary, string> &message) {
if (holds_alternative<string>(message)) {
cout << "Message 1: " << get<string>(message) << endl;
@ -177,25 +180,26 @@ void test_connectivity() {
return;
}
dc->onOpen([wdc = make_weak_ptr(dc)]() {
if (auto dc = wdc.lock())
dc->send("Second hello from 2");
});
dc->onMessage([](variant<binary, string> message) {
if (holds_alternative<string>(message)) {
cout << "Second Message 2: " << get<string>(message) << endl;
}
});
dc->send("Send hello from 2");
std::atomic_store(&second2, dc);
});
auto second1 = pc1.createDataChannel("second");
second1->onOpen([wsecond1 = make_weak_ptr(dc1)]() {
auto second1 = wsecond1.lock();
if (!second1)
return;
cout << "Second DataChannel 1: Open" << endl;
second1->send("Second hello from 1");
if (auto second1 = wsecond1.lock()) {
cout << "Second DataChannel 1: Open" << endl;
second1->send("Second hello from 1");
}
});
dc1->onMessage([](const variant<binary, string> &message) {
if (holds_alternative<string>(message)) {

View File

@ -108,14 +108,17 @@ void test_turn_connectivity() {
return;
}
dc->onOpen([wdc = make_weak_ptr(dc)]() {
if (auto dc = wdc.lock())
dc->send("Hello from 2");
});
dc->onMessage([](variant<binary, string> message) {
if (holds_alternative<string>(message)) {
cout << "Message 2: " << get<string>(message) << endl;
}
});
dc->send("Hello from 2");
std::atomic_store(&dc2, dc);
});
@ -175,14 +178,17 @@ void test_turn_connectivity() {
return;
}
dc->onOpen([wdc = make_weak_ptr(dc)]() {
if (auto dc = wdc.lock())
dc->send("Second hello from 2");
});
dc->onMessage([](variant<binary, string> message) {
if (holds_alternative<string>(message)) {
cout << "Second Message 2: " << get<string>(message) << endl;
}
});
dc->send("Send hello from 2");
std::atomic_store(&second2, dc);
});