websocketserver.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Copyright (c) 2020-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. #ifndef RTC_IMPL_WEBSOCKETSERVER_H
  19. #define RTC_IMPL_WEBSOCKETSERVER_H
  20. #if RTC_ENABLE_WEBSOCKET
  21. #include "certificate.hpp"
  22. #include "common.hpp"
  23. #include "init.hpp"
  24. #include "message.hpp"
  25. #include "tcpserver.hpp"
  26. #include "websocket.hpp"
  27. #include "rtc/websocket.hpp"
  28. #include "rtc/websocketserver.hpp"
  29. #include <atomic>
  30. #include <thread>
  31. namespace rtc::impl {
  32. struct WebSocketServer final : public std::enable_shared_from_this<WebSocketServer> {
  33. using Configuration = rtc::WebSocketServer::Configuration;
  34. WebSocketServer(Configuration config_);
  35. ~WebSocketServer();
  36. void stop();
  37. const Configuration config;
  38. unique_ptr<TcpServer> tcpServer;
  39. synchronized_callback<shared_ptr<rtc::WebSocket>> clientCallback;
  40. private:
  41. const init_token mInitToken = Init::Instance().token();
  42. void runLoop();
  43. certificate_ptr mCertificate;
  44. std::thread mThread;
  45. std::atomic<bool> mStopped;
  46. };
  47. } // namespace rtc::impl
  48. #endif
  49. #endif // RTC_IMPL_WEBSOCKET_H