MCPcopy Create free account
hub / github.com/nodejs/node / send

Method send

deps/undici/undici.js:15995–16028  ·  view source on GitHub ↗

* @see https://websockets.spec.whatwg.org/#dom-websocket-send * @param {NodeJS.TypedArray|ArrayBuffer|Blob|string} data

(data)

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 7

brandCheckMethod · 0.80
argumentLengthCheckMethod · 0.80
isConnectingFunction · 0.70
isEstablishedFunction · 0.70
isClosingFunction · 0.70
addMethod · 0.65
fromMethod · 0.45

Tested by

no test coverage detected