I have the following server side game code to provide an endpoint for Event5 events from HTML5 sources.
package controllers
import scala.util.matching
import play.api.mvc._
import play.api.libs.json.JsValue
import play.api.libs.iteratee.{Concurrent, Enumeratee}
import play.api.libs.EventSource
import play.api.libs.concurrent.Execution.Implicits._
object Application extends Controller {
val (eventOut, eventChannel) = Concurrent.broadcast[JsValue]
def filter(eventSpec: String) = Enumeratee.filter[JsValue] {
json: JsValue => ("(?i)" + eventSpec).r.pattern.matcher((json \ "eventSpec").as[String]).matches
}
def connDeathWatch(addr: String): Enumeratee[JsValue, JsValue] =
Enumeratee.onIterateeDone{ () => println(addr + " - SSE disconnected") }
def events = Action { req =>
println(req.remoteAddress + " - connected and subscribed for '" + eventSpec +"'")
Ok.feed(eventOut
&> filter(eventSpec)
&> Concurrent.buffer(50)
&> connDeathWatch(req.remoteAddress)
&> EventSource()
).as("text/event-stream").withHeaders(
"Access-Control-Allow-Origin" -> "*",
"Access-Control-Allow-Methods" -> "GET",
"Access-Control-Allow-Headers" -> "Content-Type"
)
}
}
My routes look like this
GET / events.Application.events controllers
This server works great when the Chrome browser connects through an EventSource object. Since IE does not support EventSources, I use this polyfill library. Now the problem is: IE correctly subscribes to events, since I see the "connected and signed" log output, but as soon as the event is sent to this connection, it logs "SSE disconnected". What am I missing here? Some http headers?