|
|
@ -20,10 +20,12 @@ websockets::TestProtocol<User> default_protocol{ |
|
|
|
// connection established
|
|
|
|
[](User& user, basic_websocket_info){ |
|
|
|
app->login(user); |
|
|
|
std::cout << "New user!\n"; |
|
|
|
}, |
|
|
|
// connection closed
|
|
|
|
[](User& user, basic_websocket_info){ |
|
|
|
app->logout(user); |
|
|
|
std::cout << "User left: " << &user << ": " << user.name << std::endl; |
|
|
|
}, |
|
|
|
// write (will always come after receive)
|
|
|
|
[](User& user, basic_websocket_info) -> std::string{ |
|
|
@ -39,8 +41,10 @@ websockets::TestProtocol<User> default_protocol{ |
|
|
|
auto command = object["command"]; |
|
|
|
if(command == "add line"){ |
|
|
|
app->add_line(from_json<AbstractLine>(object["data"])); |
|
|
|
std::cout << "Line from: " << &user << ": " << user.name << std::endl; |
|
|
|
} else if (command == "update user") { |
|
|
|
user = from_json<IncomingPacket>(object["data"]); |
|
|
|
std::cout << "Updated user: " << &user << ": " << user.name << std::endl; |
|
|
|
} |
|
|
|
} catch(std::exception& e) { |
|
|
|
throw websockets::runtime_error(e.what()); |
|
|
|