Added bidirectional message exchange in test

This commit is contained in:
Paul-Louis Ageneau
2019-09-30 19:48:41 +02:00
parent 4ae3d51f96
commit bca4d89f93

View File

@ -67,16 +67,22 @@ int main(int argc, char **argv) {
pc2->onDataChannel([&dc2](shared_ptr<DataChannel> dc) { pc2->onDataChannel([&dc2](shared_ptr<DataChannel> dc) {
cout << "Got a DataChannel with label: " << dc->label() << endl; cout << "Got a DataChannel with label: " << dc->label() << endl;
dc2 = dc; dc2 = dc;
dc2->send("Hello world!"); dc2->onMessage([](const variant<binary, string> &message) {
if (holds_alternative<string>(message)) {
cout << "Received 2: " << get<string>(message) << endl;
}
});
dc2->send("Hello from 2");
}); });
auto dc1 = pc1->createDataChannel("test"); auto dc1 = pc1->createDataChannel("test");
dc1->onOpen([dc1]() { dc1->onOpen([dc1]() {
cout << "DataChannel open: " << dc1->label() << endl; cout << "DataChannel open: " << dc1->label() << endl;
dc1->send("Hello from 1");
}); });
dc1->onMessage([](const variant<binary, string> &message) { dc1->onMessage([](const variant<binary, string> &message) {
if (holds_alternative<string>(message)) { if (holds_alternative<string>(message)) {
cout << "Received: " << get<string>(message) << endl; cout << "Received 1: " << get<string>(message) << endl;
} }
}); });