forked from prayagupa/smartad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX hardcoded controller path to be rest url
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
smartad-backend/app/controllers/NotificationController.scala
This file contains 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
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") | ||
} | ||
} |
This file contains 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
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> | ||
} |
This file contains 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
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> |
This file contains 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