recursal/MDN huggingface dataset:
WebSocket: close event
======================

The `close` event is fired when a connection with a `WebSocket` is closed.

Syntax
------

Use the event name in methods like `addEventListener()`, or set an event handler property.


```js
addEventListener("close", (event) => {});

onclose = (event) => {};
```

Event type
----------

A `CloseEvent`. Inherits from `Event`.

Event

CloseEventEvent properties
----------------

*In addition to the properties listed below, properties from the parent interface, `Event`, are available.*

`code` Read only 

Returns an `unsigned short` containing the close code sent by the server.

`reason` Read only 

Returns a string indicating the reason the server closed the connection. This is specific to the particular server and sub-protocol.

`wasClean` Read only 

Returns a boolean value that Indicates whether or not the connection was cleanly closed.

Examples
--------

You might want to know when the connection has been closed so that you can update the UI or, perhaps, save data about the closed connection. Given that you have a variable called `exampleSocket` that refers to an opened `WebSocket`, this handler would handle the situation where the socket has been closed.


```js
exampleSocket.addEventListener("close", (event) => {
  console.log("The connection has been closed successfully.");
});
```


You can perform the same actions using the event handler property, like this:


```js
exampleSocket.onclose = (event) => {
  console.log("The connection has been closed successfully.");
};
```

Specifications
--------------

| Specification |
| --- |
| WebSockets Standard # dom-websocket-onclose |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebSocket: error event
* WebSocket: message event
* WebSocket: open event
* Writing WebSocket client applications
WebSocket: url property
=======================

 The **`WebSocket.url`** read-only property returns the absolute
 URL of the `WebSocket` as resolved by the constructor.

Value
-----

A string.

Specifications
--------------

| Specification |
| --- |
| WebSockets Standard # ref-for-dom-websocket-url① |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
WebSocket: close() method
=========================

 The **`WebSocket.close()`** method closes the
 `WebSocket` connection or connection attempt, if any. If the connection is
 already `CLOSED`, this method does nothing.

**Note:** The process of closing the connection begins with a closing handshake, and the `close()` method does not discard previously-sent messages before starting that closing handshake; even if the user agent is still busy sending those messages, the handshake will only start after the messages are sent.

Syntax
------


```js
close()
close(code)
close(code, reason)
```

### Parameters

`code` Optional

An integer WebSocket connection close code value indicating a reason for closure:

* If unspecified, a close code for the connection is automatically set: to `1000` for a normal closure, or otherwise to another standard value in the range `1001`-`1015` that indicates the actual reason the connection was closed.
* If specified, the value of this `code` parameter overrides the automatic setting of the close code for the connection, and instead sets a custom code.
 The value must be an integer: either `1000`, or else a custom code of your choosing in the range `3000`-`4999`. If you specify a `code` value, you should also specify a `reason` value.

`reason` Optional

A string providing a custom WebSocket connection close reason (a concise human-readable prose explanation for the closure). The value must be no longer than 123 bytes (encoded in UTF-8).

**Note:** Because UTF-8 uses two to four bytes to encode any non-ASCII characters, a 123-character `reason` value containing non-ASCII characters would exceed the 123-byte limit.

If you specify a `reason` value, you should also specify a `code` value.

### Return value

None (`undefined`).

### Exceptions

`InvalidAccessError` `DOMException`

Thrown if `code` is neither an integer equal to `1000` nor an integer in the range `3000` – `4999`.

`SyntaxError` `DOMException`

Thrown if the UTF-8-encoded `reason` value is longer than 123 bytes.

Specifications
--------------

| Specification |
| --- |
| WebSockets Standard # ref-for-dom-websocket-close① |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* RFC 6455 (the WebSocket Protocol specification)
WebSocket: error event
======================

The `error` event is fired when a connection with a `WebSocket` has been closed due to an error (some data couldn't be sent for example).

Syntax
------

Use the event name in methods like `addEventListener()`, or set an event handler property.


```js
addEventListener("error", (event) => {});

onerror = (event) => {};
```

Event type
----------

A generic `Event`.

Examples
--------


```js
// Create WebSocket connection
const socket = new WebSocket("ws://localhost:8080");

// Listen for possible errors
socket.addEventListener("error", (event) => {
  console.log("WebSocket error: ", event);
});
```

Specifications
--------------

| Specification |
| --- |
| WebSockets Standard # dom-websocket-onerror |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebSocket: close event
* WebSocket: message event
* WebSocket: open event
* Writing WebSocket client applications
WebSocket: send() method
========================

 The **`WebSocket.send()`** method enqueues the specified data
 to be transmitted to the server over the WebSocket connection, increasing the value of
 `bufferedAmount` by the number of bytes needed to contain the data. If the
 data can't be sent (for example, because it needs to be buffered but the buffer is
 full), the socket is closed automatically.
 The browser will throw an exception if you call `send()` when the connection is in the `CONNECTING` state. If you call `send()` when the connection is in the `CLOSING` or `CLOSED` states, the browser will silently discard the data.

Syntax
------


```js
send(data)
```

### Parameters

`data`

The data to send to the server. It may be one of the following types:

`string`

 A text string. The string is added to the buffer in UTF-8 format, and the value
 of `bufferedAmount` is increased by the number of bytes required to
 represent the UTF-8 string.


`ArrayBuffer`

 You can send the underlying binary data used by a typed array object; its binary
 data contents are queued in the buffer, increasing the value of
 `bufferedAmount` by the requisite number of bytes.


`Blob`

 Specifying a `Blob` enqueues the blob's raw data to be transmitted in
 a binary frame (the `Blob.type` is ignored).
 The value of `bufferedAmount` is increased by the byte size of that raw data.


`TypedArray` or a `DataView`

 You can send any JavaScript typed array object as a binary frame;
 its binary data contents are queued in the buffer,
 increasing the value of `bufferedAmount` by the requisite number of bytes.



### Return value

None (`undefined`).

### Exceptions

`InvalidStateError` `DOMException`

Thrown if `WebSocket.readyState` is `CONNECTING`.

Specifications
--------------

| Specification |
| --- |
| WebSockets Standard # ref-for-dom-websocket-send① |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
WebSocket: readyState property
==============================

 The **`WebSocket.readyState`** read-only property returns the
 current state of the `WebSocket` connection.

Value
-----

One of the following `unsigned short` values:

| Value | State | Description |
| --- | --- | --- |
| `0` | `CONNECTING` | Socket has been created. The connection is not yet open. |
| `1` | `OPEN` | The connection is open and ready to communicate. |
| `2` | `CLOSING` | The connection is in the process of closing. |
| `3` | `CLOSED` | The connection is closed or couldn't be opened. |

Specifications
--------------

| Specification |
| --- |
| WebSockets Standard # ref-for-dom-websocket-readystate① |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
WebSocket: binaryType property
==============================

 The **`WebSocket.binaryType`** property controls the type of
 binary data being received over the WebSocket connection.

Value
-----

A string:

`"blob"`

Use `Blob` objects for binary data. This is the default value.

`"arraybuffer"`

Use `ArrayBuffer` objects for binary data.

Examples
--------


```js
// Create WebSocket connection.
const socket = new WebSocket("ws://localhost:8080");

// Change binary type from "blob" to "arraybuffer"
socket.binaryType = "arraybuffer";

// Listen for messages
socket.addEventListener("message", (event) => {
  if (event.data instanceof ArrayBuffer) {
    // binary frame
    const view = new DataView(event.data);
    console.log(view.getInt32(0));
  } else {
    // text frame
    console.log(event.data);
  }
});
```

Specifications
--------------

| Specification |
| --- |
| WebSockets Standard # ref-for-dom-websocket-binarytype① |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
WebSocket: open event
=====================

The `open` event is fired when a connection with a `WebSocket` is opened.

Syntax
------

Use the event name in methods like `addEventListener()`, or set an event handler property.


```js
addEventListener("open", (event) => {});

onopen = (event) => {};
```

Event type
----------

A generic `Event`.

Examples
--------


```js
// Create WebSocket connection.
const socket = new WebSocket("ws://localhost:8080");

// Connection opened
socket.addEventListener("open", (event) => {
  socket.send("Hello Server!");
});
```

Specifications
--------------

| Specification |
| --- |
| WebSockets Standard # dom-websocket-onopen |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* WebSocket: close event
* WebSocket: error event
* WebSocket: message event
* Writing WebSocket client applications
RTCRtpStreamStats: trackId property
===================================

 The `RTCRtpStreamStats` dictionary's
 **`trackId`** property is a string which uniquely identifies
 the `RTCMediaStreamTrackStats` object which contains the track statistics
 for the `MediaStreamTrack` for which statistics are provided in this
 object.

Value
-----

 A string which uniquely identifies the
 `RTCMediaStreamTrackStats` object that provides statistics for the track
 for which statistics are being collected by this `RTCStatsReport`.


**Note:** This value is *not* the same as the value of
 `MediaStreamTrack.id`.


Specifications
--------------

#### No specification found

No specification data found for `api.RTCRtpStreamStats.trackId`.  
Check for problems with this page or contribute a missing `spec_url` to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
RTCRtpStreamStats: ssrc property
================================

 The `RTCRtpStreamStats` dictionary's
 **`ssrc`** property provides the Synchronization Source
 (SSRC), an integer which uniquely identifies the source of the RTP
 packets whose statistics are covered by the `RTCStatsReport` that
 includes this `RTCRtpStreamStats` dictionary.

Value
-----

 The Synchronization Source (SSRC) is a 32-bit integer uniquely identifying the source
 of the RTP packets whose statistics are covered by the `RTCStatsReport`
 object of which this `RTCRtpStreamStats` object is a component.

 The manner in which these values are generated is not mandated by the specification,
 although it does make recommendations. You should not make any assumptions based on the
 value of `ssrc` other than that any two objects with the same
 `ssrc` value refer to the same source. See RFC 3550, section 8 for
 additional information about `ssrc`.


**Note:** The specification includes an example that generates values
 for `ssrc` using MD5. While not part of the standard, exactly, it is a good
 mechanism that may be used by some browsers; others may use other methods, such as
 random number generators. *Do not* rely upon these values meaning anything
 other than "these objects are associated with the same source."


Specifications
--------------

#### No specification found

No specification data found for `api.RTCRtpStreamStats.ssrc`.  
Check for problems with this page or contribute a missing `spec_url` to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
RTCRtpStreamStats: kind property
================================

 The **`kind`** property of the
 `RTCRtpStreamStats` dictionary is a string indicating whether the
 described RTP stream contains audio or video media.

 Its value
 is always either `"audio"` or `"video"`.

 This property was previously called `mediaType`. The name was changed in the
 specification in February, 2018. See Browser compatibility below to
 determine how this affects the browsers you're targeting.

Value
-----

 A string whose value is `"audio"` if the track whose
 statistics are given by the `RTCRtpStreamStats` object contains audio, or
 `"video"` if the track contains video media.

 This string will always be the same as the one provided by the associated
 `MediaStreamTrack` object's `kind`
 property. It will also match the statistics object's `RTCCodecStats.codec`
 property's media type.

Specifications
--------------

#### No specification found

No specification data found for `api.RTCRtpStreamStats.kind`.  
Check for problems with this page or contribute a missing `spec_url` to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
RTCRtpStreamStats: nackCount property
=====================================

 The **`nackCount`** property of the
 `RTCRtpStreamStats` dictionary is a numeric value indicating the number
 of times the receiver sent a **NACK packet** to the sender.

 A NACK
 (Negative ACKnowledgement, also called "Generic NACK") packet tells the sender that one
 or more of the RTP packets it sent were lost in transport.

Value
-----

 An integer value indicating how many times the receiver sent a NACK packet to the
 sender after detecting that one or more packets were lost during transport.

**Note:** This value is only available on the receiver.

Specifications
--------------

#### No specification found

No specification data found for `api.RTCRtpStreamStats.nackCount`.  
Check for problems with this page or contribute a missing `spec_url` to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
RTCRtpStreamStats: codecId property
===================================

 The `RTCRtpStreamStats` dictionary's
 **`codecId`** property is a string which uniquely identifies
 the object that was inspected to produce the data in the `RTCCodecStats`
 for the RTP stream.

Value
-----

 A string which uniquely identifies the object from which the contents
 of the stream's `RTCCodecStats` are derived.

Specifications
--------------

#### No specification found

No specification data found for `api.RTCRtpStreamStats.codecId`.  
Check for problems with this page or contribute a missing `spec_url` to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
RTCRtpStreamStats: pliCount property
====================================

 The **`pliCount`** property of the
 `RTCRtpStreamStats` dictionary states the number of times the stream's
 receiving end sent a **Picture Loss Indication** (**PLI**)
 packet to the sender.

 A PLI packet indicates that some amount of encoded video
 data has been lost for one or more frames.

Value
-----

 An integer value indicating the number of times a PLI packet was sent by the stream's
 receiver to the sender.

 A PLI message is used by video decoders (running on the receiving end of the stream) to
 notify the encoder (the sender) that an undefined amount of coded video data, which may
 span frame boundaries, has been lost.

 This may trigger the sender to send a full frame in order to allow the receiver to
 re-synchronize, since lost data may be an irrecoverable situation for decoding media.
 However, the primary purpose of this message is to allow the sender to consider
 techniques to mitigate network performance issues. This is often achieved by methods
 such as increasing the compression, lowering resolution, or finding other ways to reduce
 the bit rate of the stream.


**Note:** This value is only available on the receiver, and only for
 video media.


Specifications
--------------

#### No specification found

No specification data found for `api.RTCRtpStreamStats.pliCount`.  
Check for problems with this page or contribute a missing `spec_url` to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* RFC 4585, section 6.3.1: Definition of "PLI messages" in the document *Extended
RTP Profile for Real-time Transport Control Protocol (RTCP)-Based Feedback
(RTP/AVPF)*.
RTCRtpStreamStats: transportId property
=======================================

 The `RTCRtpStreamStats` dictionary's
 **`transportId`** property is a string which uniquely
 identifies the object from which the statistics contained in the
 `RTCTransportStats` properties in the
 `RTCStatsReport`.

Value
-----

 A string uniquely identifying the source of the statistics contained
 the `RTCTransportStats` properties in the `RTCStatsReport`.

Specifications
--------------

#### No specification found

No specification data found for `api.RTCRtpStreamStats.transportId`.  
Check for problems with this page or contribute a missing `spec_url` to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
RTCRtpStreamStats: firCount property
====================================

 The **`firCount`** property of the
 `RTCRtpStreamStats` dictionary indicates the number of **Full Intra
Request** (**FIR**) packets have been sent by the receiver to
 the sender.

 This is a measure of how often the stream falls behind and has to
 skip frames in order to catch up.

Value
-----

 An integer value indicating how many FIR packets have been received by the sender
 during the current connection. This value is available only on receivers for video
 tracks.

 The receiver sends a FIR packet to the sender any time it falls behind or loses packets
 and cannot decode the incoming stream any longer because of the lost data. This tells
 the sender to send a full frame instead of a delta frame, so that the receiver can catch
 up.

 The higher `firCount` is, the more often frames were dropped, which may be
 an indication that the media's bit rate is too high for the available bandwidth, or that
 the receiving device is overburdened and is therefore unable to process the incoming
 data.

Specifications
--------------

#### No specification found

No specification data found for `api.RTCRtpStreamStats.firCount`.  
Check for problems with this page or contribute a missing `spec_url` to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
XPathEvaluator: evaluate() method
=================================

 The `evaluate()` method of the `XPathEvaluator` interface
 executes an XPath expression on the given node or document and returns an
 `XPathResult`.

Syntax
------


```js
evaluate(expression, contextNode)
evaluate(expression, contextNode, resolver)
evaluate(expression, contextNode, resolver, type)
evaluate(expression, contextNode, resolver, type, result)
```

### Parameters

`expression`

 A string representing the XPath expression to be parsed and
 evaluated.


`contextNode`

A `Node` representing the context to use for evaluating the expression.

`resolver` Optional

 Permits translation of all prefixes, including the `xml` namespace
 prefix, within the XPath expression into appropriate namespace URIs.


`type` Optional

 Specifies the type of result to be returned by evaluating the expression. This must
 be one of the `XPathResult.Constants`.


`result` Optional

 Allows to specify a result object which may be reused and returned by this method.
 If this is specified as `null` or the implementation does not reuse the
 specified result, a new result object will be returned.


### Return value

 An `XPathResult` object representing the result of evaluating the XPath
 expression.

### Exceptions

#### INVALID\_EXPRESSION\_ERR

 If the expression is not legal according to the rules of the
 `XPathEvaluator`, an `XPathException` of type
 `INVALID_EXPRESSION_ERR` is raised.

#### TYPE\_ERR

 In case result cannot be converted to the specified type, an
 `XPathException` of type `TYPE_ERR` is raised.

#### NAMESPACE\_ERR

 If the expression contains namespace prefixes which cannot be resolved by the specified
 `XPathNSResolver`, a `DOMException` of type
 `NAMESPACE_ERROR` is raised.

#### WRONG\_DOCUMENT\_ERR

 If the provided context node is from a document that is not supported by the
 `XPathEvaluator`, a `DOMException` of type
 `WRONG_DOCUMENT_ERR` is raised.

#### NOT\_SUPPORTED\_ERR

 If the provided context node is not a type permitted as an XPath context node or the
 request type is not permitted by the `XPathEvaluator`, a
 `DOMException` of type `NOT_SUPPORTED_ERR` is raised.

Examples
--------

The following example shows the use of the `evaluate()` method.

### HTML


```html
<div>XPath example</div>
<div>Number of &lt;div&gt;s: <output></output></div>
```

### JavaScript


```js
const evaluator = new XPathEvaluator();
const result = evaluator.evaluate(
  "//div",
  document,
  null,
  XPathResult.ORDERED\_NODE\_SNAPSHOT\_TYPE,
);
document.querySelector("output").textContent = result.snapshotLength;
```

### Result

Specifications
--------------

| Specification |
| --- |
| DOM Standard # dom-xpathevaluatorbase-evaluate |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.