forked from xiaozhi/xiaozhi-esp32
Update to esp-ml307@3.1.1
This commit is contained in:
@@ -16,12 +16,6 @@ MqttProtocol::MqttProtocol() {
|
||||
|
||||
MqttProtocol::~MqttProtocol() {
|
||||
ESP_LOGI(TAG, "MqttProtocol deinit");
|
||||
if (udp_ != nullptr) {
|
||||
delete udp_;
|
||||
}
|
||||
if (mqtt_ != nullptr) {
|
||||
delete mqtt_;
|
||||
}
|
||||
vEventGroupDelete(event_group_handle_);
|
||||
}
|
||||
|
||||
@@ -32,7 +26,7 @@ bool MqttProtocol::Start() {
|
||||
bool MqttProtocol::StartMqttClient(bool report_error) {
|
||||
if (mqtt_ != nullptr) {
|
||||
ESP_LOGW(TAG, "Mqtt client already started");
|
||||
delete mqtt_;
|
||||
mqtt_.reset();
|
||||
}
|
||||
|
||||
Settings settings("mqtt", false);
|
||||
@@ -150,10 +144,7 @@ bool MqttProtocol::SendAudio(std::unique_ptr<AudioStreamPacket> packet) {
|
||||
void MqttProtocol::CloseAudioChannel() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(channel_mutex_);
|
||||
if (udp_ != nullptr) {
|
||||
delete udp_;
|
||||
udp_ = nullptr;
|
||||
}
|
||||
udp_.reset();
|
||||
}
|
||||
|
||||
std::string message = "{";
|
||||
@@ -193,10 +184,6 @@ bool MqttProtocol::OpenAudioChannel() {
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(channel_mutex_);
|
||||
if (udp_ != nullptr) {
|
||||
delete udp_;
|
||||
}
|
||||
|
||||
auto network = Board::GetInstance().GetNetwork();
|
||||
udp_ = network->CreateUdp(2);
|
||||
udp_->OnMessage([this](const std::string& data) {
|
||||
|
||||
@@ -37,8 +37,8 @@ private:
|
||||
std::string publish_topic_;
|
||||
|
||||
std::mutex channel_mutex_;
|
||||
Mqtt* mqtt_ = nullptr;
|
||||
Udp* udp_ = nullptr;
|
||||
std::unique_ptr<Mqtt> mqtt_;
|
||||
std::unique_ptr<Udp> udp_;
|
||||
mbedtls_aes_context aes_ctx_;
|
||||
std::string aes_nonce_;
|
||||
std::string udp_server_;
|
||||
|
||||
@@ -17,9 +17,6 @@ WebsocketProtocol::WebsocketProtocol() {
|
||||
}
|
||||
|
||||
WebsocketProtocol::~WebsocketProtocol() {
|
||||
if (websocket_ != nullptr) {
|
||||
delete websocket_;
|
||||
}
|
||||
vEventGroupDelete(event_group_handle_);
|
||||
}
|
||||
|
||||
@@ -79,17 +76,10 @@ bool WebsocketProtocol::IsAudioChannelOpened() const {
|
||||
}
|
||||
|
||||
void WebsocketProtocol::CloseAudioChannel() {
|
||||
if (websocket_ != nullptr) {
|
||||
delete websocket_;
|
||||
websocket_ = nullptr;
|
||||
}
|
||||
websocket_.reset();
|
||||
}
|
||||
|
||||
bool WebsocketProtocol::OpenAudioChannel() {
|
||||
if (websocket_ != nullptr) {
|
||||
delete websocket_;
|
||||
}
|
||||
|
||||
Settings settings("websocket", false);
|
||||
std::string url = settings.GetString("url");
|
||||
std::string token = settings.GetString("token");
|
||||
@@ -102,6 +92,10 @@ bool WebsocketProtocol::OpenAudioChannel() {
|
||||
|
||||
auto network = Board::GetInstance().GetNetwork();
|
||||
websocket_ = network->CreateWebSocket(1);
|
||||
if (websocket_ == nullptr) {
|
||||
ESP_LOGE(TAG, "Failed to create websocket");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!token.empty()) {
|
||||
// If token not has a space, add "Bearer " prefix
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
private:
|
||||
EventGroupHandle_t event_group_handle_;
|
||||
WebSocket* websocket_ = nullptr;
|
||||
std::unique_ptr<WebSocket> websocket_;
|
||||
int version_ = 1;
|
||||
|
||||
void ParseServerHello(const cJSON* root);
|
||||
|
||||
Reference in New Issue
Block a user