@@ -36,7 +36,7 @@ class WebSocket extends EventEmitter {
36
36
/**
37
37
* Create a new `WebSocket`.
38
38
*
39
- * @param {(String|url. URL) } address The URL to which to connect
39
+ * @param {(String|URL) } address The URL to which to connect
40
40
* @param {(String|String[]) } [protocols] The subprotocols
41
41
* @param {Object } [options] Connection options
42
42
*/
@@ -112,6 +112,50 @@ class WebSocket extends EventEmitter {
112
112
return Object . keys ( this . _extensions ) . join ( ) ;
113
113
}
114
114
115
+ /**
116
+ * @type {Function }
117
+ */
118
+ /* istanbul ignore next */
119
+ get onclose ( ) {
120
+ return undefined ;
121
+ }
122
+
123
+ /* istanbul ignore next */
124
+ set onclose ( listener ) { }
125
+
126
+ /**
127
+ * @type {Function }
128
+ */
129
+ /* istanbul ignore next */
130
+ get onerror ( ) {
131
+ return null ;
132
+ }
133
+
134
+ /* istanbul ignore next */
135
+ set onerror ( listener ) { }
136
+
137
+ /**
138
+ * @type {Function }
139
+ */
140
+ /* istanbul ignore next */
141
+ get onopen ( ) {
142
+ return undefined ;
143
+ }
144
+
145
+ /* istanbul ignore next */
146
+ set onopen ( listener ) { }
147
+
148
+ /**
149
+ * @type {Function }
150
+ */
151
+ /* istanbul ignore next */
152
+ get onmessage ( ) {
153
+ return undefined ;
154
+ }
155
+
156
+ /* istanbul ignore next */
157
+ set onmessage ( listener ) { }
158
+
115
159
/**
116
160
* @type {String }
117
161
*/
@@ -136,7 +180,8 @@ class WebSocket extends EventEmitter {
136
180
/**
137
181
* Set up the socket and the internal resources.
138
182
*
139
- * @param {net.Socket } socket The network socket between the server and client
183
+ * @param {(net.Socket|tls.Socket) } socket The network socket between the
184
+ * server and client
140
185
* @param {Buffer } head The first packet of the upgraded stream
141
186
* @param {Number } [maxPayload=0] The maximum allowed message size
142
187
* @private
@@ -392,11 +437,76 @@ class WebSocket extends EventEmitter {
392
437
}
393
438
}
394
439
395
- readyStates . forEach ( ( readyState , i ) => {
396
- const descriptor = { enumerable : true , value : i } ;
440
+ /**
441
+ * @constant {Number} CONNECTING
442
+ * @memberof WebSocket
443
+ */
444
+ Object . defineProperty ( WebSocket , 'CONNECTING' , {
445
+ enumerable : true ,
446
+ value : readyStates . indexOf ( 'CONNECTING' )
447
+ } ) ;
397
448
398
- Object . defineProperty ( WebSocket . prototype , readyState , descriptor ) ;
399
- Object . defineProperty ( WebSocket , readyState , descriptor ) ;
449
+ /**
450
+ * @constant {Number} CONNECTING
451
+ * @memberof WebSocket.prototype
452
+ */
453
+ Object . defineProperty ( WebSocket . prototype , 'CONNECTING' , {
454
+ enumerable : true ,
455
+ value : readyStates . indexOf ( 'CONNECTING' )
456
+ } ) ;
457
+
458
+ /**
459
+ * @constant {Number} OPEN
460
+ * @memberof WebSocket
461
+ */
462
+ Object . defineProperty ( WebSocket , 'OPEN' , {
463
+ enumerable : true ,
464
+ value : readyStates . indexOf ( 'OPEN' )
465
+ } ) ;
466
+
467
+ /**
468
+ * @constant {Number} OPEN
469
+ * @memberof WebSocket.prototype
470
+ */
471
+ Object . defineProperty ( WebSocket . prototype , 'OPEN' , {
472
+ enumerable : true ,
473
+ value : readyStates . indexOf ( 'OPEN' )
474
+ } ) ;
475
+
476
+ /**
477
+ * @constant {Number} CLOSING
478
+ * @memberof WebSocket
479
+ */
480
+ Object . defineProperty ( WebSocket , 'CLOSING' , {
481
+ enumerable : true ,
482
+ value : readyStates . indexOf ( 'CLOSING' )
483
+ } ) ;
484
+
485
+ /**
486
+ * @constant {Number} CLOSING
487
+ * @memberof WebSocket.prototype
488
+ */
489
+ Object . defineProperty ( WebSocket . prototype , 'CLOSING' , {
490
+ enumerable : true ,
491
+ value : readyStates . indexOf ( 'CLOSING' )
492
+ } ) ;
493
+
494
+ /**
495
+ * @constant {Number} CLOSED
496
+ * @memberof WebSocket
497
+ */
498
+ Object . defineProperty ( WebSocket , 'CLOSED' , {
499
+ enumerable : true ,
500
+ value : readyStates . indexOf ( 'CLOSED' )
501
+ } ) ;
502
+
503
+ /**
504
+ * @constant {Number} CLOSED
505
+ * @memberof WebSocket.prototype
506
+ */
507
+ Object . defineProperty ( WebSocket . prototype , 'CLOSED' , {
508
+ enumerable : true ,
509
+ value : readyStates . indexOf ( 'CLOSED' )
400
510
} ) ;
401
511
402
512
[
@@ -416,14 +526,7 @@ readyStates.forEach((readyState, i) => {
416
526
//
417
527
[ 'open' , 'error' , 'close' , 'message' ] . forEach ( ( method ) => {
418
528
Object . defineProperty ( WebSocket . prototype , `on${ method } ` , {
419
- configurable : true ,
420
529
enumerable : true ,
421
- /**
422
- * Return the listener of the event.
423
- *
424
- * @return {(Function|undefined) } The event listener or `undefined`
425
- * @public
426
- */
427
530
get ( ) {
428
531
const listeners = this . listeners ( method ) ;
429
532
for ( let i = 0 ; i < listeners . length ; i ++ ) {
@@ -432,12 +535,6 @@ readyStates.forEach((readyState, i) => {
432
535
433
536
return undefined ;
434
537
} ,
435
- /**
436
- * Add a listener for the event.
437
- *
438
- * @param {Function } listener The listener to add
439
- * @public
440
- */
441
538
set ( listener ) {
442
539
const listeners = this . listeners ( method ) ;
443
540
for ( let i = 0 ; i < listeners . length ; i ++ ) {
@@ -460,7 +557,7 @@ module.exports = WebSocket;
460
557
* Initialize a WebSocket client.
461
558
*
462
559
* @param {WebSocket } websocket The client to initialize
463
- * @param {(String|url. URL) } address The URL to which to connect
560
+ * @param {(String|URL) } address The URL to which to connect
464
561
* @param {String } [protocols] The subprotocols
465
562
* @param {Object } [options] Connection options
466
563
* @param {(Boolean|Object) } [options.perMessageDeflate=true] Enable/disable
@@ -744,8 +841,8 @@ function tlsConnect(options) {
744
841
* Abort the handshake and emit an error.
745
842
*
746
843
* @param {WebSocket } websocket The WebSocket instance
747
- * @param {(http.ClientRequest|net.Socket) } stream The request to abort or the
748
- * socket to destroy
844
+ * @param {(http.ClientRequest|net.Socket|tls.Socket ) } stream The request to
845
+ * abort or the socket to destroy
749
846
* @param {String } message The error message
750
847
* @private
751
848
*/
0 commit comments