From 9202158d4be6034a90e2507f18e068c7c0f97cfe Mon Sep 17 00:00:00 2001 From: Khafra Date: Mon, 20 May 2024 13:39:58 -0400 Subject: [PATCH] add protocols option to WebSocket constructor 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: https://github.com/whatwg/websockets/issues/42 --- index.bs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 6b32a1c..1492b58 100644 --- a/index.bs +++ b/index.bs @@ -209,7 +209,7 @@ enum BinaryType { "blob", "arraybuffer" }; [Exposed=(Window,Worker)] interface WebSocket : EventTarget { - constructor(USVString url, optional (DOMString or sequence) protocols = []); + constructor(USVString url, optional (DOMString or sequence or WebSocketInitDict) protocols = []); readonly attribute USVString url; // ready state @@ -233,6 +233,10 @@ interface WebSocket : EventTarget { attribute BinaryType binaryType; undefined send((BufferSource or Blob or USVString) data); }; + +dictionary WebSocketInitDict { + sequence protocols = []; +}; Each {{WebSocket}} object has an associated url, which @@ -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. + 2. 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 \``Sec-WebSocket-Protocol`\` fields as defined by The WebSocket protocol,