{
  "type": "module",
  "source": "doc/api/api-websocket.md",
  "modules": [
    {
      "textRaw": "WebSocket",
      "name": "websocket",
      "introduced_in": "v5.15.0",
      "type": "module",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>The <code>WebSocket</code> API provides a way to manage a WebSocket connection to a\nserver, allowing bidirectional communication. It follows the\n<a href=\"https://websockets.spec.whatwg.org/\">WHATWG WebSocket specification</a> and <a href=\"https://www.rfc-editor.org/rfc/rfc6455\">RFC 6455</a>, and is intended to be\ninterchangeable with the global <code>WebSocket</code> available in browsers.</p>\n<pre><code class=\"language-mjs\">import { WebSocket } from 'undici'\n\nconst ws = new WebSocket('wss://echo.websocket.events')\n\nws.addEventListener('open', () => {\n  ws.send('Hello, world!')\n})\n\nws.addEventListener('message', (event) => {\n  console.log('received:', event.data)\n})\n</code></pre>\n<p>In addition to the standard <code>WebSocket</code> interface, this module exports the\nstreams-based <a href=\"#class-websocketstream\"><code>WebSocketStream</code></a> and <a href=\"#class-websocketerror\"><code>WebSocketError</code></a> APIs, as well as a\n<a href=\"#pingwebsocket-payload\"><code>ping()</code></a> helper for sending ping frames.</p>",
      "classes": [
        {
          "textRaw": "Class: `WebSocket`",
          "name": "WebSocket",
          "type": "class",
          "meta": {
            "added": [
              "v5.15.0"
            ],
            "changes": []
          },
          "desc": "<ul>\n<li>Extends: <a href=\"https://developer.mozilla.org/docs/Web/API/EventTarget\"><code>&#x3C;EventTarget></code></a></li>\n</ul>\n<p>The <code>WebSocket</code> object represents a single WebSocket connection. Constructing a\n<code>WebSocket</code> immediately begins the opening handshake; the connection cannot be\nreused once it has been closed.</p>",
          "signatures": [
            {
              "textRaw": "`new WebSocket(url[, protocols])`",
              "name": "WebSocket",
              "type": "ctor",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "params": [
                {
                  "textRaw": "`url` {URL|string} The URL of the server to connect to. Must use the `ws:` or `wss:` scheme.",
                  "name": "url",
                  "type": "URL|string",
                  "desc": "The URL of the server to connect to. Must use the `ws:` or `wss:` scheme."
                },
                {
                  "textRaw": "`protocols` {string|string}[] | {WebSocketInit} A single subprotocol, a list of subprotocols to negotiate with the server, or a `WebSocketInit` object. **Default:** `[]`.",
                  "name": "protocols",
                  "type": "string|string",
                  "default": "`[]`",
                  "desc": "[] | {WebSocketInit} A single subprotocol, a list of subprotocols to negotiate with the server, or a `WebSocketInit` object.",
                  "options": [
                    {
                      "textRaw": "`protocols` {string|string}[] Subprotocol(s) to request the server use. **Default:** `[]`.",
                      "name": "protocols",
                      "type": "string|string",
                      "default": "`[]`",
                      "desc": "[] Subprotocol(s) to request the server use."
                    },
                    {
                      "textRaw": "`dispatcher` {Dispatcher} The dispatcher used to open the connection. **Default:** the global dispatcher.",
                      "name": "dispatcher",
                      "type": "Dispatcher",
                      "default": "the global dispatcher",
                      "desc": "The dispatcher used to open the connection."
                    },
                    {
                      "textRaw": "`headers` {HeadersInit|null} Additional headers to send with the handshake request. (optional)",
                      "name": "headers",
                      "type": "HeadersInit|null",
                      "desc": "Additional headers to send with the handshake request. (optional)"
                    }
                  ],
                  "optional": true
                }
              ],
              "desc": "<p>Creates a new <code>WebSocket</code> and begins connecting to <code>url</code>. The second argument\nmay be a string or array of subprotocols, or a <code>WebSocketInit</code> object. The\nobject form is an undici extension and is not available in browsers; it allows a\ncustom <code>dispatcher</code> and additional <code>headers</code> to be supplied.</p>\n<p>If a value in <code>protocols</code> is repeated or is not a valid subprotocol name, the\nconstructor throws a <code>SyntaxError</code> <code>DOMException</code>.</p>\n<pre><code class=\"language-mjs\">import { WebSocket } from 'undici'\n\nconst ws = new WebSocket('wss://echo.websocket.events', ['echo', 'chat'])\n</code></pre>\n<p>To route the connection through a custom dispatcher, such as a\n<a href=\"ProxyAgent.html#class-proxyagent\"><code>ProxyAgent</code></a>, pass a <code>WebSocketInit</code> object:</p>\n<pre><code class=\"language-mjs\">import { WebSocket, ProxyAgent } from 'undici'\n\nconst dispatcher = new ProxyAgent('http://localhost:8080')\n\nconst ws = new WebSocket('wss://echo.websocket.events', {\n  dispatcher,\n  protocols: ['echo', 'chat']\n})\n</code></pre>\n<p>WebSocket over HTTP/2 is experimental and may change in the future. It can be\nenabled by passing a dispatcher configured with <code>allowH2</code>:</p>\n<pre><code class=\"language-mjs\">import { WebSocket, Agent } from 'undici'\n\nconst dispatcher = new Agent({ allowH2: true })\n\nconst ws = new WebSocket('wss://echo.websocket.events', {\n  dispatcher,\n  protocols: ['echo', 'chat']\n})\n</code></pre>"
            }
          ],
          "methods": [
            {
              "textRaw": "`websocket.close([code[, reason]])`",
              "name": "close",
              "type": "method",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`code` {number} The status code explaining why the connection is being closed. **Default:** `null`.",
                      "name": "code",
                      "type": "number",
                      "default": "`null`",
                      "desc": "The status code explaining why the connection is being closed.",
                      "optional": true
                    },
                    {
                      "textRaw": "`reason` {string} A human-readable string explaining why the connection is being closed. **Default:** `''`.",
                      "name": "reason",
                      "type": "string",
                      "default": "`''`",
                      "desc": "A human-readable string explaining why the connection is being closed.",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>Starts the closing handshake. The <code>code</code> is clamped to an unsigned 16-bit\ninteger; when omitted, no status code is sent. The <code>reason</code> is encoded as\nUTF-8 and must not exceed 123 bytes.</p>\n<pre><code class=\"language-mjs\">ws.close(1000, 'Done')\n</code></pre>"
            },
            {
              "textRaw": "`websocket.send(data)`",
              "name": "send",
              "type": "method",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`data` {string|ArrayBuffer|TypedArray|DataView|Blob} The data to enqueue for transmission.",
                      "name": "data",
                      "type": "string|ArrayBuffer|TypedArray|DataView|Blob",
                      "desc": "The data to enqueue for transmission."
                    }
                  ]
                }
              ],
              "desc": "<p>Enqueues <code>data</code> to be transmitted to the server. String data is sent as a text\nframe; <code>ArrayBuffer</code>, any <code>TypedArray</code>, <code>DataView</code>, and <code>Blob</code> values are sent\nas binary frames. The number of bytes queued is added to\n<a href=\"#websocketbufferedamount\"><code>websocket.bufferedAmount</code></a>.</p>\n<p>If <a href=\"#websocketreadystate\"><code>websocket.readyState</code></a> is <code>CONNECTING</code>, an <code>InvalidStateError</code>\n<code>DOMException</code> is thrown. If the connection is closing or already closed, the\ncall is silently ignored.</p>\n<pre><code class=\"language-mjs\">ws.send('a text message')\nws.send(new Uint8Array([1, 2, 3]))\n</code></pre>"
            }
          ],
          "properties": [
            {
              "textRaw": "Type: {number}",
              "name": "readyState",
              "type": "number",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "desc": "<p>The current state of the connection. One of the numeric constants\n<code>WebSocket.CONNECTING</code> (<code>0</code>), <code>WebSocket.OPEN</code> (<code>1</code>),\n<code>WebSocket.CLOSING</code> (<code>2</code>), or <code>WebSocket.CLOSED</code> (<code>3</code>). This property is\nread-only.</p>"
            },
            {
              "textRaw": "Type: {number}",
              "name": "bufferedAmount",
              "type": "number",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "desc": "<p>The number of bytes of data that have been queued using\n<a href=\"#websocketsenddata\"><code>websocket.send()</code></a> but not yet transmitted to the network. This value\nresets to <code>0</code> once all queued data is sent. This property is read-only.</p>"
            },
            {
              "textRaw": "Type: {string}",
              "name": "url",
              "type": "string",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "desc": "<p>The absolute URL of the WebSocket as resolved during construction. This\nproperty is read-only.</p>"
            },
            {
              "textRaw": "Type: {string}",
              "name": "extensions",
              "type": "string",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "desc": "<p>The extensions negotiated by the server, taken from the\n<code>Sec-WebSocket-Extensions</code> response header. Empty until the connection is\nestablished. This property is read-only.</p>"
            },
            {
              "textRaw": "Type: {string}",
              "name": "protocol",
              "type": "string",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "desc": "<p>The subprotocol selected by the server, taken from the\n<code>Sec-WebSocket-Protocol</code> response header. Empty until the connection is\nestablished and only set when a subprotocol was negotiated. This property is\nread-only.</p>"
            },
            {
              "textRaw": "Type: {string} **Default:** `'blob'`.",
              "name": "binaryType",
              "type": "string",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "default": "`'blob'`",
              "desc": "<p>Controls the type used to represent binary data delivered by the\n<a href=\"#event-message\"><code>'message'</code></a> event. Must be either <code>'blob'</code> (binary frames are exposed as a\n<code>Blob</code>) or <code>'arraybuffer'</code> (binary frames are exposed as an <code>ArrayBuffer</code>).\nAssigning any other value resets it to <code>'blob'</code>.</p>"
            },
            {
              "textRaw": "Type: {Function|null} **Default:** `null`.",
              "name": "onopen",
              "type": "Function|null",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "default": "`null`",
              "desc": "<p>An event handler for the <a href=\"#event-open\"><code>'open'</code></a> event. Setting this property replaces any\npreviously registered <code>onopen</code> handler.</p>"
            },
            {
              "textRaw": "Type: {Function|null} **Default:** `null`.",
              "name": "onerror",
              "type": "Function|null",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "default": "`null`",
              "desc": "<p>An event handler for the <a href=\"#event-error\"><code>'error'</code></a> event. Setting this property replaces any\npreviously registered <code>onerror</code> handler.</p>"
            },
            {
              "textRaw": "Type: {Function|null} **Default:** `null`.",
              "name": "onclose",
              "type": "Function|null",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "default": "`null`",
              "desc": "<p>An event handler for the <a href=\"#event-close\"><code>'close'</code></a> event. Setting this property replaces any\npreviously registered <code>onclose</code> handler.</p>"
            },
            {
              "textRaw": "Type: {Function|null} **Default:** `null`.",
              "name": "onmessage",
              "type": "Function|null",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "default": "`null`",
              "desc": "<p>An event handler for the <a href=\"#event-message\"><code>'message'</code></a> event. Setting this property replaces\nany previously registered <code>onmessage</code> handler.</p>"
            }
          ],
          "events": [
            {
              "textRaw": "Event: `'open'`",
              "name": "open",
              "type": "event",
              "meta": {
                "added": [
                  "v5.21.0"
                ],
                "changes": []
              },
              "params": [],
              "desc": "<p>Emitted when the WebSocket connection is established. After this event,\n<a href=\"#websocketreadystate\"><code>websocket.readyState</code></a> is <code>OPEN</code> and data may be sent with\n<a href=\"#websocketsenddata\"><code>websocket.send()</code></a>. The listener receives an <code>Event</code>.</p>"
            },
            {
              "textRaw": "Event: `'message'`",
              "name": "message",
              "type": "event",
              "meta": {
                "added": [
                  "v7.0.0"
                ],
                "changes": []
              },
              "params": [],
              "desc": "<p>Emitted when a message is received from the server. The listener receives a\n<code>MessageEvent</code> whose <code>data</code> property is a <code>string</code> for text frames, and either a\n<code>Blob</code> or an <code>ArrayBuffer</code> for binary frames depending on\n<a href=\"#websocketbinarytype\"><code>websocket.binaryType</code></a>. The event's <code>origin</code> is the origin of\n<a href=\"#websocketurl\"><code>websocket.url</code></a>.</p>"
            },
            {
              "textRaw": "Event: `'error'`",
              "name": "error",
              "type": "event",
              "meta": {
                "added": [
                  "v7.0.0"
                ],
                "changes": []
              },
              "params": [],
              "desc": "<p>Emitted when the connection is terminated abnormally, for example when no close\nframe was received before the underlying transport was lost. The listener\nreceives an <code>ErrorEvent</code>.</p>"
            },
            {
              "textRaw": "Event: `'close'`",
              "name": "close",
              "type": "event",
              "meta": {
                "added": [
                  "v7.0.0"
                ],
                "changes": []
              },
              "params": [],
              "desc": "<p>Emitted when the connection is closed. The listener receives a <code>CloseEvent</code>\nwhose <code>code</code> and <code>reason</code> describe why the connection closed, and whose\n<code>wasClean</code> property is <code>true</code> only when the closing handshake completed in both\ndirections.</p>"
            }
          ]
        },
        {
          "textRaw": "Class: `WebSocketStream`",
          "name": "WebSocketStream",
          "type": "class",
          "meta": {
            "added": [
              "v7.0.0"
            ],
            "changes": []
          },
          "stability": 1,
          "stabilityText": "Experimental",
          "desc": "<p><code>WebSocketStream</code> is a streams-based alternative to the event-based\n<a href=\"#class-websocket\"><code>WebSocket</code></a> interface, exposing a connection as a pair of <code>ReadableStream</code>\nand <code>WritableStream</code> objects. See <a href=\"https://developer.mozilla.org/docs/Web/API/WebSocketStream\">MDN</a> for background.</p>\n<p>Constructing a <code>WebSocketStream</code> for the first time emits an\n<code>ExperimentalWarning</code> with the code <code>UNDICI-WSS</code>.</p>",
          "signatures": [
            {
              "textRaw": "`new WebSocketStream(url[, options])`",
              "name": "WebSocketStream",
              "type": "ctor",
              "meta": {
                "added": [
                  "v7.0.0"
                ],
                "changes": []
              },
              "stability": 1,
              "stabilityText": "Experimental",
              "params": [
                {
                  "textRaw": "`url` {URL|string} The URL of the server to connect to.",
                  "name": "url",
                  "type": "URL|string",
                  "desc": "The URL of the server to connect to."
                },
                {
                  "textRaw": "`options` {WebSocketStreamOptions}",
                  "name": "options",
                  "type": "WebSocketStreamOptions",
                  "options": [
                    {
                      "textRaw": "`protocols` {string|string}[] Subprotocol(s) to request the server use. **Default:** `[]`.",
                      "name": "protocols",
                      "type": "string|string",
                      "default": "`[]`",
                      "desc": "[] Subprotocol(s) to request the server use."
                    },
                    {
                      "textRaw": "`signal` {AbortSignal|null} An `AbortSignal` that aborts the opening handshake and rejects `webSocketStream.opened` and `webSocketStream.closed` when triggered. **Default:** `null`.",
                      "name": "signal",
                      "type": "AbortSignal|null",
                      "default": "`null`",
                      "desc": "An `AbortSignal` that aborts the opening handshake and rejects `webSocketStream.opened` and `webSocketStream.closed` when triggered."
                    }
                  ],
                  "optional": true
                }
              ],
              "desc": "<p>Creates a new <code>WebSocketStream</code> and begins connecting to <code>url</code>. As with\n<a href=\"#new-websocketurl-protocols\"><code>new WebSocket()</code></a>, a repeated or invalid subprotocol causes a <code>SyntaxError</code>\n<code>DOMException</code> to be thrown.</p>\n<pre><code class=\"language-mjs\">import { WebSocketStream } from 'undici'\n\nconst stream = new WebSocketStream('wss://echo.websocket.events')\nconst { readable, writable } = await stream.opened\n\nconst writer = writable.getWriter()\nawait writer.write('Hello, world!')\nwriter.releaseLock()\n\nconst reader = readable.getReader()\nconst { value } = await reader.read()\nconsole.log('received:', value)\n</code></pre>"
            }
          ],
          "properties": [
            {
              "textRaw": "Type: {string}",
              "name": "url",
              "type": "string",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "stability": 1,
              "stabilityText": "Experimental",
              "desc": "<p>The serialized URL of the WebSocket. This property is read-only.</p>"
            },
            {
              "textRaw": "Type: {Promise} Fulfills once the connection is established.",
              "name": "opened",
              "type": "Promise",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "stability": 1,
              "stabilityText": "Experimental",
              "desc": "<p>A promise that resolves with an object describing the open connection, or\nrejects if the connection could not be established. The fulfillment value has\nthe following shape:</p>\n<ul>\n<li><code>extensions</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The negotiated extensions.</li>\n<li><code>protocol</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The negotiated subprotocol.</li>\n<li><code>readable</code> <a href=\"https://developer.mozilla.org/docs/Web/API/ReadableStream\"><code>&#x3C;ReadableStream></code></a> A stream of incoming messages. Text frames are\ndelivered as strings and binary frames as <code>Uint8Array</code> chunks.</li>\n<li><code>writable</code> <a href=\"https://developer.mozilla.org/docs/Web/API/WritableStream\"><code>&#x3C;WritableStream></code></a> A stream for sending messages. Writing a string\nsends a text frame; writing a <code>BufferSource</code> sends a binary frame.</li>\n</ul>",
              "shortDesc": "Fulfills once the connection is established."
            },
            {
              "textRaw": "Type: {Promise} Fulfills once the connection is closed cleanly.",
              "name": "closed",
              "type": "Promise",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "stability": 1,
              "stabilityText": "Experimental",
              "desc": "<p>A promise that resolves with a <code>WebSocketCloseInfo</code> object when the connection\ncloses cleanly, or rejects with a <a href=\"#class-websocketerror\"><code>WebSocketError</code></a> when it closes\nabnormally. The fulfillment value has the following shape:</p>\n<ul>\n<li><code>closeCode</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The status code the connection was closed with.</li>\n<li><code>reason</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The reason the connection was closed with.</li>\n</ul>",
              "shortDesc": "Fulfills once the connection is closed cleanly."
            }
          ],
          "methods": [
            {
              "textRaw": "`webSocketStream.close([closeInfo])`",
              "name": "close",
              "type": "method",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "stability": 1,
              "stabilityText": "Experimental",
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`closeInfo` {Object}",
                      "name": "closeInfo",
                      "type": "Object",
                      "options": [
                        {
                          "textRaw": "`closeCode` {number} The status code to close with.",
                          "name": "closeCode",
                          "type": "number",
                          "desc": "The status code to close with."
                        },
                        {
                          "textRaw": "`reason` {string} The reason to close with. **Default:** `''`.",
                          "name": "reason",
                          "type": "string",
                          "default": "`''`",
                          "desc": "The reason to close with."
                        }
                      ],
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>Starts the closing handshake. When <code>closeInfo</code> is omitted, the connection is\nclosed without a status code.</p>"
            }
          ]
        },
        {
          "textRaw": "Class: `WebSocketError`",
          "name": "WebSocketError",
          "type": "class",
          "meta": {
            "added": [
              "v7.0.0"
            ],
            "changes": []
          },
          "stability": 1,
          "stabilityText": "Experimental",
          "desc": "<ul>\n<li>Extends: <a href=\"https://developer.mozilla.org/docs/Web/API/DOMException\"><code>&#x3C;DOMException></code></a></li>\n</ul>\n<p>An error type used by <a href=\"#class-websocketstream\"><code>WebSocketStream</code></a> to report close information. It is\nused to reject <a href=\"#websocketstreamclosed\"><code>webSocketStream.closed</code></a> when the connection closes\nabnormally, and may be passed to a stream's abort or cancel operations to close\nthe connection with a specific code and reason.</p>",
          "signatures": [
            {
              "textRaw": "`new WebSocketError([message[, init]])`",
              "name": "WebSocketError",
              "type": "ctor",
              "meta": {
                "added": [
                  "v7.0.0"
                ],
                "changes": []
              },
              "stability": 1,
              "stabilityText": "Experimental",
              "params": [
                {
                  "textRaw": "`message` {string} A human-readable description of the error. **Default:** `''`.",
                  "name": "message",
                  "type": "string",
                  "default": "`''`",
                  "desc": "A human-readable description of the error.",
                  "optional": true
                },
                {
                  "textRaw": "`init` {Object}",
                  "name": "init",
                  "type": "Object",
                  "options": [
                    {
                      "textRaw": "`closeCode` {number} The status code to associate with the error.",
                      "name": "closeCode",
                      "type": "number",
                      "desc": "The status code to associate with the error."
                    },
                    {
                      "textRaw": "`reason` {string} The reason to associate with the error. **Default:** `''`.",
                      "name": "reason",
                      "type": "string",
                      "default": "`''`",
                      "desc": "The reason to associate with the error."
                    }
                  ],
                  "optional": true
                }
              ],
              "desc": "<p>Creates a new <code>WebSocketError</code>. If <code>reason</code> is non-empty but no <code>closeCode</code> is\ngiven, <code>closeCode</code> defaults to <code>1000</code> (\"Normal Closure\"). The <code>closeCode</code> and\n<code>reason</code> are validated, so an out-of-range code or an over-long reason throws.</p>"
            }
          ],
          "properties": [
            {
              "textRaw": "Type: {number|null}",
              "name": "closeCode",
              "type": "number|null",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "stability": 1,
              "stabilityText": "Experimental",
              "desc": "<p>The status code associated with the error, or <code>null</code> if none was set. This\nproperty is read-only.</p>"
            },
            {
              "textRaw": "Type: {string}",
              "name": "reason",
              "type": "string",
              "meta": {
                "added": [
                  "v5.15.0"
                ],
                "changes": []
              },
              "stability": 1,
              "stabilityText": "Experimental",
              "desc": "<p>The reason associated with the error. This property is read-only.</p>"
            }
          ]
        }
      ],
      "methods": [
        {
          "textRaw": "`ping(websocket[, payload])`",
          "name": "ping",
          "type": "method",
          "meta": {
            "added": [
              "v7.12.0"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`websocket` {WebSocket} The WebSocket to send the ping frame on.",
                  "name": "websocket",
                  "type": "WebSocket",
                  "desc": "The WebSocket to send the ping frame on."
                },
                {
                  "textRaw": "`payload` {Buffer} Optional payload to include in the ping frame. Must not exceed 125 bytes. **Default:** `undefined`.",
                  "name": "payload",
                  "type": "Buffer",
                  "default": "`undefined`",
                  "desc": "Optional payload to include in the ping frame. Must not exceed 125 bytes.",
                  "optional": true
                }
              ]
            }
          ],
          "desc": "<p>Sends a ping control frame to the server. A conforming server replies with a\npong frame containing the same payload, which can be used to keep the connection\nalive or to verify that it is still active.</p>\n<p>The frame is only sent when the connection is open; if it is connecting,\nclosing, or closed, the call is a no-op. A <code>TypeError</code> is thrown if <code>payload</code>\nis not a <code>Buffer</code> or is larger than 125 bytes.</p>\n<pre><code class=\"language-mjs\">import { WebSocket, ping } from 'undici'\n\nconst ws = new WebSocket('wss://echo.websocket.events')\n\nws.addEventListener('open', () => {\n  ping(ws)\n  ping(ws, Buffer.from('hello'))\n})\n</code></pre>"
        }
      ],
      "modules": [
        {
          "textRaw": "Read more",
          "name": "read_more",
          "type": "module",
          "desc": "<ul>\n<li><a href=\"https://developer.mozilla.org/docs/Web/API/WebSocket\">MDN: WebSocket</a></li>\n<li><a href=\"https://www.rfc-editor.org/rfc/rfc6455\">RFC 6455</a></li>\n<li><a href=\"https://websockets.spec.whatwg.org/\">WHATWG WebSocket specification</a></li>\n</ul>",
          "displayName": "Read more"
        }
      ]
    }
  ]
}