datachannel.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef RTC_DATA_CHANNEL_H
  19. #define RTC_DATA_CHANNEL_H
  20. #include "channel.hpp"
  21. #include "include.hpp"
  22. #include "message.hpp"
  23. #include "reliability.hpp"
  24. #include <chrono>
  25. #include <functional>
  26. #include <variant>
  27. namespace rtc {
  28. class SctpTransport;
  29. class PeerConnection;
  30. class DataChannel : public Channel {
  31. public:
  32. DataChannel(unsigned int stream_, string label_, string protocol_, Reliability reliability_);
  33. DataChannel(unsigned int stream, std::shared_ptr<SctpTransport> sctpTransport);
  34. ~DataChannel();
  35. void close(void);
  36. void send(const std::variant<binary, string> &data);
  37. void send(const byte *data, size_t size);
  38. unsigned int stream() const;
  39. string label() const;
  40. string protocol() const;
  41. Reliability reliability() const;
  42. bool isOpen(void) const;
  43. bool isClosed(void) const;
  44. private:
  45. void open(std::shared_ptr<SctpTransport> sctpTransport);
  46. void incoming(message_ptr message);
  47. void processOpenMessage(message_ptr message);
  48. const unsigned int mStream;
  49. std::shared_ptr<SctpTransport> mSctpTransport;
  50. string mLabel;
  51. string mProtocol;
  52. std::shared_ptr<Reliability> mReliability;
  53. bool mIsOpen = false;
  54. bool mIsClosed = false;
  55. friend class PeerConnection;
  56. };
  57. } // namespace rtc
  58. #endif