MCPcopy Index your code
hub / github.com/nodejs/node / ping

Method ping

deps/undici/src/lib/web/websocket/websocket.js:639–656  ·  view source on GitHub ↗

* @param {WebSocket} ws * @param {Buffer|undefined} buffer

(ws, buffer)

Source from the content-addressed store, hash-verified

637 * @param {Buffer|undefined} buffer
638 */
639 static ping (ws, buffer) {
640 if (Buffer.isBuffer(buffer)) {
641 if (buffer.length > 125) {
642 throw new TypeError('A PING frame cannot have a body larger than 125 bytes.')
643 }
644 } else if (buffer !== undefined) {
645 throw new TypeError('Expected buffer payload')
646 }
647
648 // An endpoint MAY send a Ping frame any time after the connection is
649 // established and before the connection is closed.
650 const readyState = ws.#handler.readyState
651
652 if (isEstablished(readyState) && !isClosing(readyState) && !isClosed(readyState)) {
653 const frame = new WebsocketFrameSend(buffer)
654 ws.#handler.socket.write(frame.createFrame(opcodes.PING))
655 }
656 }
657}
658
659const { ping } = WebSocket

Callers 1

onHttp2SendPingFunction · 0.45

Calls 5

createFrameMethod · 0.95
isEstablishedFunction · 0.70
isClosingFunction · 0.70
isClosedFunction · 0.70
writeMethod · 0.45

Tested by

no test coverage detected