Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
ricea wants to merge33 commits intomain
base:main
Choose a base branch
Loading
fromadd-websocketstream
Open
Changes from1 commit
Commits
Show all changes
33 commits
Select commitHold shift + click to select a range
579e413
[WIP] The WebSocketStream Interface
riceaNov 11, 2021
3c4803b
Fix grammatical errors
riceaJan 23, 2024
8e5f06b
Note that backpressure is obeyed for writable
riceaJan 23, 2024
5cb355b
Remove mention of passing close code or reason to abort() or cancel()
riceaJan 23, 2024
1f9a2d6
Revert "Remove mention of passing close code or reason to abort() or …
riceaJan 28, 2024
96baeed
Mention that it has to be a WebSocketError
riceaJan 28, 2024
69bae4f
Add IDL for WebSocketError
riceaJan 28, 2024
fa5ff83
Add algorithm steps for WebSocketStream and WebSocketError
riceaJan 28, 2024
adf4bbe
Changes from reviews
riceaJan 30, 2024
f488ee4
Add missing AbortSignal algorithm steps.
riceaJan 30, 2024
b1a58f4
Use Bikeshed magic to get a URL record
riceaJan 31, 2024
8cc184c
Add missing colon
riceaJan 31, 2024
7812163
Remove "the user agent must run..."
riceaJan 31, 2024
47ab0da
Fix capitalisation of "close"
riceaJan 31, 2024
2b9ee80
Server can't send a bad reason, and wording improvement (by @domenic)
riceaJan 31, 2024
12ff404
Editorial changes from @domenic. Also change `closeCode` to [EnforceR…
riceaJan 31, 2024
a2fc7c2
Change `|this|` to `[=this=]` everywhere
riceaJan 31, 2024
3a285c7
Fix initialization of dictionaries and WebSocketErrors
riceaJan 31, 2024
397dd00
Demote "Feedback from the protocol" and "The CloseEvent interface"
riceaJan 31, 2024
9e8d8f7
Indent "Garbage Collection" and fix the WebSocketStream interface ena…
riceaFeb 1, 2024
673ace9
Use "queue a global task"
riceaFeb 6, 2024
30f5f8b
Explicitly say what realm write algorithm's promise is created in
riceaFeb 6, 2024
7d85772
Add more <hr>s
riceaFeb 6, 2024
1d7d868
Place The WebSocket Protocol in <cite> tags
riceaFeb 6, 2024
7b81f79
Fix many small nits from domenic@'s review
riceaFeb 6, 2024
6da74e7
Add a missing comma
riceaFeb 21, 2024
16a75fe
Fix description of "was ever connected"
riceaFeb 21, 2024
2bd7ad5
Fix grammar in developer notes
riceaFeb 21, 2024
b2e001c
Apply cleanups by @domenic.
riceaFeb 21, 2024
1e2eae9
Fixes requested by @domenic
riceaFeb 21, 2024
24f24f8
Fix Bikeshed compile error
riceaFeb 21, 2024
a6d426f
Set defaults for WebSocketError's closeCode and reason
riceaFeb 21, 2024
d5570f3
Add default arguments
riceaMar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Apply cleanups by@domenic.
Co-authored-by: Domenic Denicola <d@domenic.me>
  • Loading branch information
@ricea@domenic
ricea anddomenic authoredFeb 21, 2024
commitb2e001c9aa7a36a2539cbf6d95c82949e6ec0cf1
25 changes: 13 additions & 12 deletionsindex.bs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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>
: <code>|socket| = new {{WebSocketStream/constructor(url, options)|WebSocketStream}}(|url|[, |options|])</code>
:: Creates a new {{WebSocketStream}} object, immediately establishing the associated WebSocket
connection.

Expand All@@ -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
:: 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}}
Expand All@@ -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 bycalling <code><var
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
Expand DownExpand Up@@ -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
:: 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>
: <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
Expand DownExpand Up@@ -943,12 +944,12 @@ object=] to run these steps:

<div algorithm="handle WebSocketStream connection establishment">

1. Changethe [=WebSocketStream/ready state=] to {{WebSocket/OPEN}} (1).
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=]the {{WebSocketStream}} with|stream|and
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|.
Expand All@@ -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[=WebSocket/ready state=] is not {{WebSocket/OPEN}} (1), then return.
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">
Expand All@@ -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 changethe|stream|'s [=WebSocketStream/ready state=] to
|stream|'s [=relevant global object=] to change |stream|'s [=WebSocketStream/ready state=] to
{{WebSocket/CLOSING}} if it is not already. [[!WSP]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is a bit ambiguous. Does this mean: queue a task to (if state != CLOSING, set state to CLOSING) or does it mean: if state != CLOSING, queue a task to set state to CLOSING.

These could be observably different due to race conditions.

Possibly it's best to just delete "if it is not already"?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Agreed. Done.


<hr>
Expand All@@ -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. Changethe [=WebSocketStream/ready state=] to {{WebSocket/CLOSED}} (3).
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.
[=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=].
Expand DownExpand Up@@ -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|[,
: <code>|error| = new {{WebSocketError/constructor(message, init)|WebSocketError}}([|message|[,
|init|]])</code>
:: Creates a new {{WebSocketError}} object.

Expand DownExpand Up@@ -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| isnot set, then set |code| to 1000 ("Normal Closure").
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>
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp