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:
@@ -41,7 +41,7 @@ uWS::SSLApp({
|
|||||||
}).ws<UserData>("/*", {
|
}).ws<UserData>("/*", {
|
||||||
|
|
||||||
/* Just a few of the available handlers */
|
/* Just a few of the available handlers */
|
||||||
.open = [](auto *ws, auto *req) {
|
.open = [](auto *ws) {
|
||||||
/* MQTT syntax */
|
/* MQTT syntax */
|
||||||
ws->subscribe("sensors/+/house");
|
ws->subscribe("sensors/+/house");
|
||||||
},
|
},
|
||||||
|
|||||||
+6
-2
@@ -119,8 +119,12 @@ uWS::App().ws<PerSocketData>("/*", {
|
|||||||
.maxPayloadLength = 16 * 1024,
|
.maxPayloadLength = 16 * 1024,
|
||||||
.idleTimeout = 10,
|
.idleTimeout = 10,
|
||||||
/* Handlers */
|
/* Handlers */
|
||||||
.open = [](auto *ws, auto *req) {
|
.upgrade = [](auto *res, auto *req, auto *context) {
|
||||||
/* Here you can use req just like as for Http */
|
/* 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) {
|
.message = [](auto *ws, std::string_view message, uWS::OpCode opCode) {
|
||||||
ws->send(message, opCode);
|
ws->send(message, opCode);
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ int main(int argc, char **argv) {
|
|||||||
.maxPayloadLength = 16 * 1024 * 1024,
|
.maxPayloadLength = 16 * 1024 * 1024,
|
||||||
.idleTimeout = 10,
|
.idleTimeout = 10,
|
||||||
/* Handlers */
|
/* Handlers */
|
||||||
.open = [](auto *ws, auto *req) {
|
.open = [](auto *ws) {
|
||||||
std::cout << "WebSocket connected" << std::endl;
|
std::cout << "WebSocket connected" << std::endl;
|
||||||
/* Access per socket data */
|
/* Access per socket data */
|
||||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||||
|
|||||||
Reference in New Issue
Block a user