From 2d65df86c7988f5d9afa826cfbceda332f06f6a4 Mon Sep 17 00:00:00 2001 From: pavulon Date: Mon, 26 Oct 2020 13:08:24 +0100 Subject: [PATCH] Update outdated examples (#1116) Since v18.0.0 req is no longer passed to the "open" handler. You can access it in the "upgrade" handler instead. --- README.md | 2 +- misc/READMORE.md | 8 ++++++-- misc/main.cpp | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dca2892..e6eb5f4 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ uWS::SSLApp({ }).ws("/*", { /* Just a few of the available handlers */ - .open = [](auto *ws, auto *req) { + .open = [](auto *ws) { /* MQTT syntax */ ws->subscribe("sensors/+/house"); }, diff --git a/misc/READMORE.md b/misc/READMORE.md index 70e9655..db7eea9 100644 --- a/misc/READMORE.md +++ b/misc/READMORE.md @@ -119,8 +119,12 @@ uWS::App().ws("/*", { .maxPayloadLength = 16 * 1024, .idleTimeout = 10, /* Handlers */ - .open = [](auto *ws, auto *req) { - /* Here you can use req just like as for Http */ + .upgrade = [](auto *res, auto *req, auto *context) { + /* You may read from req only here, and COPY whatever you need into your PerSocketData. + * See UpgradeSync and UpgradeAsync examples. */ + }, + .open = [](auto *ws) { + }, .message = [](auto *ws, std::string_view message, uWS::OpCode opCode) { ws->send(message, opCode); diff --git a/misc/main.cpp b/misc/main.cpp index 4069aac..57238b5 100644 --- a/misc/main.cpp +++ b/misc/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char **argv) { .maxPayloadLength = 16 * 1024 * 1024, .idleTimeout = 10, /* Handlers */ - .open = [](auto *ws, auto *req) { + .open = [](auto *ws) { std::cout << "WebSocket connected" << std::endl; /* Access per socket data */ PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();