2024-11-16 05:49:35 +08:00
|
|
|
#ifndef _WEBSOCKET_PROTOCOL_H_
|
|
|
|
|
#define _WEBSOCKET_PROTOCOL_H_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "protocol.h"
|
|
|
|
|
|
|
|
|
|
#include <web_socket.h>
|
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
|
#include <freertos/event_groups.h>
|
|
|
|
|
|
|
|
|
|
#define WEBSOCKET_PROTOCOL_SERVER_HELLO_EVENT (1 << 0)
|
|
|
|
|
|
|
|
|
|
class WebsocketProtocol : public Protocol {
|
|
|
|
|
public:
|
|
|
|
|
WebsocketProtocol();
|
|
|
|
|
~WebsocketProtocol();
|
|
|
|
|
|
2025-04-21 06:54:50 +08:00
|
|
|
bool Start() override;
|
2025-07-19 22:45:22 +08:00
|
|
|
bool SendAudio(std::unique_ptr<AudioStreamPacket> packet) override;
|
2024-11-16 05:49:35 +08:00
|
|
|
bool OpenAudioChannel() override;
|
|
|
|
|
void CloseAudioChannel() override;
|
|
|
|
|
bool IsAudioChannelOpened() const override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
EventGroupHandle_t event_group_handle_;
|
2025-07-21 05:46:05 +08:00
|
|
|
std::unique_ptr<WebSocket> websocket_;
|
2025-04-28 16:29:33 +08:00
|
|
|
int version_ = 1;
|
2024-11-16 05:49:35 +08:00
|
|
|
|
|
|
|
|
void ParseServerHello(const cJSON* root);
|
2025-04-09 09:13:18 +08:00
|
|
|
bool SendText(const std::string& text) override;
|
2025-05-22 19:19:36 +08:00
|
|
|
std::string GetHelloMessage();
|
2024-11-16 05:49:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|