⛱️ Removes phycic stream
This commit is contained in:
@@ -32,8 +32,7 @@ CameraService::CameraService(PsychicHttpServer *server,
|
||||
SecurityManager *securityManager)
|
||||
: _server(server),
|
||||
_taskManager(taskManager),
|
||||
_securityManager(securityManager),
|
||||
_videoStream(_STREAM_CONTENT_TYPE) {}
|
||||
_securityManager(securityManager) {}
|
||||
void CameraService::begin() {
|
||||
InitializeCamera();
|
||||
_server->on(
|
||||
|
||||
@@ -32,7 +32,6 @@ class CameraService
|
||||
PsychicHttpServer *_server;
|
||||
TaskManager *_taskManager;
|
||||
SecurityManager *_securityManager;
|
||||
PsychicStream _videoStream;
|
||||
esp_err_t cameraStill(PsychicRequest *request);
|
||||
esp_err_t cameraStream(PsychicRequest *request);
|
||||
esp_err_t InitializeCamera();
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "PsychicRequest.h"
|
||||
#include "PsychicResponse.h"
|
||||
#include "PsychicStaticFileHandler.h"
|
||||
#include "PsychicStream.h"
|
||||
#include "PsychicStreamResponse.h"
|
||||
#include "PsychicUploadHandler.h"
|
||||
#include "PsychicWebSocket.h"
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
#include "PsychicStream.h"
|
||||
|
||||
/*****************************************/
|
||||
// PsychicStream - Handler
|
||||
/*****************************************/
|
||||
|
||||
PsychicStream::PsychicStream(const String &contentType)
|
||||
: PsychicHandler(), _onOpen(NULL), _onClose(NULL), _onRequest(NULL), _contentType(contentType)
|
||||
{
|
||||
}
|
||||
|
||||
PsychicStream::~PsychicStream()
|
||||
{
|
||||
}
|
||||
|
||||
PsychicStreamClient *PsychicStream::getClient(int socket)
|
||||
{
|
||||
PsychicClient *client = PsychicHandler::getClient(socket);
|
||||
|
||||
if (client == NULL)
|
||||
return NULL;
|
||||
|
||||
return (PsychicStreamClient *)client->_friend;
|
||||
}
|
||||
|
||||
PsychicStreamClient *PsychicStream::getClient(PsychicClient *client)
|
||||
{
|
||||
return getClient(client->socket());
|
||||
}
|
||||
|
||||
esp_err_t PsychicStream::handleRequest(PsychicRequest *request)
|
||||
{
|
||||
|
||||
esp_err_t err = httpd_resp_set_type(request->request(), _contentType.c_str());
|
||||
|
||||
for (HTTPHeader header : DefaultHeaders::Instance().getHeaders())
|
||||
httpd_resp_set_hdr(request->request(), header.field, header.value);
|
||||
|
||||
// lookup our client
|
||||
PsychicClient *client = checkForNewClient(request->client());
|
||||
if (client->isNew)
|
||||
{
|
||||
// let our handler know.
|
||||
openCallback(client);
|
||||
// _onRequest(request->request());
|
||||
}
|
||||
|
||||
// PsychicStreamResponse response = PsychicStreamResponse(request, _contentType);
|
||||
// esp_err_t err = ESP_OK; // response.beginSend();
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
PsychicStream *PsychicStream::onOpen(PsychicStreamClientCallback fn)
|
||||
{
|
||||
_onOpen = fn;
|
||||
return this;
|
||||
}
|
||||
|
||||
PsychicStream *PsychicStream::onClose(PsychicStreamClientCallback fn)
|
||||
{
|
||||
_onClose = fn;
|
||||
return this;
|
||||
}
|
||||
|
||||
PsychicStream *PsychicStream::onRequest(PsychicStreamRequestCallback fn)
|
||||
{
|
||||
_onRequest = fn;
|
||||
return this;
|
||||
}
|
||||
|
||||
void PsychicStream::addClient(PsychicClient *client)
|
||||
{
|
||||
client->_friend = new PsychicStreamClient(client);
|
||||
PsychicHandler::addClient(client);
|
||||
}
|
||||
|
||||
void PsychicStream::removeClient(PsychicClient *client)
|
||||
{
|
||||
PsychicHandler::removeClient(client);
|
||||
delete (PsychicStreamResponse *)client->_friend;
|
||||
client->_friend = NULL;
|
||||
}
|
||||
|
||||
void PsychicStream::openCallback(PsychicClient *client)
|
||||
{
|
||||
PsychicStreamClient *buddy = getClient(client);
|
||||
if (buddy == NULL)
|
||||
{
|
||||
TRACE();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_onOpen != NULL)
|
||||
_onOpen(buddy);
|
||||
}
|
||||
|
||||
void PsychicStream::closeCallback(PsychicClient *client)
|
||||
{
|
||||
PsychicStreamClient *buddy = getClient(client);
|
||||
if (buddy == NULL)
|
||||
{
|
||||
TRACE();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_onClose != NULL)
|
||||
_onClose(getClient(buddy));
|
||||
}
|
||||
|
||||
void PsychicStream::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
if (_clients.size() == 0)
|
||||
return;
|
||||
ESP_LOGI("PsychicStream", "Writing to %d clients", _clients.size());
|
||||
for (PsychicClient *c : _clients)
|
||||
{
|
||||
((PsychicStreamClient *)c->_friend)->write(buffer, size);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************/
|
||||
// PsychicStreamClient
|
||||
/*****************************************/
|
||||
|
||||
PsychicStreamClient::PsychicStreamClient(PsychicClient *client) : PsychicClient(client->server(), client->socket())
|
||||
{
|
||||
}
|
||||
|
||||
PsychicStreamClient::~PsychicStreamClient()
|
||||
{
|
||||
}
|
||||
|
||||
void PsychicStreamClient::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
int result;
|
||||
do
|
||||
{
|
||||
result = httpd_socket_send(this->server(), this->socket(), (const char *)buffer, size, 0);
|
||||
} while (result == HTTPD_SOCK_ERR_TIMEOUT);
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
#ifndef PsychicStream_H_
|
||||
#define PsychicStream_H_
|
||||
|
||||
#include "PsychicClient.h"
|
||||
#include "PsychicCore.h"
|
||||
#include "PsychicHandler.h"
|
||||
#include "PsychicResponse.h"
|
||||
#include "PsychicStreamResponse.h"
|
||||
|
||||
class PsychicStream;
|
||||
class PsychicStreamResponse;
|
||||
class PsychicStreamClient;
|
||||
class PsychicResponse;
|
||||
|
||||
typedef std::function<void(PsychicStreamClient *client)> PsychicStreamClientCallback;
|
||||
typedef std::function<void(httpd_req_t *request)> PsychicStreamRequestCallback;
|
||||
|
||||
class PsychicStreamClient : public PsychicClient
|
||||
{
|
||||
friend PsychicStream;
|
||||
|
||||
public:
|
||||
PsychicStreamClient(PsychicClient *client);
|
||||
~PsychicStreamClient();
|
||||
|
||||
void write(const uint8_t *buffer, size_t size);
|
||||
};
|
||||
|
||||
class PsychicStream : public PsychicHandler
|
||||
{
|
||||
private:
|
||||
PsychicStreamClientCallback _onOpen;
|
||||
PsychicStreamClientCallback _onClose;
|
||||
PsychicStreamRequestCallback _onRequest;
|
||||
String _contentType;
|
||||
|
||||
public:
|
||||
PsychicStream(const String &contentType);
|
||||
~PsychicStream();
|
||||
|
||||
PsychicStreamClient *getClient(int socket) override;
|
||||
PsychicStreamClient *getClient(PsychicClient *client) override;
|
||||
void addClient(PsychicClient *client) override;
|
||||
void removeClient(PsychicClient *client) override;
|
||||
void openCallback(PsychicClient *client) override;
|
||||
void closeCallback(PsychicClient *client) override;
|
||||
|
||||
PsychicStream *onOpen(PsychicStreamClientCallback fn);
|
||||
PsychicStream *onClose(PsychicStreamClientCallback fn);
|
||||
PsychicStream *onRequest(PsychicStreamRequestCallback fn);
|
||||
|
||||
esp_err_t handleRequest(PsychicRequest *request) override final;
|
||||
|
||||
void write(const uint8_t *buffer, size_t size);
|
||||
};
|
||||
|
||||
#endif /* PsychicStream_H_ */
|
||||
Reference in New Issue
Block a user