MCPcopy
hub / github.com/nodejs/undici / WebSocketStream

Class WebSocketStream

lib/web/websocket/stream/websocketstream.js:18–450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16let emittedExperimentalWarning = false
17
18class WebSocketStream {
19 // Each WebSocketStream object has an associated url , which is a URL record .
20 /** @type {URL} */
21 #url
22
23 // Each WebSocketStream object has an associated opened promise , which is a promise.
24 /** @type {ReturnType<typeof Promise.withResolvers>} */
25 #openedPromise
26
27 // Each WebSocketStream object has an associated closed promise , which is a promise.
28 /** @type {ReturnType<typeof Promise.withResolvers>} */
29 #closedPromise
30
31 // Each WebSocketStream object has an associated readable stream , which is a ReadableStream .
32 /** @type {ReadableStream} */
33 #readableStream
34 /** @type {ReadableStreamDefaultController} */
35 #readableStreamController
36
37 // Each WebSocketStream object has an associated writable stream , which is a WritableStream .
38 /** @type {WritableStream} */
39 #writableStream
40
41 // Each WebSocketStream object has an associated boolean handshake aborted , which is initially false.
42 #handshakeAborted = false
43
44 /** @type {import('../websocket').Handler} */
45 #handler = {
46 // https://whatpr.org/websockets/48/7b748d3...d5570f3.html#feedback-to-websocket-stream-from-the-protocol
47 onConnectionEstablished: (response, extensions) => this.#onConnectionEstablished(response, extensions),
48 onMessage: (opcode, data) => this.#onMessage(opcode, data),
49 onParserError: (err) => failWebsocketConnection(this.#handler, null, err.message),
50 onParserDrain: () => this.#handler.socket.resume(),
51 onSocketData: (chunk) => {
52 if (!this.#parser.write(chunk)) {
53 this.#handler.socket.pause()
54 }
55 },
56 onSocketError: (err) => {
57 this.#handler.readyState = states.CLOSING
58
59 if (channels.socketError.hasSubscribers) {
60 channels.socketError.publish(err)
61 }
62
63 this.#handler.socket.destroy()
64 },
65 onSocketClose: () => this.#onSocketClose(),
66 onPing: () => {},
67 onPong: () => {},
68
69 readyState: states.CONNECTING,
70 socket: null,
71 closeState: new Set(),
72 controller: null,
73 wasEverConnected: false
74 }
75

Callers

nothing calls this directly

Calls 8

#onMessageMethod · 0.95
#onSocketCloseMethod · 0.95
failWebsocketConnectionFunction · 0.85
resumeMethod · 0.65
pauseMethod · 0.65
writeMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…