EventSource and Internet Explorer

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 {

  /** Central hub for distributing chat messages */
  val (eventOut, eventChannel) = Concurrent.broadcast[JsValue]

  /** Enumeratee for filtering messages based on eventSpec */
  def filter(eventSpec: String) = Enumeratee.filter[JsValue] {
    json: JsValue => ("(?i)" + eventSpec).r.pattern.matcher((json \ "eventSpec").as[String]).matches
  }

  /** Enumeratee for detecting disconnect of SSE stream */
  def connDeathWatch(addr: String): Enumeratee[JsValue, JsValue] = 
    Enumeratee.onIterateeDone{ () => println(addr + " - SSE disconnected") }

  /** Controller action serving activity based on eventSpec */
  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?

+4
1

, CORS. ( CORS.) , , polyfill CORS. CORS, polyfill.

0

Source: https://habr.com/ru/post/1533141/


All Articles