forked from me-no-dev/ESPAsyncWebServer
add method to disable new connections to a WebSocket instance
This commit is contained in:
@@ -499,7 +499,7 @@ size_t AsyncWebSocketClient::printf_P(PGM_P formatP, ...) {
|
|||||||
#else
|
#else
|
||||||
size_t len = vsnprintf(NULL, 0, format, arg)+1;
|
size_t len = vsnprintf(NULL, 0, format, arg)+1;
|
||||||
#endif
|
#endif
|
||||||
size_t fmtLen = strlen_P(formatP);
|
size_t fmtLen = strlen_P(formatP);
|
||||||
format = (char*)calloc(fmtLen+1, sizeof(char));
|
format = (char*)calloc(fmtLen+1, sizeof(char));
|
||||||
if ( format ) {
|
if ( format ) {
|
||||||
strcpy_P(format, formatP);
|
strcpy_P(format, formatP);
|
||||||
@@ -599,6 +599,7 @@ AsyncWebSocket::AsyncWebSocket(String url)
|
|||||||
:_url(url)
|
:_url(url)
|
||||||
,_clients(NULL)
|
,_clients(NULL)
|
||||||
,_cNextId(1)
|
,_cNextId(1)
|
||||||
|
,_enabled(true)
|
||||||
{
|
{
|
||||||
_eventHandler = NULL;
|
_eventHandler = NULL;
|
||||||
}
|
}
|
||||||
@@ -792,7 +793,7 @@ size_t AsyncWebSocket::printfAll_P(PGM_P formatP, ...) {
|
|||||||
#else
|
#else
|
||||||
size_t len = vsnprintf(NULL, 0, format, arg)+1;
|
size_t len = vsnprintf(NULL, 0, format, arg)+1;
|
||||||
#endif
|
#endif
|
||||||
size_t fmtLen = strlen_P(formatP);
|
size_t fmtLen = strlen_P(formatP);
|
||||||
format = (char*)calloc(fmtLen+1, sizeof(char));
|
format = (char*)calloc(fmtLen+1, sizeof(char));
|
||||||
if ( format ) {
|
if ( format ) {
|
||||||
strcpy_P(format, formatP);
|
strcpy_P(format, formatP);
|
||||||
@@ -898,6 +899,9 @@ const char * WS_STR_ACCEPT = "Sec-WebSocket-Accept";
|
|||||||
const char * WS_STR_UUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
const char * WS_STR_UUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||||
|
|
||||||
bool AsyncWebSocket::canHandle(AsyncWebServerRequest *request){
|
bool AsyncWebSocket::canHandle(AsyncWebServerRequest *request){
|
||||||
|
if(!_enabled)
|
||||||
|
return false;
|
||||||
|
|
||||||
if(request->method() != HTTP_GET || !request->url().equals(_url))
|
if(request->method() != HTTP_GET || !request->url().equals(_url))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@@ -101,7 +101,7 @@ class AsyncWebSocketClient {
|
|||||||
|
|
||||||
size_t printf(const char *format, ...);
|
size_t printf(const char *format, ...);
|
||||||
size_t printf_P(PGM_P formatP, ...);
|
size_t printf_P(PGM_P formatP, ...);
|
||||||
|
|
||||||
void text(const char * message, size_t len);
|
void text(const char * message, size_t len);
|
||||||
void text(const char * message);
|
void text(const char * message);
|
||||||
void text(uint8_t * message, size_t len);
|
void text(uint8_t * message, size_t len);
|
||||||
@@ -134,10 +134,13 @@ class AsyncWebSocket: public AsyncWebHandler {
|
|||||||
AsyncWebSocketClient * _clients;
|
AsyncWebSocketClient * _clients;
|
||||||
uint32_t _cNextId;
|
uint32_t _cNextId;
|
||||||
AwsEventHandler _eventHandler;
|
AwsEventHandler _eventHandler;
|
||||||
|
bool _enabled;
|
||||||
public:
|
public:
|
||||||
AsyncWebSocket(String url);
|
AsyncWebSocket(String url);
|
||||||
~AsyncWebSocket();
|
~AsyncWebSocket();
|
||||||
const char * url(){ return _url.c_str(); }
|
const char * url(){ return _url.c_str(); }
|
||||||
|
void enable(bool e){ _enabled = e; }
|
||||||
|
bool enabled() { return _enabled; }
|
||||||
|
|
||||||
size_t count();
|
size_t count();
|
||||||
AsyncWebSocketClient * client(uint32_t id);
|
AsyncWebSocketClient * client(uint32_t id);
|
||||||
|
Reference in New Issue
Block a user