EventSource

  • Revision slug: Server-sent_events/EventSource
  • Revision title: EventSource
  • Revision id: 60472
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment new page; page created, 278 words added

Revision Content

The EventSource interface is used to manage server-sent events. See Using server-sent events for details on how to use it.

Method overview

void close();
void init(in nsIPrincipal principal, in nsIScriptContext scriptContext, in nsPIDOMWindow ownerWindow, in DOMString url); {{ noscript_inline() }}

Attributes

Attribute Type Description
onerror {{ Interface("nsIDOMEventListener") }} A JavaScript function to call when an error occurs.
onmessage {{ Interface("nsIDOMEventListener") }} A JavaScript function to call when an a message without an event field arrives.
onopen {{ Interface("nsIDOMEventListener") }} A JavaScript function to call when the connection has opened.
readyState long The state of the connection, must be one of CONNECTING, OPEN, or CLOSED. Read only.
url {{ domxref("DOMString") }} Read only.

Constants

Constant Value Description
CONNECTING 0 The connection is being established.
OPEN 1 The connection is open and dispatching events.
CLOSED 2 The connection is not being established, has been closed or there was a fatal error.

Methods

close()

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

void close();
Parameters

None.

{{ method_noscript("init") }}

Initializes the object for use from C++ code with the principal, script context, and owner window that should be used.

void init(
  in nsIPrincipal principal,
  in nsIScriptContext scriptContext,
  in nsPIDOMWindow ownerWindow,
  in DOMString url
);
Parameters
principal
The principal to use for the request. This must not be null.
scriptContext
The script context to use for the request. May be null.
ownerWindow
The associated window for the request. May be null.
url
The EventSource's URL. This must not be empty.

See also

  • {{ spec("http://www.w3.org/TR/eventsource/#the-eventsource-interface","Server-Sent Events: The EventSource Interface","WD") }}
  • Using server-sent events

Revision Source

<p>The EventSource interface is used to manage server-sent events. See <a href="/en/Server-sent_events/Using_server-sent_events" title="en/Server-sent events/Using server-sent events">Using server-sent events</a> for details on how to use it.</p>
<h2 name="Method_overview">Method overview</h2>
<table class="standard-table"> <tbody> <tr> <td><code>void <a href="#close()">close</a>();</code></td> </tr> <tr> <td><code>void <a href="#init()">init</a>(in nsIPrincipal principal, in nsIScriptContext scriptContext, in nsPIDOMWindow ownerWindow, in DOMString url);</code> {{ noscript_inline() }}</td> </tr> </tbody>
</table>
<h2 name="Attributes">Attributes</h2>
<table class="standard-table"> <tbody> <tr> <td class="header">Attribute</td> <td class="header">Type</td> <td class="header">Description</td> </tr> <tr> <td><code>onerror</code></td> <td><code>{{ Interface("nsIDOMEventListener") }}</code></td> <td>A JavaScript function to call when an error occurs. </td> </tr> <tr> <td><code>onmessage</code></td> <td><code>{{ Interface("nsIDOMEventListener") }}</code></td> <td>A JavaScript function to call when an a message without an <code>event</code> field arrives.</td> </tr> <tr> <td><code>onopen</code></td> <td><code>{{ Interface("nsIDOMEventListener") }}</code></td> <td>A JavaScript function to call when the connection has opened.</td> </tr> <tr> <td><code>readyState</code></td> <td><code><a href="/en/long" title="en/long">long</a></code></td> <td>The state of the connection, must be one of <code>CONNECTING</code>, <code>OPEN</code>, or <code>CLOSED</code>. <strong>Read only.</strong></td> </tr> <tr> <td><code>url</code></td> <td>{{ domxref("DOMString") }}</td> <td><strong>Read only.</strong></td> </tr> </tbody>
</table>
<h2 name="Constants">Constants</h2>
<table class="standard-table"> <tbody> <tr> <td class="header">Constant</td> <td class="header">Value</td> <td class="header">Description</td> </tr> <tr> <td><code>CONNECTING</code></td> <td><code>0</code></td> <td>The connection is being established.</td> </tr> <tr> <td><code>OPEN</code></td> <td><code>1</code></td> <td>The connection is open and dispatching events.</td> </tr> <tr> <td><code>CLOSED</code></td> <td><code>2</code></td> <td>The connection is not being established, has been closed or there was a fatal error.</td> </tr> </tbody>
</table>
<h2 name="Methods">Methods</h2>
<h3 name="close()">close()</h3>
<p>Closes the connection, if any, and sets the <code>readyState</code> attribute to <code>CLOSED</code>. If the connection is already closed, the method does nothing.</p>
<pre class="eval">void close();
</pre>
<h6 name="Parameters">Parameters</h6>
<p>None.</p>
<p>{{ method_noscript("init") }}</p>
<p>Initializes the object for use from C++ code with the principal, script context, and owner window that should be used.</p>
<pre class="eval">void init(
  in nsIPrincipal principal,
  in nsIScriptContext scriptContext,
  in nsPIDOMWindow ownerWindow,
  in DOMString url
);
</pre>
<h6 name="Parameters">Parameters</h6>
<dl> <dt><code>principal</code></dt> <dd>The principal to use for the request. This must not be <code>null</code>.</dd> <dt><code>scriptContext</code></dt> <dd>The script context to use for the request. May be <code>null</code>.</dd> <dt><code>ownerWindow</code></dt> <dd>The associated window for the request. May be <code>null</code>.</dd> <dt><code>url</code></dt> <dd>The <code>EventSource</code>'s URL. This must not be empty.</dd>
</dl>
<h2 name="See_also">See also</h2>
<ul> <li>{{ spec("http://www.w3.org/TR/eventsource/#the-eventsource-interface","Server-Sent Events: The EventSource Interface","WD") }}</li> <li><a href="/en/Server-sent_events/Using_server-sent_events" title="en/Server-sent events/Using server-sent events">Using server-sent events</a></li>
</ul>
Revert to this revision