Better messages
This commit is contained in:
parent
ffd5864bce
commit
418d2fde0c
2 changed files with 6 additions and 2 deletions
|
@ -20,10 +20,12 @@ websockets::TestProtocol<User> default_protocol{
|
||||||
// connection established
|
// connection established
|
||||||
[](User& user, basic_websocket_info){
|
[](User& user, basic_websocket_info){
|
||||||
app->login(user);
|
app->login(user);
|
||||||
|
std::cout << "New user!\n";
|
||||||
},
|
},
|
||||||
// connection closed
|
// connection closed
|
||||||
[](User& user, basic_websocket_info){
|
[](User& user, basic_websocket_info){
|
||||||
app->logout(user);
|
app->logout(user);
|
||||||
|
std::cout << "User left: " << &user << ": " << user.name << std::endl;
|
||||||
},
|
},
|
||||||
// write (will always come after receive)
|
// write (will always come after receive)
|
||||||
[](User& user, basic_websocket_info) -> std::string{
|
[](User& user, basic_websocket_info) -> std::string{
|
||||||
|
@ -39,8 +41,10 @@ websockets::TestProtocol<User> default_protocol{
|
||||||
auto command = object["command"];
|
auto command = object["command"];
|
||||||
if(command == "add line"){
|
if(command == "add line"){
|
||||||
app->add_line(from_json<AbstractLine>(object["data"]));
|
app->add_line(from_json<AbstractLine>(object["data"]));
|
||||||
|
std::cout << "Line from: " << &user << ": " << user.name << std::endl;
|
||||||
} else if (command == "update user") {
|
} else if (command == "update user") {
|
||||||
user = from_json<IncomingPacket>(object["data"]);
|
user = from_json<IncomingPacket>(object["data"]);
|
||||||
|
std::cout << "Updated user: " << &user << ": " << user.name << std::endl;
|
||||||
}
|
}
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
throw websockets::runtime_error(e.what());
|
throw websockets::runtime_error(e.what());
|
||||||
|
|
|
@ -124,12 +124,12 @@ namespace websockets {
|
||||||
try{
|
try{
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case LWS_CALLBACK_ESTABLISHED:
|
case LWS_CALLBACK_ESTABLISHED:
|
||||||
lwsl_notice("Connection established (%p, %p)\n", this, user_ptr);
|
if(verbose) lwsl_notice("Connection established (%p, %p)\n", this, user_ptr);
|
||||||
new (user_ptr) user_type();
|
new (user_ptr) user_type();
|
||||||
establish_func(user, binfo);
|
establish_func(user, binfo);
|
||||||
break;
|
break;
|
||||||
case LWS_CALLBACK_CLOSED:
|
case LWS_CALLBACK_CLOSED:
|
||||||
lwsl_notice("Connection closed (%p, %p)\n", this, user_ptr);
|
if(verbose) lwsl_notice("Connection closed (%p, %p)\n", this, user_ptr);
|
||||||
user.~user_type();
|
user.~user_type();
|
||||||
close_func(user, binfo);
|
close_func(user, binfo);
|
||||||
break;
|
break;
|
||||||
|
|
Reference in a new issue