websocket_protocol.h 827 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef _WEBSOCKET_PROTOCOL_H_
  2. #define _WEBSOCKET_PROTOCOL_H_
  3. #include "protocol.h"
  4. #include <web_socket.h>
  5. #include <freertos/FreeRTOS.h>
  6. #include <freertos/event_groups.h>
  7. #define WEBSOCKET_PROTOCOL_SERVER_HELLO_EVENT (1 << 0)
  8. class WebsocketProtocol : public Protocol {
  9. public:
  10. WebsocketProtocol();
  11. ~WebsocketProtocol();
  12. bool Start() override;
  13. bool SendAudio(std::unique_ptr<AudioStreamPacket> packet) override;
  14. bool OpenAudioChannel() override;
  15. void CloseAudioChannel() override;
  16. bool IsAudioChannelOpened() const override;
  17. private:
  18. EventGroupHandle_t event_group_handle_;
  19. std::unique_ptr<WebSocket> websocket_;
  20. int version_ = 1;
  21. void ParseServerHello(const cJSON* root);
  22. bool SendText(const std::string& text) override;
  23. std::string GetHelloMessage();
  24. };
  25. #endif