Application.scala 992 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. object Application extends Controller {
  8. /**
  9. * Just display the home page.
  10. */
  11. def index = Action { implicit request =>
  12. Ok(views.html.index())
  13. }
  14. /**
  15. * Handles the chat websocket.
  16. */
  17. def chat(username: String, room: String = "default") = WebSocket.async[JsValue] { request =>
  18. ChatRoom.join(room, username)
  19. }
  20. val routeCache = {
  21. import routes._
  22. val jsRoutesClass = classOf[routes.javascript]
  23. val controllers = jsRoutesClass.getFields().map(_.get(null))
  24. controllers.flatMap { controller =>
  25. controller.getClass().getDeclaredMethods().map { action =>
  26. action.invoke(controller).asInstanceOf[play.core.Router.JavascriptReverseRoute]
  27. }
  28. }
  29. }
  30. def javascriptRoutes = Action { implicit request =>
  31. Ok(Routes.javascriptRouter("jsRoutes")(routeCache:_*)).as("text/javascript")
  32. }
  33. }