EventSource

open class EventSource(val url: String, init: EventSourceInit = definedExternally) : EventTarget, JsCloseable(source)

The EventSource interface is web content's interface to server-sent events.

MDN Reference

Constructors

Link copied to clipboard
constructor(url: String, init: EventSourceInit = definedExternally)
constructor(url: URL, init: EventSourceInit = definedExternally)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
sealed interface ReadyState

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The readyState read-only property of the EventSource interface returns a number representing the state of the connection.

Link copied to clipboard
val url: String

The url read-only property of the EventSource interface returns a string representing the URL of the source.

Link copied to clipboard

The withCredentials read-only property of the EventSource interface returns a boolean value indicating whether the EventSource object was instantiated with CORS credentials set.

Functions

Link copied to clipboard
fun <E : Event> EventTargetLike.addEventListener(type: EventType<E>, handler: (E) -> Unit, options: AddEventListenerOptions? = undefined)

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

Link copied to clipboard
open override fun close()

The close() method of the EventSource interface closes the connection, if one is made, and sets the EventSource.readyState attribute to 2 (closed).

Link copied to clipboard
open fun dispatchEvent(event: Event): Boolean

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

Link copied to clipboard
fun <E : Event> EventTargetLike.removeEventListener(type: EventType<E>, handler: (E) -> Unit, options: EventListenerOptions? = undefined)

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

Link copied to clipboard
fun <T : Event> when(type: EventType<T>, options: ObservableEventListenerOptions? = definedExternally): Observable<T>