Switched to JerseyBroadcaster
This commit is contained in:
parent
daeae689b3
commit
352d4b6c2a
7 changed files with 39 additions and 6 deletions
Binary file not shown.
Binary file not shown.
10
deploy/root/page.html
Normal file
10
deploy/root/page.html
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<html>
|
||||||
|
<head><title>blah</title></head>
|
||||||
|
<body>
|
||||||
|
<form method="post" enctype="application/x-www-form-urlencoded" action="chat">
|
||||||
|
<input name="action"/>
|
||||||
|
<input name="name"/>
|
||||||
|
<input name="message"/>
|
||||||
|
<input type="submit" value="submit" name="submit"/>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
|
@ -94,7 +94,7 @@ class AkkaCometServlet extends org.atmosphere.cpr.AtmosphereServlet
|
||||||
val servlet = new AkkaServlet
|
val servlet = new AkkaServlet
|
||||||
this.config = new AtmosphereConfig { ah = servlet }
|
this.config = new AtmosphereConfig { ah = servlet }
|
||||||
|
|
||||||
atmosphereHandlers.put("", new AtmosphereHandlerWrapper(servlet,new DefaultBroadcaster))
|
atmosphereHandlers.put("", new AtmosphereHandlerWrapper(servlet,new JerseyBroadcaster))
|
||||||
|
|
||||||
setCometSupport(new GrizzlyCometSupport(config))
|
setCometSupport(new GrizzlyCometSupport(config))
|
||||||
getCometSupport.init(sconf)
|
getCometSupport.init(sconf)
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -21,9 +21,6 @@ class Boot {
|
||||||
SupervisorConfig(
|
SupervisorConfig(
|
||||||
RestartStrategy(OneForOne, 3, 100),
|
RestartStrategy(OneForOne, 3, 100),
|
||||||
Supervise(
|
Supervise(
|
||||||
new SimpleService,
|
|
||||||
LifeCycle(Permanent, 100))
|
|
||||||
:: Supervise(
|
|
||||||
new Chat,
|
new Chat,
|
||||||
LifeCycle(Permanent, 100))
|
LifeCycle(Permanent, 100))
|
||||||
:: Nil)
|
:: Nil)
|
||||||
|
|
@ -93,6 +90,9 @@ class Chat extends Actor with Logging{
|
||||||
|
|
||||||
override def receive: PartialFunction[Any, Unit] = {
|
override def receive: PartialFunction[Any, Unit] = {
|
||||||
case Chat(who,what,msg) => {
|
case Chat(who,what,msg) => {
|
||||||
|
|
||||||
|
//log.info("Chat(" + who + ", " + what + ", " + msg + ")")
|
||||||
|
|
||||||
what match {
|
what match {
|
||||||
case "login" => reply("System Message__"+who+" has joined.")
|
case "login" => reply("System Message__"+who+" has joined.")
|
||||||
case "post" => reply("" + who + "__" + msg)
|
case "post" => reply("" + who + "__" + msg)
|
||||||
|
|
@ -106,6 +106,29 @@ class Chat extends Actor with Logging{
|
||||||
@Consumes(Array("application/x-www-form-urlencoded"))
|
@Consumes(Array("application/x-www-form-urlencoded"))
|
||||||
@POST
|
@POST
|
||||||
@Produces(Array("text/html"))
|
@Produces(Array("text/html"))
|
||||||
@FilterBroadcast(Array(classOf[XSSHtmlFilter]))
|
@FilterBroadcast(Array(classOf[XSSHtmlFilter],classOf[JsonpFilter]))
|
||||||
def publishMessage(form: MultivaluedMap[String, String]) = (this !! Chat(form.getFirst("name"),form.getFirst("action"),form.getFirst("message"))).getOrElse("System__error")
|
def publishMessage(form: MultivaluedMap[String, String]) = (this !! Chat(form.getFirst("name"),form.getFirst("action"),form.getFirst("message"))).getOrElse("System__error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JsonpFilter extends BroadcastFilter[String] with Logging
|
||||||
|
{
|
||||||
|
|
||||||
|
val BEGIN_SCRIPT_TAG = "<script type='text/javascript'>\n"
|
||||||
|
val END_SCRIPT_TAG = "</script>\n"
|
||||||
|
|
||||||
|
def filter(m : String) = {
|
||||||
|
var name = m
|
||||||
|
var message = ""
|
||||||
|
|
||||||
|
if (m.indexOf("__") > 0) {
|
||||||
|
name = m.substring(0, m.indexOf("__"))
|
||||||
|
message = m.substring(m.indexOf("__") + 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
(BEGIN_SCRIPT_TAG + "window.parent.app.update({ name: \""
|
||||||
|
+ name + "\", message: \""
|
||||||
|
+ message + "\" });\n"
|
||||||
|
+ END_SCRIPT_TAG)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue