* @see https://websockets.spec.whatwg.org/#dom-websocket-send * @param {NodeJS.TypedArray|ArrayBuffer|Blob|string} data
(data)
| 63722 | } else { |
| 63723 | this[kReadyState] = _WebSocket.CLOSING; |
| 63724 | } |
| 63725 | } |
| 63726 | /** |
| 63727 | * @see https://websockets.spec.whatwg.org/#dom-websocket-send |
| 63728 | * @param {NodeJS.TypedArray|ArrayBuffer|Blob|string} data |
| 63729 | */ |
| 63730 | send(data) { |
| 63731 | webidl.brandCheck(this, _WebSocket); |
| 63732 | webidl.argumentLengthCheck(arguments, 1, { header: "WebSocket.send" }); |
| 63733 | data = webidl.converters.WebSocketSendData(data); |
| 63734 | if (this[kReadyState] === _WebSocket.CONNECTING) { |
| 63735 | throw new DOMException3("Sent before connected.", "InvalidStateError"); |
| 63736 | } |
| 63737 | if (!isEstablished(this) || isClosing(this)) { |
| 63738 | return; |
| 63739 | } |
| 63740 | const socket = this[kResponse].socket; |
| 63741 | if (typeof data === "string") { |
| 63742 | const value = Buffer.from(data); |
| 63743 | const frame = new WebsocketFrameSend(value); |
| 63744 | const buffer = frame.createFrame(opcodes.TEXT); |
| 63745 | this.#bufferedAmount += value.byteLength; |
| 63746 | socket.write(buffer, () => { |
| 63747 | this.#bufferedAmount -= value.byteLength; |
| 63748 | }); |
| 63749 | } else if (types.isArrayBuffer(data)) { |
| 63750 | const value = Buffer.from(data); |
| 63751 | const frame = new WebsocketFrameSend(value); |
| 63752 | const buffer = frame.createFrame(opcodes.BINARY); |
| 63753 | this.#bufferedAmount += value.byteLength; |
| 63754 | socket.write(buffer, () => { |
| 63755 | this.#bufferedAmount -= value.byteLength; |
| 63756 | }); |
| 63757 | } else if (ArrayBuffer.isView(data)) { |
| 63758 | const ab = Buffer.from(data, data.byteOffset, data.byteLength); |
| 63759 | const frame = new WebsocketFrameSend(ab); |
| 63760 | const buffer = frame.createFrame(opcodes.BINARY); |
| 63761 | this.#bufferedAmount += ab.byteLength; |
| 63762 | socket.write(buffer, () => { |
| 63763 | this.#bufferedAmount -= ab.byteLength; |
| 63764 | }); |
| 63765 | } else if (isBlobLike3(data)) { |
| 63766 | const frame = new WebsocketFrameSend(); |
| 63767 | data.arrayBuffer().then((ab) => { |
| 63768 | const value = Buffer.from(ab); |
| 63769 | frame.frameData = value; |
| 63770 | const buffer = frame.createFrame(opcodes.BINARY); |
| 63771 | this.#bufferedAmount += value.byteLength; |
| 63772 | socket.write(buffer, () => { |
| 63773 | this.#bufferedAmount -= value.byteLength; |
| 63774 | }); |
no test coverage detected