main.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Copyright (c) 2019 Paul-Louis Ageneau
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <peerconnection.hpp>
  19. #include <chrono>
  20. #include <iostream>
  21. #include <memory>
  22. #include <thread>
  23. using namespace rtc;
  24. using namespace std;
  25. int main(int argc, char **argv) {
  26. IceConfiguration config;
  27. auto pc1 = std::make_shared<PeerConnection>(config);
  28. auto pc2 = std::make_shared<PeerConnection>(config);
  29. pc1->onLocalDescription([pc2](const Description &sdp) {
  30. cout << "Description 1: " << sdp << endl;
  31. pc2->setRemoteDescription(sdp);
  32. });
  33. pc1->onLocalCandidate([pc2](const optional<Candidate> &candidate) {
  34. if (candidate) {
  35. cout << "Candidate 1: " << *candidate << endl;
  36. pc2->setRemoteCandidate(*candidate);
  37. }
  38. });
  39. pc2->onLocalDescription([pc1](const Description &sdp) {
  40. cout << "Description 2: " << sdp << endl;
  41. pc1->setRemoteDescription(sdp);
  42. });
  43. pc2->onLocalCandidate([pc1](const optional<Candidate> &candidate) {
  44. if (candidate) {
  45. cout << "Candidate 2: " << *candidate << endl;
  46. pc1->setRemoteCandidate(*candidate);
  47. }
  48. });
  49. shared_ptr<DataChannel> dc2;
  50. pc2->onDataChannel([&dc2](shared_ptr<DataChannel> dc) {
  51. cout << "Got a DataChannel with label: " << dc->label() << endl;
  52. dc2 = dc;
  53. });
  54. auto dc1 = pc1->createDataChannel("test");
  55. dc1->onOpen([dc1]() {
  56. cout << "DataChannel open: " << dc1->label() << endl;
  57. });
  58. this_thread::sleep_for(10s);
  59. }