EventSource

class EventSource(requestSupplier: suspend (Headers) -> Request, retryTime: Duration = retryTimeDefault, eventTimeout: Duration? = eventTimeoutDefault, eventTimeoutCheckInterval: Duration = eventTimeoutCheckIntervalDefault, logger: Logger = LoggerFactory.getLogger(EventSource::class.java)) : Closeable

Server-Sent Events stream client.

EventSource is built on Sunday requests and allows customizing the requests for scenarios like authentication and custom headers.

Constructors

Link copied to clipboard
fun EventSource(requestSupplier: suspend (Headers) -> Request, retryTime: Duration = retryTimeDefault, eventTimeout: Duration? = eventTimeoutDefault, eventTimeoutCheckInterval: Duration = eventTimeoutCheckIntervalDefault, logger: Logger = LoggerFactory.getLogger(EventSource::class.java))

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class Event(val event: String?, val id: String?, val data: String?, val origin: String)

SSE Event.

Link copied to clipboard

Possible states of the EventSource.

Functions

Link copied to clipboard
fun addEventListener(event: String, handler: (EventSource.Event) -> Unit)

Add an event listener for a specific event type.

Link copied to clipboard
open override fun close()

Close and disconnect the EventSource.

Link copied to clipboard
fun connect()

Connect the EventSource.

Link copied to clipboard

Removed a previously added event listener.

Properties

Link copied to clipboard

Current list of event listeners.

Link copied to clipboard
var onError: (error: Throwable?) -> Unit?

Error handler.

Link copied to clipboard
var onMessage: (event: EventSource.Event) -> Unit?

Message handler.

Link copied to clipboard
var onOpen: () -> Unit?

Open handler.

Link copied to clipboard
Link copied to clipboard

Current retry time.