Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
937 B

  1. #ifndef _AsyncJsonCallbackResponse_H_
  2. #define _AsyncJsonCallbackResponse_H_
  3. #include <AsyncJson.h>
  4. #include <ESPAsyncWebServer.h>
  5. /*
  6. * Listens for a response being destroyed and calls a callback during said distruction.
  7. * used so we can take action after the response has been rendered to the client.
  8. *
  9. * Avoids having to fork ESPAsyncWebServer with a callback feature, but not nice!
  10. */
  11. typedef std::function<void()> AsyncJsonCallback;
  12. class AsyncJsonCallbackResponse : public AsyncJsonResponse {
  13. private:
  14. AsyncJsonCallback _callback;
  15. public:
  16. AsyncJsonCallbackResponse(AsyncJsonCallback callback,
  17. bool isArray = false,
  18. size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) :
  19. AsyncJsonResponse(isArray, maxJsonBufferSize),
  20. _callback{callback} {
  21. }
  22. ~AsyncJsonCallbackResponse() {
  23. _callback();
  24. }
  25. };
  26. #endif // end _AsyncJsonCallbackResponse_H_