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
NextNext commit
[WIP] The WebSocketStream Interface
  • Loading branch information
@ricea
ricea committedJan 28, 2024
commit579e4130d5438fcf5a83048529ff25e2eea7c3b2
122 changes: 122 additions & 0 deletionsindex.bs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -795,6 +795,128 @@ the following list:

</div>



# 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 {
constructor(USVString url, optional WebSocketStreamOptions options);
readonly attribute USVString url;
readonly attribute Promise<WebSocketOpenInfo> opened;
readonly attribute Promise<WebSocketCloseInfo> closed;
undefined close(optional WebSocketCloseInfo closeInfo);
};
</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
initially unset.

<dl class="domintro non-normative">
: <code>|socket| = new {{WebSocketStream/constructor(url, options)|WebSocketStream}}(|url| [, |options| ]</code>
:: Creates a new {{WebSocketStream}} object, immediately establishing the associating WebSocket
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.

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]]

: {{WebSocketStreamOptions/signal}}
:: An {{AbortSignal}} that can be used to abort the handshake. After the handshake is complete the
signal does nothing.

: <code>|socket| . {{WebSocketStream/url}}</code>
:: 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
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.

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
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
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()}}
{{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
[=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.

: <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
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp