object EventSource
This class provides an easy way to use Server Sent Events (SSE) as a chunked encoding, using an Pekko 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 org.apache.pekko.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
- Protected
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[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- 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[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @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
- @HotSpotIntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- object Event extends Serializable
- object EventDataExtractor extends LowPriorityEventEncoder with Serializable
- object EventIdExtractor extends LowPriorityEventIdExtractor with Serializable
- object EventNameExtractor extends LowPriorityEventNameExtractor with Serializable
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)