Add a few more events

This commit is contained in:
Alex Hultman
2018-12-21 04:31:37 +01:00
parent 4a2cd93a22
commit 3fa0fbc5fa
7 changed files with 91 additions and 49 deletions
+7 -2
View File
@@ -54,8 +54,13 @@ public:
struct WebSocketBehavior {
bool compression = false;
int maxPayloadLength = 16 * 1024;
std::function<void(uWS::WebSocket<SSL, true> *, HttpRequest *)> open = nullptr;
std::function<void(uWS::WebSocket<SSL, true> *, std::string_view, uWS::OpCode)> message = nullptr;
std::function<void(uWS::WebSocket<SSL, true> *)> drain = nullptr;
std::function<void(uWS::WebSocket<SSL, true> *)> ping = nullptr;
std::function<void(uWS::WebSocket<SSL, true> *)> pong = nullptr;
std::function<void(uWS::WebSocket<SSL, true> *, int, std::string_view)> close = nullptr;
};
template <class UserData>
@@ -75,6 +80,8 @@ public:
/* Copy all handlers */
webSocketContext->getExt()->messageHandler = behavior.message;
webSocketContext->getExt()->drainHandler = behavior.drain;
webSocketContext->getExt()->closeHandler = behavior.close;
return get(pattern, [webSocketContext, this, behavior](auto *res, auto *req) {
/* If we have this header set, it's a websocket */
@@ -125,8 +132,6 @@ public:
behavior.open(webSocket, req);
}
std::cout << "oh hey!" << std::endl;
} else {
/* For now we do not support having HTTP and websocket routes on the same URL */
res->close();