Object

play.api.libs

EventSource

Related Doc: package libs

Permalink

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
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. EventSource
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Type Members

  1. case class Event(data: String, id: Option[String], name: Option[String]) extends Product with Serializable

    Permalink

    An event encoded with the SSE protocol..

  2. case class EventDataExtractor[A](eventData: (A) ⇒ String) extends Product with Serializable

    Permalink
  3. case class EventIdExtractor[E](eventId: (E) ⇒ Option[String]) extends Product with Serializable

    Permalink
  4. case class EventNameExtractor[E](eventName: (E) ⇒ Option[String]) extends Product with Serializable

    Permalink
  5. trait LowPriorityEventEncoder extends AnyRef

    Permalink
  6. trait LowPriorityEventIdExtractor extends AnyRef

    Permalink
  7. trait LowPriorityEventNameExtractor extends AnyRef

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. object Event extends Serializable

    Permalink
  5. object EventDataExtractor extends LowPriorityEventEncoder with Serializable

    Permalink
  6. object EventIdExtractor extends LowPriorityEventIdExtractor with Serializable

    Permalink
  7. object EventNameExtractor extends LowPriorityEventNameExtractor with Serializable

    Permalink
  8. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  9. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. def flow[E](implicit arg0: EventDataExtractor[E], arg1: EventNameExtractor[E], arg2: EventIdExtractor[E]): Flow[E, Event, _]

    Permalink

    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)
  14. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  15. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  16. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  17. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  20. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  21. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def apply[E]()(implicit arg0: EventDataExtractor[E], arg1: EventNameExtractor[E], arg2: EventIdExtractor[E]): Enumeratee[E, Event]

    Permalink

    Makes an Enumeratee[E, Event], that is an iteratee.Enumeratee transforming E values into Event values.

    Makes an Enumeratee[E, Event], that is an iteratee.Enumeratee transforming E values into Event values.

    Usage example:

    val someDataStream: Enumerator[SomeData] = ???
    Ok.chunked(someDataStream &> EventSource())
    E

    from type of the Enumeratee

    Annotations
    @deprecated
    Deprecated

    (Since version 2.5.0) Use apply with an Akka source instead

Inherited from AnyRef

Inherited from Any

Ungrouped