Created
April 1, 2012 23:54
-
-
Save mostlygeek/2279554 to your computer and use it in GitHub Desktop.
Controller from Play 2.0 Chatroom Sample App
This file contains hidden or 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
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