diff --git a/library.json b/library.json index 847ecc4..187076e 100644 --- a/library.json +++ b/library.json @@ -19,7 +19,7 @@ "examples": "examples/*/*.ino", "dependencies": { "bblanchon/ArduinoJson": "^7.1.0", - "links2004/WebSockets": "^2.4.2" + "links2004/WebSockets": "^2.4.1" }, "repository": { "type": "git", diff --git a/library.properties b/library.properties index 5b249fd..3295939 100644 --- a/library.properties +++ b/library.properties @@ -7,4 +7,4 @@ paragraph=This allows developers to interface their ESP32/ESP8266 with Supabase, category=Other url=https://github.com/jhagas/ESP32-Supabase architectures=* -depends=ArduinoJson (>=7.1.0), WebSockets (>=2.4.2) +depends=ArduinoJson (>=7.1.0), WebSockets (>=2.4.1) diff --git a/platformio.ini b/platformio.ini index 0cbdef7..fdd50e6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -26,7 +26,7 @@ board = esp32doit-devkit-v1 framework = arduino lib_deps = bblanchon/ArduinoJson @ ^7.1.0 - links2004/WebSockets@^2.4.2 + links2004/WebSockets@^2.4.1 build_flags = ${config.build_flags} build_src_filter = ${config.src_filter} @@ -36,6 +36,6 @@ board = nodemcuv2 framework = arduino lib_deps = bblanchon/ArduinoJson @ ^7.1.0 - links2004/WebSockets@^2.4.2 + links2004/WebSockets@^2.4.1 build_flags = ${config.build_flags} build_src_filter = ${config.src_filter} diff --git a/src/ESP-Supabase.h b/src/ESP-Supabase.h index b45ef6c..b694256 100644 --- a/src/ESP-Supabase.h +++ b/src/ESP-Supabase.h @@ -21,6 +21,48 @@ struct SupabaseQuery String value; }; +class SupabaseRealtimeTableEntry +{ +private: + WiFiClientSecure client; + WebSocketsClient webSocket; + std::function handleEvent; // Changed to std::function + String jsonRealtimeConfig; + String key; + String hostname; + +public: + void setupHandler(std::function handler); + + SupabaseRealtimeTableEntry(String key, String hostname) + { + hostname.replace("https://", ""); + this->key = key; + this->hostname = hostname; + } + + void setupListener(String table, String event, SupabaseQuery queries[], int numqueries); + void processMessage(uint8_t *payload, size_t length, JsonDocument result); + void webSocketEvent(WStype_t type, uint8_t *payload, size_t length); + void loop(); +}; + +class SupabaseRealtime +{ +private: + String hostname; + String key; + // Define an array to store SUPABASERealtimeTableEntry objects + std::vector entries; + +public: + SupabaseRealtime(){} + void setupConnection(String hostname, String key); + // Function to add a SUPABASERealtimeTableEntry object to the array + void addEntry(String table, String event, SupabaseQuery queries[], int numqueries, std::function handler);\ + void loop(); +}; + class Supabase { private: @@ -100,46 +142,4 @@ class Supabase String rpc(String func_name, String json_param = ""); }; -class SupabaseRealtimeTableEntry -{ -private: - WiFiClientSecure client; - WebSocketsClient webSocket; - std::function handleEvent; // Changed to std::function - String jsonRealtimeConfig; - String key; - String hostname; - -public: - void setupHandler(std::function handler); - - SupabaseRealtimeTableEntry(String key, String hostname) - { - hostname.replace("https://", ""); - this->key = key; - this->hostname = hostname; - } - - void setupListener(String table, String event, SupabaseQuery queries[], int numqueries); - void processMessage(uint8_t *payload, size_t length, JsonDocument result); - void webSocketEvent(WStype_t type, uint8_t *payload, size_t length); - void loop(); -}; - -class SupabaseRealtime -{ -private: - String hostname; - String key; - // Define an array to store SUPABASERealtimeTableEntry objects - std::vector entries; - -public: - SupabaseRealtime(){} - void setupConnection(String hostname, String key); - // Function to add a SUPABASERealtimeTableEntry object to the array - void addEntry(String table, String event, SupabaseQuery queries[], int numqueries, std::function handler);\ - void loop(); -}; - #endif \ No newline at end of file