-
-
Save fitomad/495f06e258fb1c1e18637756f7a00f41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - HTTP - | |
func routes(_ app: Application) throws { | |
... | |
/// | |
app.post("login") { req -> HTTPStatus in | |
let login = try req.content.decode(LoginRequest.self) | |
... | |
// almacenamos valores en la sesion | |
req.session.data["nickname"] = login.nickname | |
req.session.data["room"] = login.roomName | |
... | |
} | |
} | |
// MARK: - WebSockets - | |
func webSockets(_ app: Application) throws | |
{ | |
app.webSocket("chat") { request, ws in | |
... | |
// Recuperamos valores de la sesion. | |
let userName = request.session.data["nickname"] ?? "Usuario desconocido" | |
let room = request.session.data["room"] ?? "The Empty" | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment