diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index d3c2e9fbe..9869cd768 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -3672,11 +3672,18 @@ declare var ClipboardEvent: { /** A CloseEvent is sent to clients using WebSockets when the connection is closed. This is delivered to the listener indicated by the WebSocket object's onclose attribute. */ interface CloseEvent extends Event { + /** + * Returns the WebSocket connection close code provided by the server. + */ readonly code: number; + /** + * Returns the WebSocket connection close reason provided by the server. + */ readonly reason: string; + /** + * Returns true if the connection closed cleanly; false otherwise. + */ readonly wasClean: boolean; - /** @deprecated */ - initCloseEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, wasCleanArg: boolean, codeArg: number, reasonArg: string): void; } declare var CloseEvent: { @@ -18381,17 +18388,45 @@ interface WebSocketEventMap { /** Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. */ 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". + */ 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.) + */ readonly bufferedAmount: number; + /** + * Returns the extensions selected by the server, if any. + */ readonly extensions: string; onclose: ((this: WebSocket, ev: CloseEvent) => any) | null; onerror: ((this: WebSocket, ev: Event) => any) | null; onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null; onopen: ((this: WebSocket, ev: Event) => any) | null; + /** + * Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation. + */ readonly protocol: string; + /** + * Returns the state of the WebSocket object's connection. It can have the values described below. + */ readonly readyState: number; + /** + * Returns the URL that was used to establish the WebSocket connection. + */ readonly url: string; + /** + * Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason. + */ close(code?: number, reason?: string): void; + /** + * Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView. + */ send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void; readonly CLOSED: number; readonly CLOSING: number; diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index c0b1c51b4..8f1f9071a 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -896,11 +896,18 @@ declare var Clients: { /** A CloseEvent is sent to clients using WebSockets when the connection is closed. This is delivered to the listener indicated by the WebSocket object's onclose attribute. */ interface CloseEvent extends Event { + /** + * Returns the WebSocket connection close code provided by the server. + */ readonly code: number; + /** + * Returns the WebSocket connection close reason provided by the server. + */ readonly reason: string; + /** + * Returns true if the connection closed cleanly; false otherwise. + */ readonly wasClean: boolean; - /** @deprecated */ - initCloseEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, wasCleanArg: boolean, codeArg: number, reasonArg: string): void; } declare var CloseEvent: { @@ -5276,17 +5283,45 @@ interface WebSocketEventMap { /** Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. */ 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". + */ 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.) + */ readonly bufferedAmount: number; + /** + * Returns the extensions selected by the server, if any. + */ readonly extensions: string; onclose: ((this: WebSocket, ev: CloseEvent) => any) | null; onerror: ((this: WebSocket, ev: Event) => any) | null; onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null; onopen: ((this: WebSocket, ev: Event) => any) | null; + /** + * Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation. + */ readonly protocol: string; + /** + * Returns the state of the WebSocket object's connection. It can have the values described below. + */ readonly readyState: number; + /** + * Returns the URL that was used to establish the WebSocket connection. + */ readonly url: string; + /** + * Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason. + */ close(code?: number, reason?: string): void; + /** + * Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView. + */ send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void; readonly CLOSED: number; readonly CLOSING: number; diff --git a/inputfiles/addedTypes.json b/inputfiles/addedTypes.json index 9ac2f163e..cfad7b550 100644 --- a/inputfiles/addedTypes.json +++ b/inputfiles/addedTypes.json @@ -2203,6 +2203,20 @@ } ] } + }, + "WebSocket": { + "events": { + "event": [ + { + "name": "close", + "type": "CloseEvent" + }, + { + "name": "error", + "type": "Event" + } + ] + } } } }, diff --git a/inputfiles/idl/HTML - Web sockets.commentmap.json b/inputfiles/idl/HTML - Web sockets.commentmap.json new file mode 100644 index 000000000..64db3afc4 --- /dev/null +++ b/inputfiles/idl/HTML - Web sockets.commentmap.json @@ -0,0 +1,16 @@ +{ + "websocket": "Creates a new WebSocket object, immediately establishing the associated WebSocket connection.\n\nurl is a string giving the URL over which the connection is established. Only \"ws\" or \"wss\" schemes are allowed; others will cause a \"SyntaxError\" DOMException. URLs with fragments will also cause such an exception.\n\nprotocols is either a string or an array of strings. If it is a string, it is equivalent to an array consisting of just that string; if it is omitted, it is equivalent to the empty array. Each string in the array is a subprotocol name. The connection will only be established if the server reports that it has selected one of these subprotocols. The subprotocol names have to match the requirements for elements that comprise the value of Sec-WebSocket-Protocol fields as defined by The WebSocket protocol. [WSP]", + "websocket-send": "Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.", + "websocket-close": "Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.", + "websocket-url": "Returns the URL that was used to establish the WebSocket connection.", + "websocket-readystate": "Returns the state of the WebSocket object's connection. It can have the values described below.", + "websocket-bufferedamount": "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.\n\nIf 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.)", + "websocket-extensions": "Returns the extensions selected by the server, if any.", + "websocket-protocol": "Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation.", + "websocket-binarytype": "Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:\n\nCan be set, to change how binary data is returned. The default is \"blob\".", + "closeevent-wasclean": "Returns true if the connection closed cleanly; false otherwise.", + "closeevent-code": "Returns the WebSocket connection close code provided by the server.", + "closeevent-reason": "Returns the WebSocket connection close reason provided by the server.", + "binarytype-blob": "Binary data is returned in Blob form.", + "binarytype-arraybuffer": "Binary data is returned in ArrayBuffer form." +} diff --git a/inputfiles/idl/HTML - Web sockets.widl b/inputfiles/idl/HTML - Web sockets.widl new file mode 100644 index 000000000..c629ce1f1 --- /dev/null +++ b/inputfiles/idl/HTML - Web sockets.widl @@ -0,0 +1,46 @@ +enum BinaryType { "blob", "arraybuffer" }; +[Exposed=(Window,Worker)] +interface WebSocket : EventTarget { + constructor(USVString url, optional (DOMString or sequence) protocols = []); + + readonly attribute USVString url; + + // ready state + const unsigned short CONNECTING = 0; + const unsigned short OPEN = 1; + const unsigned short CLOSING = 2; + const unsigned short CLOSED = 3; + readonly attribute unsigned short readyState; + readonly attribute unsigned long long bufferedAmount; + + // networking + attribute EventHandler onopen; + attribute EventHandler onerror; + attribute EventHandler onclose; + readonly attribute DOMString extensions; + readonly attribute DOMString protocol; + void close(optional [Clamp] unsigned short code, optional USVString reason); + + // messaging + attribute EventHandler onmessage; + attribute BinaryType binaryType; + void send(USVString data); + void send(Blob data); + void send(ArrayBuffer data); + void send(ArrayBufferView data); +}; + +[Exposed=(Window,Worker)] +interface CloseEvent : Event { + constructor(DOMString type, optional CloseEventInit eventInitDict = {}); + + readonly attribute boolean wasClean; + readonly attribute unsigned short code; + readonly attribute USVString reason; +}; + +dictionary CloseEventInit : EventInit { + boolean wasClean = false; + unsigned short code = 0; + USVString reason = ""; +}; diff --git a/inputfiles/idlSources.json b/inputfiles/idlSources.json index 95b13f806..e754e0ce8 100644 --- a/inputfiles/idlSources.json +++ b/inputfiles/idlSources.json @@ -322,6 +322,10 @@ "url": "https://html.spec.whatwg.org/multipage/webappapis.html", "title": "HTML - Web application APIs" }, + { + "url": "https://html.spec.whatwg.org/multipage/web-sockets.html", + "title": "HTML - Web sockets" + }, { "url": "https://html.spec.whatwg.org/multipage/webstorage.html", "title": "HTML - Web storage"