The EventSource interface is web content's interface to server-sent events. An EventSource instance opens a persistent connection to an HTTP server, which sends events in text/event-stream format.

Documentation EventSource by Mozilla Contributors, licensed under CC-BY-SA 2.5.

See also:

Static variables

@:value(2)staticinlineread onlyCLOSED:Int = 2

@:value(0)staticinlineread onlyCONNECTING:Int = 0

@:value(1)staticinlineread onlyOPEN:Int = 1

Constructor

new(url:String, ?eventSourceInitDict:Null<EventSourceInit>)

Throws:

null

DOMError

Variables

onerror:Function

Is an EventHandler called when an error occurs and the error event is dispatched on an EventSource object.

onmessage:Function

Is an EventHandler called when a message event is received, that is when a message is coming from the source.

onopen:Function

Is an EventHandler called when an open event is received, that is when the connection was just opened.

read onlyreadyState:Int

A number representing the state of the connection. Possible values are CONNECTING (0), OPEN (1), or CLOSED (2).

read onlyurl:String

A DOMString representing the URL of the source.

read onlywithCredentials:Bool

A Boolean indicating whether the EventSource object was instantiated with cross-origin (CORS) credentials set (true), or not (false, the default).

Methods

close():Void

Closes the connection, if any, and sets the readyState attribute to CLOSED. If the connection is already closed, the method does nothing.

Inherited Variables

Inherited Methods

Defined by EventTarget

addEventListener(type:String, listener:Function, ?options:EitherType<AddEventListenerOptions, Bool>, ?wantsUntrusted:Bool):Void

addEventListener(type:String, listener:EventListener, ?options:EitherType<AddEventListenerOptions, Bool>, ?wantsUntrusted:Bool):Void

Register an event handler of a specific event type on the EventTarget.

Throws:

null

DOMError

dispatchEvent(event:Event):Bool

Dispatch an event to this EventTarget.

Throws:

null

DOMError

removeEventListener(type:String, listener:Function, ?options:EitherType<EventListenerOptions, Bool>):Void

removeEventListener(type:String, listener:EventListener, ?options:EitherType<EventListenerOptions, Bool>):Void

Removes an event listener from the EventTarget.

Throws:

null

DOMError