websocketserver.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright (c) 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_WEBSOCKETSERVER_H
  19. #define RTC_WEBSOCKETSERVER_H
  20. #if RTC_ENABLE_WEBSOCKET
  21. #include "common.hpp"
  22. #include "websocket.hpp"
  23. namespace rtc {
  24. namespace impl {
  25. struct WebSocketServer;
  26. }
  27. class RTC_CPP_EXPORT WebSocketServer final : private CheshireCat<impl::WebSocketServer> {
  28. public:
  29. struct Configuration {
  30. uint16_t port = 8080;
  31. bool enableTls = false;
  32. optional<string> certificatePemFile;
  33. optional<string> keyPemFile;
  34. optional<string> keyPemPass;
  35. };
  36. WebSocketServer();
  37. WebSocketServer(Configuration config);
  38. ~WebSocketServer();
  39. void stop();
  40. uint16_t port() const;
  41. void onClient(std::function<void(shared_ptr<WebSocket>)> callback);
  42. private:
  43. using CheshireCat<impl::WebSocketServer>::impl;
  44. };
  45. } // namespace rtc
  46. #endif
  47. #endif // RTC_WEBSOCKET_H