docs: adding examples and a see link to Websockets jdocs (#27957)

adding examples to websockets interfaces and a see link

---------

Co-authored-by: Phil Hawksworth <phil@deno.com>
This commit is contained in:
Jo Franchetti 2025-02-11 14:35:15 +00:00 committed by GitHub
parent b9183c737f
commit 07410d19cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

@ -1 +1 @@
Subproject commit af4c6a1eee825f19d3b3cce74cfdd03ebe1a3b92
Subproject commit a7874340aaeb06b31780d7497edf7eee51e08efc

View file

@ -49,6 +49,8 @@ interface WebSocketEventMap {
* If you are looking to create a WebSocket server, please take a look at
* `Deno.upgradeWebSocket()`.
*
* @see https://developer.mozilla.org/docs/Web/API/WebSocket
*
* @tags allow-net
* @category WebSockets
*/
@ -57,16 +59,44 @@ interface WebSocket extends EventTarget {
* Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:
*
* Can be set, to change how binary data is returned. The default is "blob".
*
* ```ts
* const ws = new WebSocket("ws://localhost:8080");
* ws.binaryType = "arraybuffer";
* ```
*/
binaryType: BinaryType;
/**
* Returns the number of bytes of application data (UTF-8 text and binary data) that have been queued using send() but not yet been transmitted to the network.
*
* If the WebSocket connection is closed, this attribute's value will only increase with each call to the send() method. (The number does not reset to zero once the connection closes.)
*
* ```ts
* const ws = new WebSocket("ws://localhost:8080");
* ws.send("Hello, world!");
* console.log(ws.bufferedAmount); // 13
* ```
*/
readonly bufferedAmount: number;
/**
* Returns the extensions selected by the server, if any.
*
* WebSocket extensions add optional features negotiated during the handshake via
* the `Sec-WebSocket-Extensions` header.
*
* At the time of writing, there are two registered extensions:
*
* - [`permessage-deflate`](https://www.rfc-editor.org/rfc/rfc7692.html): Enables per-message compression using DEFLATE.
* - [`bbf-usp-protocol`](https://usp.technology/): Used by the Broadband Forum's User Services Platform (USP).
*
* See the full list at [IANA WebSocket Extensions](https://www.iana.org/assignments/websocket/websocket.xml#extension-name).
*
* Example:
*
* ```ts
* const ws = new WebSocket("ws://localhost:8080");
* console.log(ws.extensions); // e.g., "permessage-deflate"
* ```
*/
readonly extensions: string;
onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;