mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 15:15:28 +00:00
Introduced onOpen() callback on receiving side in tests
This commit is contained in:
@ -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
|
||||
|
@ -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];
|
||||
|
@ -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;
|
||||
|
||||
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;
|
||||
|
||||
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)) {
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user