object EventSource
This class provides an easy way to use Server Sent Events (SSE) as a chunked encoding, using an Akka Source.
Please see the Server-Sent Events specification for details.
An example of how to display an event stream:
import java.time.ZonedDateTime import java.time.format.DateTimeFormatter import javax.inject.Singleton import akka.stream.scaladsl.Source import play.api.http.ContentTypes import play.api.libs.EventSource import play.api.mvc._ import scala.concurrent.duration._ def liveClock() = Action { val df: DateTimeFormatter = DateTimeFormatter.ofPattern("HH mm ss") val tickSource = Source.tick(0 millis, 100 millis, "TICK") val source = tickSource.map { (tick) => df.format(ZonedDateTime.now()) } Ok.chunked(source via EventSource.flow).as(ContentTypes.EVENT_STREAM) }
- Source
- EventSource.scala
- Alphabetic
- By Inheritance
- EventSource
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
case class
Event(data: String, id: Option[String], name: Option[String]) extends Product with Serializable
An event encoded with the SSE protocol..
- case class EventDataExtractor[A](eventData: (A) ⇒ String) extends Product with Serializable
- case class EventIdExtractor[E](eventId: (E) ⇒ Option[String]) extends Product with Serializable
- case class EventNameExtractor[E](eventName: (E) ⇒ Option[String]) extends Product with Serializable
- trait LowPriorityEventEncoder extends AnyRef
- trait LowPriorityEventIdExtractor extends AnyRef
- trait LowPriorityEventNameExtractor extends AnyRef
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
flow[E](implicit arg0: EventDataExtractor[E], arg1: EventNameExtractor[E], arg2: EventIdExtractor[E]): Flow[E, Event, _]
Makes a
Flow[E, Event, _]
, given an input source.Makes a
Flow[E, Event, _]
, given an input source.Usage example:
val jsonStream: Source[JsValue, Unit] = createJsonSource() Ok.chunked(jsonStream via EventSource.flow).as(ContentTypes.EVENT_STREAM)
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
- object Event extends Serializable
- object EventDataExtractor extends LowPriorityEventEncoder with Serializable
- object EventIdExtractor extends LowPriorityEventIdExtractor with Serializable
- object EventNameExtractor extends LowPriorityEventNameExtractor with Serializable