* @see https://websockets.spec.whatwg.org/#dom-websocket-send * @param {NodeJS.TypedArray|ArrayBuffer|Blob|string} data
(data)
| 15993 | * @param {NodeJS.TypedArray|ArrayBuffer|Blob|string} data |
| 15994 | */ |
| 15995 | send(data) { |
| 15996 | webidl.brandCheck(this, _WebSocket); |
| 15997 | const prefix = "WebSocket.send"; |
| 15998 | webidl.argumentLengthCheck(arguments, 1, prefix); |
| 15999 | data = webidl.converters.WebSocketSendData(data, prefix, "data"); |
| 16000 | if (isConnecting(this.#handler.readyState)) { |
| 16001 | throw new DOMException("Sent before connected.", "InvalidStateError"); |
| 16002 | } |
| 16003 | if (!isEstablished(this.#handler.readyState) || isClosing(this.#handler.readyState)) { |
| 16004 | return; |
| 16005 | } |
| 16006 | if (typeof data === "string") { |
| 16007 | const buffer = Buffer.from(data); |
| 16008 | this.#bufferedAmount += buffer.byteLength; |
| 16009 | this.#sendQueue.add(buffer, () => { |
| 16010 | this.#bufferedAmount -= buffer.byteLength; |
| 16011 | }, sendHints.text); |
| 16012 | } else if (isArrayBuffer(data)) { |
| 16013 | this.#bufferedAmount += data.byteLength; |
| 16014 | this.#sendQueue.add(data, () => { |
| 16015 | this.#bufferedAmount -= data.byteLength; |
| 16016 | }, sendHints.arrayBuffer); |
| 16017 | } else if (ArrayBuffer.isView(data)) { |
| 16018 | this.#bufferedAmount += data.byteLength; |
| 16019 | this.#sendQueue.add(data, () => { |
| 16020 | this.#bufferedAmount -= data.byteLength; |
| 16021 | }, sendHints.typedArray); |
| 16022 | } else if (webidl.is.Blob(data)) { |
| 16023 | this.#bufferedAmount += data.size; |
| 16024 | this.#sendQueue.add(data, () => { |
| 16025 | this.#bufferedAmount -= data.size; |
| 16026 | }, sendHints.blob); |
| 16027 | } |
| 16028 | } |
| 16029 | get readyState() { |
| 16030 | webidl.brandCheck(this, _WebSocket); |
| 16031 | return this.#handler.readyState; |
nothing calls this directly
no test coverage detected