summaryrefslogtreecommitdiff
path: root/deps/undici/src/docs/api/WebSocket.md
diff options
context:
space:
mode:
Diffstat (limited to 'deps/undici/src/docs/api/WebSocket.md')
-rw-r--r--deps/undici/src/docs/api/WebSocket.md29
1 files changed, 26 insertions, 3 deletions
diff --git a/deps/undici/src/docs/api/WebSocket.md b/deps/undici/src/docs/api/WebSocket.md
index 639a5333a1..9d374f4046 100644
--- a/deps/undici/src/docs/api/WebSocket.md
+++ b/deps/undici/src/docs/api/WebSocket.md
@@ -1,17 +1,40 @@
# Class: WebSocket
-> ⚠️ Warning: the WebSocket API is experimental and has known bugs.
+> ⚠️ Warning: the WebSocket API is experimental.
Extends: [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
-The WebSocket object provides a way to manage a WebSocket connection to a server, allowing bidirectional communication. The API follows the [WebSocket spec](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket).
+The WebSocket object provides a way to manage a WebSocket connection to a server, allowing bidirectional communication. The API follows the [WebSocket spec](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) and [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455).
## `new WebSocket(url[, protocol])`
Arguments:
* **url** `URL | string` - The url's protocol *must* be `ws` or `wss`.
-* **protocol** `string | string[]` (optional) - Subprotocol(s) to request the server use.
+* **protocol** `string | string[] | WebSocketInit` (optional) - Subprotocol(s) to request the server use, or a [`Dispatcher`](./Dispatcher.md).
+
+### Example:
+
+This example will not work in browsers or other platforms that don't allow passing an object.
+
+```mjs
+import { WebSocket, ProxyAgent } from 'undici'
+
+const proxyAgent = new ProxyAgent('my.proxy.server')
+
+const ws = new WebSocket('wss://echo.websocket.events', {
+ dispatcher: proxyAgent,
+ protocols: ['echo', 'chat']
+})
+```
+
+If you do not need a custom Dispatcher, it's recommended to use the following pattern:
+
+```mjs
+import { WebSocket } from 'undici'
+
+const ws = new WebSocket('wss://echo.websocket.events', ['echo', 'chat'])
+```
## Read More