mirror of
https://github.com/Links2004/arduinoWebSockets.git
synced 2025-07-17 09:12:05 +02:00
code style
This commit is contained in:
@ -42,7 +42,11 @@
|
|||||||
|
|
||||||
#ifndef NODEBUG_WEBSOCKETS
|
#ifndef NODEBUG_WEBSOCKETS
|
||||||
#ifdef DEBUG_ESP_PORT
|
#ifdef DEBUG_ESP_PORT
|
||||||
#define DEBUG_WEBSOCKETS(...) { DEBUG_ESP_PORT.printf(__VA_ARGS__); DEBUG_ESP_PORT.flush(); }
|
#define DEBUG_WEBSOCKETS(...) \
|
||||||
|
{ \
|
||||||
|
DEBUG_ESP_PORT.printf(__VA_ARGS__); \
|
||||||
|
DEBUG_ESP_PORT.flush(); \
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
//#define DEBUG_WEBSOCKETS(...) os_printf( __VA_ARGS__ )
|
//#define DEBUG_WEBSOCKETS(...) os_printf( __VA_ARGS__ )
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,22 +30,18 @@
|
|||||||
|
|
||||||
#if WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266 && WEBSERVER_HAS_HOOK
|
#if WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266 && WEBSERVER_HAS_HOOK
|
||||||
|
|
||||||
class WebSockets4WebServer: public WebSocketsServerCore {
|
class WebSockets4WebServer : public WebSocketsServerCore {
|
||||||
public:
|
public:
|
||||||
|
WebSockets4WebServer(const String & origin = "", const String & protocol = "arduino")
|
||||||
WebSockets4WebServer(const String& origin = "", const String& protocol = "arduino"):
|
: WebSocketsServerCore(origin, protocol) {
|
||||||
WebSocketsServerCore(origin, protocol)
|
|
||||||
{
|
|
||||||
begin();
|
begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP8266WebServer::HookFunction hookForWebserver (const String& wsRootDir, WebSocketServerEvent event)
|
ESP8266WebServer::HookFunction hookForWebserver(const String & wsRootDir, WebSocketServerEvent event) {
|
||||||
{
|
|
||||||
onEvent(event);
|
onEvent(event);
|
||||||
|
|
||||||
return [&, wsRootDir](const String & method, const String & url, WiFiClient * tcpClient, ESP8266WebServer::ContentTypeFunction contentType)
|
return [&, wsRootDir](const String & method, const String & url, WiFiClient * tcpClient, ESP8266WebServer::ContentTypeFunction contentType) {
|
||||||
{
|
if(!(method == "GET" && url.indexOf(wsRootDir) == 0)) {
|
||||||
if (!(method == "GET" && url.indexOf(wsRootDir) == 0)) {
|
|
||||||
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
|
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +51,7 @@ class WebSockets4WebServer: public WebSocketsServerCore {
|
|||||||
// Then initialize a new WSclient_t (like in WebSocketsServer::handleNewClient())
|
// Then initialize a new WSclient_t (like in WebSocketsServer::handleNewClient())
|
||||||
WSclient_t * client = handleNewClient(newTcpClient);
|
WSclient_t * client = handleNewClient(newTcpClient);
|
||||||
|
|
||||||
if (client)
|
if(client) {
|
||||||
{
|
|
||||||
// give "GET <url>"
|
// give "GET <url>"
|
||||||
String headerLine;
|
String headerLine;
|
||||||
headerLine.reserve(url.length() + 5);
|
headerLine.reserve(url.length() + 5);
|
||||||
@ -71,6 +66,6 @@ class WebSockets4WebServer: public WebSocketsServerCore {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266 && WEBSERVER_HAS_HOOK
|
#endif // WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266 && WEBSERVER_HAS_HOOK
|
||||||
|
|
||||||
#endif // __WEBSOCKETS4WEBSERVER_H
|
#endif // __WEBSOCKETS4WEBSERVER_H
|
||||||
|
@ -33,8 +33,7 @@
|
|||||||
|
|
||||||
class WebSocketsServerCore : protected WebSockets {
|
class WebSocketsServerCore : protected WebSockets {
|
||||||
public:
|
public:
|
||||||
|
WebSocketsServerCore(const String & origin = "", const String & protocol = "arduino");
|
||||||
WebSocketsServerCore(const String& origin = "", const String& protocol = "arduino");
|
|
||||||
virtual ~WebSocketsServerCore(void);
|
virtual ~WebSocketsServerCore(void);
|
||||||
|
|
||||||
void begin(void);
|
void begin(void);
|
||||||
@ -96,7 +95,7 @@ class WebSocketsServerCore : protected WebSockets {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
||||||
void loop(void); // handle client data only
|
void loop(void); // handle client data only
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -207,7 +206,7 @@ class WebSocketsServerCore : protected WebSockets {
|
|||||||
/**
|
/**
|
||||||
* drop native tcp connection (client->tcp)
|
* drop native tcp connection (client->tcp)
|
||||||
*/
|
*/
|
||||||
void dropNativeClient (WSclient_t * client);
|
void dropNativeClient(WSclient_t * client);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*
|
/*
|
||||||
@ -215,27 +214,24 @@ class WebSocketsServerCore : protected WebSockets {
|
|||||||
* @param headerName String ///< the name of the header being checked
|
* @param headerName String ///< the name of the header being checked
|
||||||
*/
|
*/
|
||||||
bool hasMandatoryHeader(String headerName);
|
bool hasMandatoryHeader(String headerName);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class WebSocketsServer: public WebSocketsServerCore {
|
class WebSocketsServer : public WebSocketsServerCore {
|
||||||
public:
|
public:
|
||||||
|
WebSocketsServer(uint16_t port, const String & origin = "", const String & protocol = "arduino");
|
||||||
WebSocketsServer(uint16_t port, const String& origin = "", const String& protocol = "arduino");
|
|
||||||
virtual ~WebSocketsServer(void);
|
virtual ~WebSocketsServer(void);
|
||||||
|
|
||||||
void begin(void);
|
void begin(void);
|
||||||
void close(void);
|
void close(void);
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
||||||
void loop(void); // handle incoming client and client data
|
void loop(void); // handle incoming client and client data
|
||||||
#else
|
#else
|
||||||
// Async interface not need a loop call
|
// Async interface not need a loop call
|
||||||
void loop(void) __attribute__((deprecated)) {}
|
void loop(void) __attribute__((deprecated)) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
#if(WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC)
|
||||||
void handleNewClients(void);
|
void handleNewClients(void);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user