首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EventSource和Internet

EventSource和Internet
EN

Stack Overflow用户
提问于 2014-03-24 10:57:24
回答 1查看 3K关注 0票数 4

我有以下服务器端播放代码,以便为HTML5 EventSources提供端点。

代码语言:javascript
复制
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"
    )
  }

}

我的路线是这样的

/events controllers.Application.events

当Chrome浏览器通过EventSource对象附加自己时,该服务器运行得非常好。由于IE不支持EventSources,所以我使用的是填充库。现在的问题是: IE正确地订阅了事件,就像我看到的“已连接和订阅的”日志输出一样,但是一旦一个事件被传递给这个连接,它就会记录'SSE断开连接‘。我在这里错过了什么?一些http标头?

EN

回答 1

Stack Overflow用户

发布于 2014-09-30 18:19:49

看上去你可能在用CORS。(您正在发送CORS头。)如果是这样的话,这可能就是问题所在,因为您正在使用的多边形填充不支持CORS。如果您需要CORS,可以使用这个填充代替了

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22607423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档