Update demo interface
This commit is contained in:
@@ -17,37 +17,32 @@ uWS::SSLApp({
|
|||||||
.cert_file_name = "cert.pem",
|
.cert_file_name = "cert.pem",
|
||||||
.key_file_name = "key.pem"
|
.key_file_name = "key.pem"
|
||||||
|
|
||||||
}).onGet("/", [](auto *res, auto *req) {
|
}).get("/hello", [](auto *res, auto *req) {
|
||||||
|
|
||||||
/* Respond with the web app on default route */
|
/* You can efficiently stream huge files too */
|
||||||
res->writeStatus("200 OK")
|
res->writeHeader("Content-Type", "text/html; charset=utf-8")->end("Hello HTTP!");
|
||||||
->writeHeader("Content-Type", "text/html; charset=utf-8")
|
|
||||||
->end(indexHtmlBuffer);
|
|
||||||
|
|
||||||
}).onWebSocket<UserData>("/ws/chat", [&](auto *ws, auto *req) {
|
}).ws<UserData>("/*", {
|
||||||
|
|
||||||
/* Subscribe to topic /chat */
|
/* Just a few of the available handlers */
|
||||||
ws->subscribe("chat");
|
.open = [](auto *ws, auto *req) {
|
||||||
|
ws->subscribe("buzzword weekly");
|
||||||
}).onMessage([&](auto *ws, auto message, auto opCode) {
|
},
|
||||||
|
.message = [](auto *ws, std::string_view message, uWS::OpCode opCode) {
|
||||||
/* Parse incoming message according to some protocol & publish it */
|
ws->send(message, opCode);
|
||||||
if (seemsReasonable(message)) {
|
|
||||||
ws->publish("chat", message);
|
|
||||||
} else {
|
|
||||||
ws->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}).onClose([&](auto *ws, int code, auto message) {
|
}).listen(9001, [](auto *token) {
|
||||||
|
|
||||||
/* Remove websocket from this topic */
|
if (token) {
|
||||||
ws->unsubscribe("chat");
|
std::cout << "Listening on port " << 9001 << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
}).listen("localhost", 3000, 0).run();
|
}).run();
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Pay what you want.
|
#### Pay what you want.
|
||||||
A free & open source ([Zlib](LICENSE)) project since 2016. Kindly sponsored by [BitMEX](https://bitmex.com), [Bitfinex](https://bitfinex.com) & [Coinbase](https://www.coinbase.com/) in 2018.
|
A free & open source ([permissive](LICENSE)) project since 2016. Kindly sponsored by [BitMEX](https://bitmex.com), [Bitfinex](https://bitfinex.com) & [Coinbase](https://www.coinbase.com/) in 2018.
|
||||||
|
|
||||||
<div align="center"><img src="misc/2018.png"/></div>
|
<div align="center"><img src="misc/2018.png"/></div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user