public interface EventSource extends EventTarget
The EventSource
interface is used to manage server-sent events. You can set the onmessage attribute to a JavaScript function to receive non-typed messages (that is, messages with no event
field). You can also call addEventListener()
to listen for events just like any other event source.
See Using server-sent events for further details.
Modifier and Type | Field and Description |
---|---|
static int |
CLOSED
The connection is not being established, has been closed or there was a fatal error.
|
static int |
CONNECTING
The connection is being established.
|
static int |
OPEN
The connection is open and dispatching events.
|
Modifier and Type | Method and Description |
---|---|
EventRemover |
addEventListener(String type,
EventListener listener)
Register an event handler of a specific event type on the
EventTarget . |
EventRemover |
addEventListener(String type,
EventListener listener,
boolean useCapture)
Register an event handler of a specific event type on the
EventTarget . |
void |
close()
Closes the connection, if any, and sets the
readyState attribute to CLOSED . |
boolean |
dispatchEvent(Event evt)
Dispatch an event to this
EventTarget . |
EventListener |
getOnerror()
A JavaScript function to call when an error occurs.
|
EventListener |
getOnmessage()
A JavaScript function to call when an a message without an
event field arrives. |
EventListener |
getOnopen()
A JavaScript function to call when the connection has opened.
|
int |
getReadyState()
The state of the connection, must be one of
CONNECTING , OPEN , or CLOSED . |
String |
getUrl()
Read only.
|
String |
getURL() |
void |
removeEventListener(String type,
EventListener listener)
Removes an event listener from the
EventTarget . |
void |
removeEventListener(String type,
EventListener listener,
boolean useCapture)
Removes an event listener from the
EventTarget . |
void |
setOnerror(EventListener arg) |
void |
setOnmessage(EventListener arg) |
void |
setOnopen(EventListener arg) |
static final int CLOSED
static final int CONNECTING
static final int OPEN
String getURL()
EventListener getOnerror()
void setOnerror(EventListener arg)
EventListener getOnmessage()
event
field arrives.void setOnmessage(EventListener arg)
EventListener getOnopen()
void setOnopen(EventListener arg)
int getReadyState()
CONNECTING
, OPEN
, or CLOSED
. Read only.String getUrl()
EventRemover addEventListener(String type, EventListener listener)
EventTarget
EventTarget
.addEventListener
in interface EventTarget
EventRemover addEventListener(String type, EventListener listener, boolean useCapture)
EventTarget
EventTarget
.addEventListener
in interface EventTarget
void close()
readyState
attribute to CLOSED
. If the connection is already closed, the method does nothing.boolean dispatchEvent(Event evt)
EventTarget
EventTarget
.dispatchEvent
in interface EventTarget
void removeEventListener(String type, EventListener listener)
EventTarget
EventTarget
.removeEventListener
in interface EventTarget
void removeEventListener(String type, EventListener listener, boolean useCapture)
EventTarget
EventTarget
.removeEventListener
in interface EventTarget
Copyright © 2016. All rights reserved.