|
@ -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()); |
|
|