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.

31 lines
882 B

  1. #ifndef _AsyncJsonCallbackResponse_H_
  2. #define _AsyncJsonCallbackResponse_H_
  3. #include <ESPAsyncWebServer.h>
  4. #include <AsyncJson.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. {
  14. private:
  15. AsyncJsonCallback _callback;
  16. public:
  17. AsyncJsonCallbackResponse(AsyncJsonCallback callback, bool isArray = false, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE)
  18. : AsyncJsonResponse(isArray, maxJsonBufferSize), _callback{callback} {}
  19. ~AsyncJsonCallbackResponse()
  20. {
  21. _callback();
  22. }
  23. };
  24. #endif // end _AsyncJsonCallbackResponse_H_