Compare commits
2 Commits
master
...
feature/vo
Author | SHA1 | Date | |
---|---|---|---|
bdb9bd3625 | |||
165db0f093 |
@ -18,11 +18,15 @@
|
||||
"platforms": ["espressif8266", "espressif32"],
|
||||
"dependencies": [
|
||||
{
|
||||
"owner": "me-no-dev",
|
||||
"name": "ESPAsyncTCP",
|
||||
"version": "^1.2.2",
|
||||
"platforms": "espressif8266"
|
||||
},
|
||||
{
|
||||
"owner": "me-no-dev",
|
||||
"name": "AsyncTCP",
|
||||
"version": "^1.1.1",
|
||||
"platforms": "espressif32"
|
||||
},
|
||||
{
|
||||
|
@ -181,7 +181,7 @@ public:
|
||||
*/
|
||||
|
||||
|
||||
AsyncWebSocketMessage::AsyncWebSocketMessage(std::shared_ptr<std::vector<uint8_t>> buffer, uint8_t opcode, bool mask) :
|
||||
AsyncWebSocketMessage::AsyncWebSocketMessage(AsyncWebSocketMessageBuffer buffer, uint8_t opcode, bool mask) :
|
||||
_WSbuffer{buffer},
|
||||
_opcode(opcode & 0x07),
|
||||
_mask{mask},
|
||||
@ -643,39 +643,12 @@ size_t AsyncWebSocketClient::printf_P(PGM_P formatP, ...)
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
std::shared_ptr<std::vector<uint8_t>> makeBuffer(const uint8_t *message, size_t len)
|
||||
AsyncWebSocketMessageBuffer AsyncWebSocketClient::makeBuffer(const uint8_t *message, size_t len)
|
||||
{
|
||||
auto buffer = std::make_shared<std::vector<uint8_t>>(len);
|
||||
std::memcpy(buffer->data(), message, len);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::text(std::shared_ptr<std::vector<uint8_t>> buffer)
|
||||
{
|
||||
_queueMessage(buffer);
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::text(const uint8_t *message, size_t len)
|
||||
{
|
||||
text(makeBuffer(message, len));
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::text(const char *message, size_t len)
|
||||
{
|
||||
text((const uint8_t *)message, len);
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::text(const char *message)
|
||||
{
|
||||
text(message, strlen(message));
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::text(const String &message)
|
||||
{
|
||||
text(message.c_str(), message.length());
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::text(const __FlashStringHelper *data)
|
||||
{
|
||||
@ -698,31 +671,6 @@ void AsyncWebSocketClient::text(const __FlashStringHelper *data)
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::binary(std::shared_ptr<std::vector<uint8_t>> buffer)
|
||||
{
|
||||
_queueMessage(buffer, WS_BINARY);
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::binary(const uint8_t *message, size_t len)
|
||||
{
|
||||
binary(makeBuffer(message, len));
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::binary(const char *message, size_t len)
|
||||
{
|
||||
binary((const uint8_t *)message, len);
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::binary(const char *message)
|
||||
{
|
||||
binary(message, strlen(message));
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::binary(const String &message)
|
||||
{
|
||||
binary(message.c_str(), message.length());
|
||||
}
|
||||
|
||||
void AsyncWebSocketClient::binary(const __FlashStringHelper *data, size_t len)
|
||||
{
|
||||
PGM_P p = reinterpret_cast<PGM_P>(data);
|
||||
@ -850,23 +798,15 @@ void AsyncWebSocket::pingAll(const uint8_t *data, size_t len)
|
||||
c.ping(data, len);
|
||||
}
|
||||
|
||||
void AsyncWebSocket::text(uint32_t id, AsyncWebSocketMessageBuffer message){
|
||||
if (AsyncWebSocketClient * c = client(id))
|
||||
c->message(message);
|
||||
};
|
||||
void AsyncWebSocket::text(uint32_t id, const uint8_t *message, size_t len)
|
||||
{
|
||||
if (AsyncWebSocketClient * c = client(id))
|
||||
c->text(makeBuffer(message, len));
|
||||
}
|
||||
void AsyncWebSocket::text(uint32_t id, const char *message, size_t len)
|
||||
{
|
||||
text(id, (const uint8_t *)message, len);
|
||||
}
|
||||
void AsyncWebSocket::text(uint32_t id, const char * message)
|
||||
{
|
||||
text(id, message, strlen(message));
|
||||
}
|
||||
void AsyncWebSocket::text(uint32_t id, const String &message)
|
||||
{
|
||||
text(id, message.c_str(), message.length());
|
||||
}
|
||||
void AsyncWebSocket::text(uint32_t id, const __FlashStringHelper *data)
|
||||
{
|
||||
PGM_P p = reinterpret_cast<PGM_P>(data);
|
||||
@ -889,7 +829,7 @@ void AsyncWebSocket::text(uint32_t id, const __FlashStringHelper *data)
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncWebSocket::textAll(std::shared_ptr<std::vector<uint8_t>> buffer)
|
||||
void AsyncWebSocket::textAll(AsyncWebSocketMessageBuffer buffer)
|
||||
{
|
||||
for (auto &c : _clients)
|
||||
if (c.status() == WS_CONNECTED)
|
||||
@ -932,6 +872,10 @@ void AsyncWebSocket::textAll(const __FlashStringHelper *data)
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncWebSocket::binary(uint32_t id, AsyncWebSocketMessageBuffer message){
|
||||
if (AsyncWebSocketClient * c = client(id))
|
||||
c->binary(message);
|
||||
};
|
||||
void AsyncWebSocket::binary(uint32_t id, const uint8_t *message, size_t len)
|
||||
{
|
||||
if (AsyncWebSocketClient *c = client(id))
|
||||
@ -961,7 +905,7 @@ void AsyncWebSocket::binary(uint32_t id, const __FlashStringHelper *data, size_t
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncWebSocket::binaryAll(std::shared_ptr<std::vector<uint8_t>> buffer)
|
||||
void AsyncWebSocket::binaryAll(AsyncWebSocketMessageBuffer buffer)
|
||||
{
|
||||
for (auto &c : _clients)
|
||||
if (c.status() == WS_CONNECTED)
|
||||
@ -1022,7 +966,7 @@ size_t AsyncWebSocket::printfAll(const char *format, ...)
|
||||
va_end(arg);
|
||||
delete[] temp;
|
||||
|
||||
std::shared_ptr<std::vector<uint8_t>> buffer = std::make_shared<std::vector<uint8_t>>(len);
|
||||
AsyncWebSocketMessageBuffer buffer = std::make_shared<std::vector<uint8_t>>(len);
|
||||
|
||||
va_start(arg, format);
|
||||
vsnprintf( (char *)buffer->data(), len + 1, format, arg);
|
||||
@ -1058,7 +1002,7 @@ size_t AsyncWebSocket::printfAll_P(PGM_P formatP, ...)
|
||||
va_end(arg);
|
||||
delete[] temp;
|
||||
|
||||
std::shared_ptr<std::vector<uint8_t>> buffer = std::make_shared<std::vector<uint8_t>>(len + 1);
|
||||
AsyncWebSocketMessageBuffer buffer = std::make_shared<std::vector<uint8_t>>(len + 1);
|
||||
|
||||
va_start(arg, formatP);
|
||||
vsnprintf_P((char *)buffer->data(), len + 1, formatP, arg);
|
||||
@ -1141,6 +1085,13 @@ void AsyncWebSocket::handleRequest(AsyncWebServerRequest *request)
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
AsyncWebSocketMessageBuffer AsyncWebSocket::makeBuffer(const uint8_t *message, size_t len)
|
||||
{
|
||||
auto buffer = std::make_shared<std::vector<uint8_t>>(len);
|
||||
std::memcpy(buffer->data(), message, len);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
* Response to Web Socket request - sends the authorization and detaches the TCP Client from the web server
|
||||
* Authentication code from https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.cpp#L480
|
||||
@ -1208,3 +1159,4 @@ size_t AsyncWebSocketResponse::_ack(AsyncWebServerRequest *request, size_t len,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,8 @@
|
||||
#define DEFAULT_MAX_WS_CLIENTS 4
|
||||
#endif
|
||||
|
||||
using AsyncWebSocketMessageBuffer = std::shared_ptr<std::vector<uint8_t>>;
|
||||
|
||||
class AsyncWebSocket;
|
||||
class AsyncWebSocketResponse;
|
||||
class AsyncWebSocketClient;
|
||||
@ -84,6 +86,7 @@ typedef enum { WS_CONTINUATION, WS_TEXT, WS_BINARY, WS_DISCONNECT = 0x08, WS_PIN
|
||||
typedef enum { WS_MSG_SENDING, WS_MSG_SENT, WS_MSG_ERROR } AwsMessageStatus;
|
||||
typedef enum { WS_EVT_CONNECT, WS_EVT_DISCONNECT, WS_EVT_PONG, WS_EVT_ERROR, WS_EVT_DATA } AwsEventType;
|
||||
|
||||
|
||||
class AsyncWebSocketMessage
|
||||
{
|
||||
private:
|
||||
@ -161,7 +164,26 @@ class AsyncWebSocketClient {
|
||||
}
|
||||
|
||||
//data packets
|
||||
void message(std::shared_ptr<std::vector<uint8_t>> buffer, uint8_t opcode=WS_TEXT, bool mask=false) { _queueMessage(buffer, opcode, mask); }
|
||||
/**
|
||||
* @brief allocate memory buffer owned by shared-pointer and copy provided data
|
||||
* used to keep the data untill websocket send is complete for single/multiple clients
|
||||
*
|
||||
* @param message
|
||||
* @param len
|
||||
* @return AsyncWebSocketMessageBuffer
|
||||
*/
|
||||
AsyncWebSocketMessageBuffer makeBuffer(const uint8_t *message, size_t len);
|
||||
|
||||
/**
|
||||
* @brief allocate empty memory buffer owned by shared-pointer
|
||||
* used to keep the data untill websocket send is complete for single/multiple clients
|
||||
*
|
||||
* @param len
|
||||
* @return AsyncWebSocketMessageBuffer
|
||||
*/
|
||||
inline AsyncWebSocketMessageBuffer makeBuffer(size_t len){ return std::make_shared<std::vector<uint8_t>>(len); };
|
||||
|
||||
void message(AsyncWebSocketMessageBuffer buffer, uint8_t opcode=WS_TEXT, bool mask=false) { _queueMessage(buffer, opcode, mask); }
|
||||
bool queueIsFull() const;
|
||||
size_t queueLen() const;
|
||||
|
||||
@ -170,18 +192,18 @@ class AsyncWebSocketClient {
|
||||
size_t printf_P(PGM_P formatP, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
#endif
|
||||
|
||||
void text(std::shared_ptr<std::vector<uint8_t>> buffer);
|
||||
void text(const uint8_t *message, size_t len);
|
||||
void text(const char *message, size_t len);
|
||||
void text(const char *message);
|
||||
void text(const String &message);
|
||||
inline void text(AsyncWebSocketMessageBuffer buffer){ _queueMessage(buffer); };
|
||||
inline void text(const uint8_t *message, size_t len){ text(makeBuffer(message, len)); };
|
||||
inline void text(const char *message, size_t len){ text((const uint8_t *)message, len); };
|
||||
inline void text(const char *message){ text(message, strlen(message)); };
|
||||
inline void text(const String &message){ text(message.c_str(), message.length()); };
|
||||
void text(const __FlashStringHelper *message);
|
||||
|
||||
void binary(std::shared_ptr<std::vector<uint8_t>> buffer);
|
||||
void binary(const uint8_t *message, size_t len);
|
||||
void binary(const char * message, size_t len);
|
||||
void binary(const char * message);
|
||||
void binary(const String &message);
|
||||
inline void binary(AsyncWebSocketMessageBuffer buffer){ _queueMessage(buffer, WS_BINARY); };
|
||||
inline void binary(const uint8_t *message, size_t len){ binary(makeBuffer(message, len)); };
|
||||
inline void binary(const char * message, size_t len){ binary((const uint8_t *)message, len); };
|
||||
inline void binary(const char * message){ binary(message, strlen(message)); };
|
||||
inline void binary(const String &message){ binary(message.c_str(), message.length()); };
|
||||
void binary(const __FlashStringHelper *message, size_t len);
|
||||
|
||||
bool canSend() const;
|
||||
@ -229,26 +251,48 @@ class AsyncWebSocket: public AsyncWebHandler {
|
||||
void ping(uint32_t id, const uint8_t *data=NULL, size_t len=0);
|
||||
void pingAll(const uint8_t *data=NULL, size_t len=0); // done
|
||||
|
||||
//data packets
|
||||
/**
|
||||
* @brief allocate memory buffer owned by shared-pointer and copy provided data
|
||||
* used to keep the data untill websocket send is complete for single/multiple clients
|
||||
*
|
||||
* @param message
|
||||
* @param len
|
||||
* @return AsyncWebSocketMessageBuffer
|
||||
*/
|
||||
AsyncWebSocketMessageBuffer makeBuffer(const uint8_t *message, size_t len);
|
||||
|
||||
/**
|
||||
* @brief allocate empty memory buffer owned by shared-pointer
|
||||
* used to keep the data untill websocket send is complete for single/multiple clients
|
||||
*
|
||||
* @param len
|
||||
* @return AsyncWebSocketMessageBuffer
|
||||
*/
|
||||
inline AsyncWebSocketMessageBuffer makeBuffer(size_t len){ return std::make_shared<std::vector<uint8_t>>(len); };
|
||||
|
||||
void text(uint32_t id, AsyncWebSocketMessageBuffer message);
|
||||
void text(uint32_t id, const uint8_t * message, size_t len);
|
||||
void text(uint32_t id, const char *message, size_t len);
|
||||
void text(uint32_t id, const char *message);
|
||||
void text(uint32_t id, const String &message);
|
||||
inline void text(uint32_t id, const char *message, size_t len){ text(id, (const uint8_t *)message, len); };
|
||||
inline void text(uint32_t id, const char *message){ text(id, message, strlen(message)); };
|
||||
inline void text(uint32_t id, const String &message){ text(id, message.c_str(), message.length()); };
|
||||
void text(uint32_t id, const __FlashStringHelper *message);
|
||||
|
||||
void textAll(std::shared_ptr<std::vector<uint8_t>> buffer);
|
||||
void textAll(AsyncWebSocketMessageBuffer buffer);
|
||||
void textAll(const uint8_t *message, size_t len);
|
||||
void textAll(const char * message, size_t len);
|
||||
void textAll(const char * message);
|
||||
void textAll(const String &message);
|
||||
void textAll(const __FlashStringHelper *message); // need to convert
|
||||
|
||||
void binary(uint32_t id, AsyncWebSocketMessageBuffer message);
|
||||
void binary(uint32_t id, const uint8_t *message, size_t len);
|
||||
void binary(uint32_t id, const char *message, size_t len);
|
||||
void binary(uint32_t id, const char *message);
|
||||
void binary(uint32_t id, const String &message);
|
||||
void binary(uint32_t id, const __FlashStringHelper *message, size_t len);
|
||||
|
||||
void binaryAll(std::shared_ptr<std::vector<uint8_t>> buffer);
|
||||
void binaryAll(AsyncWebSocketMessageBuffer buffer);
|
||||
void binaryAll(const uint8_t *message, size_t len);
|
||||
void binaryAll(const char *message, size_t len);
|
||||
void binaryAll(const char *message);
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "SPIFFSEditor.h"
|
||||
#include <FS.h>
|
||||
|
||||
#define EDFS
|
||||
|
||||
#ifndef EDFS
|
||||
#include "edit.htm.gz.h"
|
||||
#endif
|
||||
|
@ -37,7 +37,7 @@ class AsyncStaticWebHandler: public AsyncWebHandler {
|
||||
bool _fileExists(AsyncWebServerRequest *request, const String& path);
|
||||
uint8_t _countBits(const uint8_t value) const;
|
||||
protected:
|
||||
FS &_fs;
|
||||
FS _fs;
|
||||
String _uri;
|
||||
String _path;
|
||||
String _default_file;
|
||||
|
Loading…
Reference in New Issue
Block a user