Name
EventSource — a Comet connection to an HTTP server
Inherits from
EventTarget
Synopsis
An EventSource represents a long-lived HTTP connection through
which a Web server can “push” textual messages. To use these “Server
Sent Events”, pass the server URL to the EventSource() constructor and then
register a message event handler on the resulting Event
Source object.
Server Sent Events are new, and at the time of this writing, are not supported in all browsers.
Constructor
newEventSource(stringurl)
Creates a new EventSource
object connected to the web server at the specified
url. url is
interpreted relative to the URL of the containing document.
Constants
These constants define the possible values of the readyState property.
unsigned shortCONNECTING= 0The connection is being set up, or the connection closed and the EventSource is re-connecting.
unsigned shortOPEN= 1The connection is open and events are being dispatched.
unsigned shortCLOSED= 2The connection was closed, either because
close()was called or a fatal error occurred and it is not possible to reconnect.
Properties
readonly unsigned shortreadyStateThe state of the connection. The constants above define the possible values.
readonly stringurlThe absolute URL to which the EventSource is connected.
Methods
void close()
close()This method closes the connection. Once this method is called, the EventSource object can no longer be used. If you need to connect again, create a new EventSource.
Event Handlers
Network communication is asynchronous, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access