本文整理汇总了Scala中play.api.libs.iteratee.Enumeratee类的典型用法代码示例。如果您正苦于以下问题:Scala Enumeratee类的具体用法?Scala Enumeratee怎么用?Scala Enumeratee使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Enumeratee类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ChatController
//设置package包名称以及导入依赖的类
package controllers
import models.{User, ChatRoom}
import play.api.data._
import play.api.data.Forms._
import play.api.libs.EventSource
import play.api.libs.iteratee.{Enumeratee, Concurrent}
import play.api.libs.json.JsValue
import play.api.mvc.{WebSocket, Action, Controller}
import play.api.libs.concurrent.Execution.Implicits._
object ChatController extends Controller {
def index = Action { implicit request =>
Ok(views.html.chat())
}
def chatWS(username: String) = WebSocket.tryAccept[JsValue] { request =>
ChatRoom.join(username).map{ io =>
Right(io)
}.recover{ case e => Left(Ok(e))}
}
def chatSSE(username: String) = Action.async { request =>
ChatRoom.join(username).map{ io =>
Ok.feed(io._2
&> Concurrent.buffer(50)
&> Enumeratee.onIterateeDone{ () =>
play.Logger.info(request.remoteAddress + " - SSE disconnected")
}
&> EventSource()).as("text/event-stream")
}.recover{ case e => BadRequest(e)}
}
val talkForm = Form(
tuple(
"username" -> nonEmptyText,
"msg" -> text
)
)
def talk = Action{ implicit request =>
talkForm.bindFromRequest.fold(
error => BadRequest,
value => {
ChatRoom.talk(value._1, value._2)
Ok
}
)
}
}