|
@@ -19,10 +19,7 @@
|
|
|
#include "esphome/core/log.h"
|
|
#include "esphome/core/log.h"
|
|
|
#include "esphome/core/util.h"
|
|
#include "esphome/core/util.h"
|
|
|
|
|
|
|
|
-#if ESPHOME_VERSION_CODE >= VERSION_CODE(2021, 10, 0)
|
|
|
|
|
#include "esphome/components/network/util.h"
|
|
#include "esphome/components/network/util.h"
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
static const char *TAG = "streamserver";
|
|
static const char *TAG = "streamserver";
|
|
|
|
|
|
|
@@ -62,37 +59,21 @@ void StreamServerComponent::read() {
|
|
|
while ((len = this->stream_->available()) > 0) {
|
|
while ((len = this->stream_->available()) > 0) {
|
|
|
char buf[128];
|
|
char buf[128];
|
|
|
len = std::min(len, 128);
|
|
len = std::min(len, 128);
|
|
|
-#if ESPHOME_VERSION_CODE >= VERSION_CODE(2021, 10, 0)
|
|
|
|
|
this->stream_->read_array(reinterpret_cast<uint8_t*>(buf), len);
|
|
this->stream_->read_array(reinterpret_cast<uint8_t*>(buf), len);
|
|
|
-#else
|
|
|
|
|
- this->stream_->readBytes(buf, len);
|
|
|
|
|
-#endif
|
|
|
|
|
for (auto const& client : this->clients_)
|
|
for (auto const& client : this->clients_)
|
|
|
client->tcp_client->write(buf, len);
|
|
client->tcp_client->write(buf, len);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void StreamServerComponent::write() {
|
|
void StreamServerComponent::write() {
|
|
|
-#if ESPHOME_VERSION_CODE >= VERSION_CODE(2021, 10, 0)
|
|
|
|
|
this->stream_->write_array(this->recv_buf_);
|
|
this->stream_->write_array(this->recv_buf_);
|
|
|
this->recv_buf_.clear();
|
|
this->recv_buf_.clear();
|
|
|
-#else
|
|
|
|
|
- size_t len;
|
|
|
|
|
- while ((len = this->recv_buf_.size()) > 0) {
|
|
|
|
|
- this->stream_->write(this->recv_buf_.data(), len);
|
|
|
|
|
- this->recv_buf_.erase(this->recv_buf_.begin(), this->recv_buf_.begin() + len);
|
|
|
|
|
- }
|
|
|
|
|
-#endif
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void StreamServerComponent::dump_config() {
|
|
void StreamServerComponent::dump_config() {
|
|
|
ESP_LOGCONFIG(TAG, "Stream Server:");
|
|
ESP_LOGCONFIG(TAG, "Stream Server:");
|
|
|
ESP_LOGCONFIG(TAG, " Address: %s:%u",
|
|
ESP_LOGCONFIG(TAG, " Address: %s:%u",
|
|
|
-#if ESPHOME_VERSION_CODE >= VERSION_CODE(2021, 10, 0)
|
|
|
|
|
esphome::network::get_ip_address().str().c_str(),
|
|
esphome::network::get_ip_address().str().c_str(),
|
|
|
-#else
|
|
|
|
|
- network_get_address().c_str(),
|
|
|
|
|
-#endif
|
|
|
|
|
this->port_);
|
|
this->port_);
|
|
|
}
|
|
}
|
|
|
|
|
|