EventSource
interface
interface EventSource extends EventTargetRepresents a connection to a server that sends
server-sent events,
receiving updates pushed by the server as a stream of message events over a
persistent HTTP connection that automatically reconnects when interrupted.
variable
var EventSource: { … }The EventSource interface is a 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. The connection
remains open until closed by calling EventSource.close.
See also
Constructors
constructor
new EventSource(url: string | URL, eventSourceInitDict?: EventSourceInit): EventSourceProperties
onerror
onerror: ((this: EventSource, ev: Event) => any) | nullonmessage
onmessage: ((this: EventSource, ev: MessageEvent) => any) | nullonopen
onopen: ((this: EventSource, ev: Event) => any) | nullreadyState
readonly readyState: numberReturns the state of this EventSource object's connection. It can have the values described below.
url
readonly url: stringReturns the URL providing the event stream.
withCredentials
readonly withCredentials: booleanReturns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
CONNECTING
readonly CONNECTING: 0readonly CONNECTING: 0OPEN
readonly OPEN: 1readonly OPEN: 1CLOSED
readonly CLOSED: 2readonly CLOSED: 2prototype
prototype: EventSourceMethods
close
close(): voidAborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
addEventListener
addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): voidaddEventListener(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | AddEventListenerOptions): voidaddEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): voidremoveEventListener
removeEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | EventListenerOptions): voidremoveEventListener(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | EventListenerOptions): voidremoveEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void