datachannel.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Copyright (c) 2019-2021 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 "datachannel.hpp"
  19. #include "globals.hpp"
  20. #include "common.hpp"
  21. #include "peerconnection.hpp"
  22. #include "impl/datachannel.hpp"
  23. #include "impl/peerconnection.hpp"
  24. #ifdef _WIN32
  25. #include <winsock2.h>
  26. #else
  27. #include <arpa/inet.h>
  28. #endif
  29. namespace rtc {
  30. DataChannel::DataChannel(impl_ptr<impl::DataChannel> impl)
  31. : CheshireCat<impl::DataChannel>(impl),
  32. Channel(std::dynamic_pointer_cast<impl::Channel>(impl)) {}
  33. DataChannel::~DataChannel() { close(); }
  34. void DataChannel::close() { return impl()->close(); }
  35. uint16_t DataChannel::stream() const { return impl()->stream(); }
  36. uint16_t DataChannel::id() const { return impl()->stream(); }
  37. string DataChannel::label() const { return impl()->label(); }
  38. string DataChannel::protocol() const { return impl()->protocol(); }
  39. Reliability DataChannel::reliability() const { return impl()->reliability(); }
  40. bool DataChannel::isOpen(void) const { return impl()->isOpen(); }
  41. bool DataChannel::isClosed(void) const { return impl()->isClosed(); }
  42. size_t DataChannel::maxMessageSize() const { return impl()->maxMessageSize(); }
  43. bool DataChannel::send(message_variant data) {
  44. return impl()->outgoing(make_message(std::move(data)));
  45. }
  46. bool DataChannel::send(const byte *data, size_t size) {
  47. return impl()->outgoing(std::make_shared<Message>(data, data + size, Message::Binary));
  48. }
  49. } // namespace rtc