* @param {string} url * @param {string|string[]} protocols
(url, protocols = [])
| 127 | * @param {string|string[]} protocols |
| 128 | */ |
| 129 | constructor (url, protocols = []) { |
| 130 | super() |
| 131 | |
| 132 | webidl.util.markAsUncloneable(this) |
| 133 | |
| 134 | const prefix = 'WebSocket constructor' |
| 135 | webidl.argumentLengthCheck(arguments, 1, prefix) |
| 136 | |
| 137 | const options = webidl.converters['DOMString or sequence<DOMString> or WebSocketInit'](protocols, prefix, 'options') |
| 138 | |
| 139 | url = webidl.converters.USVString(url) |
| 140 | protocols = options.protocols |
| 141 | |
| 142 | // 1. Let baseURL be this's relevant settings object's API base URL. |
| 143 | const baseURL = environmentSettingsObject.settingsObject.baseUrl |
| 144 | |
| 145 | // 2. Let urlRecord be the result of getting a URL record given url and baseURL. |
| 146 | const urlRecord = getURLRecord(url, baseURL) |
| 147 | |
| 148 | // 3. If protocols is a string, set protocols to a sequence consisting |
| 149 | // of just that string. |
| 150 | if (typeof protocols === 'string') { |
| 151 | protocols = [protocols] |
| 152 | } |
| 153 | |
| 154 | // 4. If any of the values in protocols occur more than once or otherwise |
| 155 | // fail to match the requirements for elements that comprise the value |
| 156 | // of `Sec-WebSocket-Protocol` fields as defined by The WebSocket |
| 157 | // protocol, then throw a "SyntaxError" DOMException. |
| 158 | if (protocols.length !== new Set(protocols.map(p => p.toLowerCase())).size) { |
| 159 | throw new DOMException('Invalid Sec-WebSocket-Protocol value', 'SyntaxError') |
| 160 | } |
| 161 | |
| 162 | if (protocols.length > 0 && !protocols.every(p => isValidSubprotocol(p))) { |
| 163 | throw new DOMException('Invalid Sec-WebSocket-Protocol value', 'SyntaxError') |
| 164 | } |
| 165 | |
| 166 | // 5. Set this's url to urlRecord. |
| 167 | this.#url = new URL(urlRecord.href) |
| 168 | |
| 169 | // 6. Let client be this's relevant settings object. |
| 170 | const client = environmentSettingsObject.settingsObject |
| 171 | |
| 172 | // 7. Run this step in parallel: |
| 173 | // 7.1. Establish a WebSocket connection given urlRecord, protocols, |
| 174 | // and client. |
| 175 | this.#handler.controller = establishWebSocketConnection( |
| 176 | urlRecord, |
| 177 | protocols, |
| 178 | client, |
| 179 | this.#handler, |
| 180 | options |
| 181 | ) |
| 182 | |
| 183 | // Each WebSocket object has an associated ready state, which is a |
| 184 | // number representing the state of the connection. Initially it must |
| 185 | // be CONNECTING (0). |
| 186 | this.#handler.readyState = WebSocket.CONNECTING |
nothing calls this directly
no test coverage detected