Skip to content

Commit

Permalink
add protocols option to WebSocket constructor
Browse files Browse the repository at this point in the history
This commit adds an option bag to the WebSocket constructor that allows
settings the protocols. This will bring interop between browsers and
server environments that already implement this (Bun and Node).

Closes: whatwg#42
  • Loading branch information
KhafraDev committed May 20, 2024
1 parent 7b748d3 commit d2ebb69
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ enum BinaryType { "blob", "arraybuffer" };

[Exposed=(Window,Worker)]
interface WebSocket : EventTarget {
constructor(USVString url, optional (DOMString or sequence<DOMString>) protocols = []);
constructor(USVString url, optional (DOMString or sequence<DOMString> or WebSocketInitDict) protocols = []);
readonly attribute USVString url;

// ready state
Expand All @@ -233,6 +233,10 @@ interface WebSocket : EventTarget {
attribute BinaryType binaryType;
undefined send((BufferSource or Blob or USVString) data);
};

dictionary WebSocketInitDict {
sequence<DOMString> protocols = [];
};
</xmp>

Each {{WebSocket}} object has an associated <dfn for="WebSocket" lt="internal-url">url</dfn>, which
Expand Down Expand Up @@ -330,6 +334,8 @@ It can have the following values:
"{{SyntaxError}}" {{DOMException}}.
1. If |urlRecord|'s [=fragment=] is non-null, then throw a "{{SyntaxError}}" {{DOMException}}.
1. If |protocols| is a string, set |protocols| to a sequence consisting of just that string.
1. Otherwise, if |protocols| is a dictionary, set |protocols| to
|protocols|["{{WebSocketInitDict/protocols}}"]
1. If any of the values in |protocols| occur more than once or otherwise fail 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,
Expand Down

0 comments on commit d2ebb69

Please sign in to comment.