- 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
Co-authored-by: Domenic Denicola <d@domenic.me>
- 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 |
|---|---|---|
| @@ -788,7 +788,7 @@ state=], but is not exposed to JavaScript. | ||
| <dl class="domintro non-normative"> | ||
| : <code>|socket| = new {{WebSocketStream/constructor(url, options)|WebSocketStream}}(|url|[, |options|])</code> | ||
| :: Creates a new {{WebSocketStream}} object, immediately establishing the associated WebSocket | ||
| connection. | ||
| @@ -813,7 +813,7 @@ state=], but is not exposed to JavaScript. | ||
| :: Returns the [=WebSocketStream/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 | ||
| the handshake fails. On success, it resolves to an object with the following properties: | ||
| : {{WebSocketOpenInfo/readable}} | ||
| @@ -823,7 +823,7 @@ state=], but is not exposed to JavaScript. | ||
| <p class=note>The original {{WebSocket}} API supplied {{ArrayBuffer}} objects, but modern | ||
| practice is to prefer the {{Uint8Array}} type for binary data, particularly when using streams. | ||
| The underlying {{ArrayBuffer}} object can be recovered byaccessing <code><var | ||
| ignore>chunk</var>.buffer</code>. | ||
| The stream can be closed by calling {{ReadableStream/cancel()}} on | ||
| @@ -858,14 +858,15 @@ state=], but is not exposed to JavaScript. | ||
| :: 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 | ||
| [=cleanly=] then the promise is rejected with a {{WebSocketError}}. When the connection closes | ||
| [=cleanly=] the promise is fulfilled with an object with properties | ||
| {{WebSocketCloseInfo/closeCode}} and {{WebSocketCloseInfo/reason}}, giving [=the WebSocket | ||
| connection close code=] and [=the WebSocket connection close reason=] that were supplied by the | ||
| server. | ||
| : <code>|socket|.{{WebSocketStream/close()}}</code> | ||
ricea marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| : <code>|socket|.{{WebSocketStream/close({ {{WebSocketCloseInfo/closeCode}}, {{WebSocketCloseInfo/reason}} })}}</code> | ||
| :: Close the connection, optionally supplying an object with {{WebSocketCloseInfo/closeCode}} 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 | ||
| @@ -943,12 +944,12 @@ object=] to run these steps: | ||
| <div algorithm="handle WebSocketStream connection establishment"> | ||
| 1. Change|stream|'s [=WebSocketStream/ready state=] to {{WebSocket/OPEN}} (1). | ||
| 1. Set |stream|'s [=WebSocketStream/was ever connected=] to true. | ||
| 1. Let |extensions| be the [=extensions in use=]. | ||
| 1. Let |protocol| be the [=subprotocol in use=]. | ||
| 1. Let |pullAlgorithm| be an action that [=pulls bytes=] from |stream|. | ||
| 1. Let |cancelAlgorithm| be an action that [=cancels=] |stream|with | ||
| |reason|, given |reason|. | ||
| 1. Let |readable| be a [=new=] {{ReadableStream}}. | ||
| 1. [=ReadableStream/Set up=] |readable| with |pullAlgorithm| and |cancelAlgorithm|. | ||
| @@ -975,7 +976,7 @@ When [=a WebSocket message has been received=] for a {{WebSocketStream}} |stream | ||
| and data |data|, the user agent must [=queue a global task=] on the [=WebSocket task source=] given | ||
| |stream|'s [=relevant global object=] to follow these steps: [[!WSP]] | ||
| 1. If|stream|'s [=WebSocketStream/ready state=] is not {{WebSocket/OPEN}} (1), then return. | ||
| 1. Let |chunk| be determined by switching on |type|: | ||
| <dl class="switch"> | ||
| @@ -1000,7 +1001,7 @@ and data |data|, the user agent must [=queue a global task=] on the [=WebSocket | ||
| When [=the WebSocket closing handshake is started=] for a {{WebSocketStream}} | ||
| |stream|, the user agent must [=queue a global task=] on the [=WebSocket task source=] given | ||
| |stream|'s [=relevant global object=] to change |stream|'s [=WebSocketStream/ready state=] to | ||
| {{WebSocket/CLOSING}} if it is not already. [[!WSP]] | ||
| ||
| <hr> | ||
| @@ -1011,10 +1012,10 @@ When [=the WebSocket connection is closed=] for a {{WebSocketStream}} |stream|, | ||
| [=cleanly=], the user agent must [=queue a global task=] on the [=WebSocket task source=] given | ||
| |stream|'s [=relevant global object=] to run the following substeps: | ||
| 1. Change|stream|'s [=WebSocketStream/ready state=] to {{WebSocket/CLOSED}} (3). | ||
| 1. If |stream|'s [=WebSocketStream/handshake aborted=] is true, then return. | ||
| 1. If |stream|'s [=WebSocketStream/was ever connected=] is false, then [=reject=] |stream|'s | ||
| [=opened promise=] with a [=new=]{{WebSocketError}}. | ||
| 1. Let |code| be [=the WebSocket connection close code=]. | ||
| 1. Let |reason| be the result of applying [=UTF-8 decode without BOM=] to [=the WebSocket | ||
| connection close reason=]. | ||
| @@ -1143,7 +1144,7 @@ Each {{WebSocketError}} object has an associated <dfn for="WebSocketError">reaso | ||
| string. | ||
| <dl class="domintro non-normative"> | ||
| : <code>|error| = new {{WebSocketError/constructor(message, init)|WebSocketError}}([|message|[, | ||
| |init|]])</code> | ||
| :: Creates a new {{WebSocketError}} object. | ||
| @@ -1182,7 +1183,7 @@ WebSocketError(|message|, |init|)</code></dfn> constructor steps are: | ||
| 1. Let |reason| be |init|["{{WebSocketCloseInfo/reason}}"] if it [=map/exists=], or the empty | ||
| string otherwise. | ||
| 1. [=Validate close code and reason=] with |code| and |reason|. | ||
| 1. If |reason| is non-empty, but |code| isnull, then set |code| to 1000 ("Normal Closure"). | ||
| 1. Set [=this=]'s [=WebSocketError/closeCode=] to |code|. | ||
| 1. Set [=this=]'s [=WebSocketError/reason=] to |reason|. | ||
| </div> | ||