@@ -38,17 +38,14 @@ class WebSocketStream {
38
38
/** @type {WritableStream } */
39
39
#writableStream
40
40
41
- // Each WebSocketStream object has an associated was ever connected , which is a boolean, initially false.
42
- #wasEverConnected = false
43
-
44
41
// Each WebSocketStream object has an associated boolean handshake aborted , which is initially false.
45
42
#handshakeAborted = false
46
43
47
44
/** @type {import('../websocket').Handler } */
48
45
#handler = {
49
46
// https://whatpr.org/websockets/48/7b748d3...d5570f3.html#feedback-to-websocket-stream-from-the-protocol
50
47
onConnectionEstablished : ( response , extensions ) => this . #onConnectionEstablished( response , extensions ) ,
51
- onFail : ( reason ) => this . #onFail ( reason ) ,
48
+ onFail : ( _code , _reason ) => { } ,
52
49
onMessage : ( opcode , data ) => this . #onMessage( opcode , data ) ,
53
50
onParserError : ( err ) => failWebsocketConnection ( this . #handler, null , err . message ) ,
54
51
onParserDrain : ( ) => this . #handler. socket . resume ( ) ,
@@ -71,15 +68,13 @@ class WebSocketStream {
71
68
readyState : states . CONNECTING ,
72
69
socket : null ,
73
70
closeState : new Set ( ) ,
74
- receivedClose : false
71
+ controller : null ,
72
+ wasEverConnected : false
75
73
}
76
74
77
75
/** @type {import('../receiver').ByteParser } */
78
76
#parser
79
77
80
- /** @type {import('../../fetch/index').Fetch } */
81
- #controller
82
-
83
78
constructor ( url , options = undefined ) {
84
79
if ( ! emittedExperimentalWarning ) {
85
80
process . emitWarning ( 'WebSocketStream is experimental! Expect it to change at any time.' , {
@@ -161,7 +156,7 @@ class WebSocketStream {
161
156
162
157
// 10. Run this step in parallel :
163
158
// 10.1. Establish a WebSocket connection given urlRecord , protocols , and client . [FETCH]
164
- this . #controller = establishWebSocketConnection (
159
+ this . #handler . controller = establishWebSocketConnection (
165
160
urlRecord ,
166
161
protocols ,
167
162
client ,
@@ -269,7 +264,7 @@ class WebSocketStream {
269
264
this . #handler. readyState = states . OPEN
270
265
271
266
// 2. Set stream ’s was ever connected to true.
272
- this . #wasEverConnected = true
267
+ // This is done in the opening handshake.
273
268
274
269
// 3. Let extensions be the extensions in use .
275
270
const extensions = parsedExtensions ?? ''
@@ -367,7 +362,7 @@ class WebSocketStream {
367
362
}
368
363
369
364
// 3. If stream ’s was ever connected is false, then reject stream ’s opened promise with a new WebSocketError.
370
- if ( ! this . #wasEverConnected) {
365
+ if ( ! this . #handler . wasEverConnected ) {
371
366
this . #openedPromise. reject ( new WebSocketError ( 'Socket never opened' ) )
372
367
}
373
368
@@ -422,22 +417,6 @@ class WebSocketStream {
422
417
}
423
418
}
424
419
425
- #onFail ( code , reason ) {
426
- // If _The WebSocket Connection is Established_ prior to the point where
427
- // the endpoint is required to _Fail the WebSocket Connection_, the
428
- // endpoint SHOULD send a Close frame with an appropriate status code
429
- // (Section 7.4) before proceeding to _Close the WebSocket Connection_.
430
- if ( isEstablished ( this . #handler. readyState ) ) {
431
- closeWebSocketConnection ( this . #handler, code , reason , false )
432
- }
433
-
434
- this . #controller. abort ( )
435
-
436
- if ( this . #handler. socket && ! this . #handler. socket . destroyed ) {
437
- this . #handler. socket . destroy ( )
438
- }
439
- }
440
-
441
420
#closeUsingReason ( reason ) {
442
421
// 1. Let code be null.
443
422
let code = null
0 commit comments