Skip to content

Commit

Permalink
FIX hardcoded controller path to be rest url
Browse files Browse the repository at this point in the history
  • Loading branch information
prayagupa committed Nov 9, 2014
1 parent cdd3dcc commit c078fad
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
47 changes: 47 additions & 0 deletions smartad-backend/app/controllers/NotificationController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package controllers

import play.api.mvc._

import play.api.libs.{ EventSource }
import play.api.libs.iteratee._
import play.api.libs.concurrent._

import scala.concurrent.duration._
import scala.language.postfixOps
import play.api.libs.concurrent.Execution.Implicits.defaultContext


/**
* notification engine using SSE
*/

object NotificationController extends Controller {

/**
* notification engine using ES
*/

/**
* A String Enumerator producing a formatted Time message every 100 millis.
* A callback enumerator is pure an can be applied on several Iteratee.
*/
lazy val clock: Enumerator[String] = {

import java.util._
import java.text._

val dateFormat = new SimpleDateFormat("HH mm ss")

Enumerator.generateM {
Promise.timeout(Some(dateFormat.format(new Date)), 100 milliseconds)
}
}

def index = Action {
Ok(views.html.user())
}

def notification = Action {
Ok.chunked(clock &> EventSource()).as("text/event-stream")
}
}
19 changes: 19 additions & 0 deletions smartad-backend/app/views/user.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@usermain {

<h1>SSE clock</h1>

<h1 id="clock">here goes time </h1>


<script type="text/javascript" charset="utf-8">
if (!!window.EventSource) {
var source = new EventSource("/notification");

source.addEventListener('message', function(e) {
$('#clock').html(e.data.replace(/(\d)/g, '<span>$1</span>'))
});
} else {
$("#clock").html("Sorry");
}
</script>
}
15 changes: 15 additions & 0 deletions smartad-backend/app/views/usermain.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@(content: Html)

<!DOCTYPE html>

<html>
<head>
<title>clock</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
</html>
2 changes: 1 addition & 1 deletion smartad-backend/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GET / controllers.Application.index
GET /getJson controllers.Application.getJson
GET /user controllers.NotificationController.index
GET /notification/n controllers.RestController.notification
GET /notification/ controllers.NotificationController.notification
GET /notification controllers.NotificationController.notification
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)

0 comments on commit c078fad

Please sign in to comment.