Application.scala 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package controllers
  2. import play.api._
  3. import play.api.mvc._
  4. import play.api.libs.json._
  5. import play.api.libs.iteratee._
  6. import models._
  7. import akka.actor._
  8. import scala.concurrent.duration._
  9. object Application extends Controller {
  10. /**
  11. * Just display the home page.
  12. */
  13. def index = Action { implicit request =>
  14. Ok(views.html.chatRoomNg())
  15. }
  16. /**
  17. * Handles the chat websocket.
  18. */
  19. def chat(username: String) = WebSocket.async[JsValue] { request =>
  20. ChatRoom.join(username)
  21. }
  22. val routeCache = {
  23. import routes._
  24. val jsRoutesClass = classOf[routes.javascript]
  25. val controllers = jsRoutesClass.getFields().map(_.get(null))
  26. controllers.flatMap { controller =>
  27. controller.getClass().getDeclaredMethods().map { action =>
  28. action.invoke(controller).asInstanceOf[play.core.Router.JavascriptReverseRoute]
  29. }
  30. }
  31. }
  32. def javascriptRoutes = Action { implicit request =>
  33. Ok(Routes.javascriptRouter("jsRoutes")(routeCache:_*)).as("text/javascript")
  34. }
  35. }