1
0

Application.scala 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. def stats = Action {
  15. Ok(Json.obj(
  16. "rooms" -> ChatRoom.chatRooms.keySet,
  17. "activeConnections" -> ChatRoom.connectionCount,
  18. "totalCards" -> Card.size
  19. ))
  20. }
  21. /**
  22. * Handles the chat websocket.
  23. */
  24. def chat(username: String, room: String = "default") = WebSocket.async[JsValue] { request =>
  25. ChatRoom.join(room, username)
  26. }
  27. val routeCache = {
  28. import routes._
  29. val jsRoutesClass = classOf[routes.javascript]
  30. val controllers = jsRoutesClass.getFields().map(_.get(null))
  31. controllers.flatMap { controller =>
  32. controller.getClass().getDeclaredMethods().map { action =>
  33. action.invoke(controller).asInstanceOf[play.core.Router.JavascriptReverseRoute]
  34. }
  35. }
  36. }
  37. def javascriptRoutes = Action { implicit request =>
  38. Ok(Routes.javascriptRouter("jsRoutes")(routeCache:_*)).as("text/javascript")
  39. }
  40. }