- Notifications
You must be signed in to change notification settings - Fork18
The WebSocketStream Interface#48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
579e4133c4803b8e5f06b5cb355b1f9a2d696baeed69bae4ffa5ff83adf4bbef488ee4b1a58f48cc184c781216347ab0da2b9ee8012ff404a2fc7c23a285c7397dd009e8d8f7673ace930f5f8b7d857721d7d8687b81f796da74e716a75fe2bd7ad5b2e001c1e2eae924f24f8a6d426fd5570f3File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -795,6 +795,128 @@ the following list: | ||
| </div> | ||
ricea marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| # The {{WebSocketStream}} interface # {#the-websocketstream-interface} | ||
| The Web IDL definition for the {{WebSocketStream}} class is given as follows: | ||
| <xmp class="idl"> | ||
| dictionary WebSocketOpenInfo { | ||
| ReadableStream readable; | ||
| WritableStream writable; | ||
| DOMString extensions; | ||
| DOMString protocol; | ||
| }; | ||
| dictionary WebSocketCloseInfo { | ||
| [Clamp] unsigned short code; | ||
| USVString reason = ""; | ||
| }; | ||
| dictionary WebSocketStreamOptions { | ||
| sequence<USVString> protocols; | ||
| AbortSignal signal; | ||
| }; | ||
| [ | ||
| Exposed=(Window,Worker) | ||
| ] interface WebSocketStream { | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| constructor(USVString url, optional WebSocketStreamOptions options); | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| readonly attribute USVString url; | ||
| readonly attribute Promise<WebSocketOpenInfo> opened; | ||
| readonly attribute Promise<WebSocketCloseInfo> closed; | ||
| undefined close(optional WebSocketCloseInfo closeInfo); | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| }; | ||
| </xmp> | ||
| A {{WebSocketStream}} object has an associated <dfn>url</dfn> (a [=URL record=]). | ||
| A {{WebSocketStream}} object has an associated <dfn>opened promise</dfn>. | ||
| A {{WebSocketStream}} object has an associated <dfn>closed promise</dfn>. | ||
| A {{WebSocketStream}} object has an associated <dfn>was ever connected flag</dfn>, which is | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| initially unset. | ||
| <dl class="domintro non-normative"> | ||
| : <code>|socket| = new {{WebSocketStream/constructor(url, options)|WebSocketStream}}(|url| [, |options| ]</code> | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| :: Creates a new {{WebSocketStream}} object, immediately establishing the associating WebSocket | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| connection. | ||
| |url| is a string giving the <a dfn spec=url>URL</a> 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. | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| The |options| argument is an object whose properties can be set as follows: | ||
| : {{WebSocketStreamOptions/protocols}} | ||
| :: An array of strings. If it is omitted, it is equivalent to an 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 \`<a http-header>`Sec-WebSocket-Protocol`</a>\` fields as | ||
| defined by The WebSocket protocol. [[!WSP]] | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| : {{WebSocketStreamOptions/signal}} | ||
| :: An {{AbortSignal}} that can be used to abort the handshake. After the handshake is complete the | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| signal does nothing. | ||
| : <code>|socket| . {{WebSocketStream/url}}</code> | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| :: Returns the <a lt="url">URL that was used</a> to establish the WebSocket connection. | ||
| : <code>|socket| . {{WebSocketStream/opened}}</code> | ||
| :: Returns a {{promise}} which resolves when the handshake successfully completes, or rejects if | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| the handshake fails. On success, it resolves to an object with the following properties: | ||
| : {{WebSocketOpenInfo/readable}} | ||
| :: A {{ReadableStream}} that can be used to read messages from the server. Each chunk read | ||
| corresponds to one message. Text messages will be read as strings; binary messages will be read | ||
| as ArrayBuffer objects. | ||
domenic marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| The stream can be closed by calling {{ReadableStream/cancel()}} on | ||
| {{WebSocketOpenInfo/readable}}. If the argument passed to {{ReadableStream/cancel()}} is an | ||
| object with a {{WebSocketCloseInfo/code}} property and an <span class=allow-2119>optional</span> {{WebSocketCloseInfo/reason}} | ||
| property then {{WebSocketCloseInfo/code}} will be used as [=the WebSocket connection close | ||
| code=] and {{WebSocketCloseInfo/reason}} or the empty string will be used as [=the WebSocket | ||
| connection close reason=]. | ||
| If no messages are read, or if messages are read slower than they are sent, then backpressure | ||
ricea marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| will be applied and eventually the server will stop sending new messages. | ||
| : {{WebSocketOpenInfo/writable}} | ||
| :: A {{WritableStream}} that can be used to send messages to the server. Each chunk written will | ||
| be converted to one messages. Strings will be sent as text messages; {{BufferSource}} chunks will | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| be sent as binary messages. | ||
| The WebSocket can be closed by calling {{WritableStream/close()}} on | ||
| {{WebSocketOpenInfo/writable}}. | ||
| The stream can also be closed by calling {{WritableStream/abort()}} | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| {{WebSocketOpenInfo/writable}}. If an argument is passed to {{WritableStream/abort()}} then it | ||
| can be used to specify [=the WebSocket connection close code=] and [=the WebSocket connection | ||
| close reason=] as with {{ReadableStream/cancel()}} above. | ||
| : {{WebSocketOpenInfo/extensions}} | ||
| :: The [=extensions in use=] for the connection. | ||
| : {{WebSocketOpenInfo/protocol}} | ||
| :: The [=subprotocol in use=] for the connection. | ||
| : <code>|socket| . {{WebSocketStream/closed}}</code> | ||
| :: A {{promise}} which resolves when the connection is closed. If the connection did not close | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| [=cleanly=] then the promise is rejected. When the connection closes [=cleanly=] the promise is | ||
| resolved with an object with properties {{WebSocketCloseInfo/code}} and | ||
| {{WebSocketCloseInfo/reason}}, giving [=the WebSocket connection close code=] and [=the WebSocket | ||
| connection close reason=] the were supplied by the server. | ||
ricea marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| : <code>|socket| . {{WebSocketStream/close()}}</code> | ||
| :: Close the connection, optionally supplying an object with {{WebSocketCloseInfo/code}} and | ||
| {{WebSocketCloseInfo/reason}} properties to indicate [=the WebSocket connection close code=] and | ||
| [=the WebSocket connection close reason=] that will be sent to the remote server. If the handshake | ||
| is still in progress then it will be aborted and {{WebSocketCloseInfo/code}} and | ||
| {{WebSocketCloseInfo/reason}} will be ignored. | ||
| </dl> | ||
| <h2 id="acks" class="no-num">Acknowledgments</h2> | ||
| Until the creation of this standard in 2021, the text here was maintained in the <a | ||