Skip to content

Instantly share code, notes, and snippets.

@mostlygeek
Created April 1, 2012 23:54
Show Gist options
  • Save mostlygeek/2279554 to your computer and use it in GitHub Desktop.
Save mostlygeek/2279554 to your computer and use it in GitHub Desktop.
Controller from Play 2.0 Chatroom Sample App
object Application extends Controller {
/**
* Just display the home page.
*/
def index = Action { implicit request =>
Ok(views.html.index())
}
/**
* Display the chat room page.
*/
def chatRoom(username: Option[String]) = Action { implicit request =>
username.filterNot(_.isEmpty).map { username =>
Ok(views.html.chatRoom(username))
}.getOrElse {
Redirect(routes.Application.index).flashing(
"error" -> "Please choose a valid username."
)
}
}
/**
* Handles the chat websocket.
*/
def chat(username: String) = WebSocket.async[JsValue] { request =>
ChatRoom.join(username)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment