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.
This commit is contained in:
pavulon
2020-10-26 13:08:24 +01:00
committed by GitHub
parent b4e08ffb01
commit 2d65df86c7
3 changed files with 8 additions and 4 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ uWS::SSLApp({
}).ws<UserData>("/*", {
/* Just a few of the available handlers */
.open = [](auto *ws, auto *req) {
.open = [](auto *ws) {
/* MQTT syntax */
ws->subscribe("sensors/+/house");
},
+6 -2
View File
@@ -119,8 +119,12 @@ uWS::App().ws<PerSocketData>("/*", {
.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);
+1 -1
View File
@@ -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();