@@ -36,7 +36,7 @@ class WebSocket extends EventEmitter {
3636 /**
3737 * Create a new `WebSocket`.
3838 *
39- * @param {(String|url. URL) } address The URL to which to connect
39+ * @param {(String|URL) } address The URL to which to connect
4040 * @param {(String|String[]) } [protocols] The subprotocols
4141 * @param {Object } [options] Connection options
4242 */
@@ -112,6 +112,50 @@ class WebSocket extends EventEmitter {
112112 return Object . keys ( this . _extensions ) . join ( ) ;
113113 }
114114
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+
115159 /**
116160 * @type {String }
117161 */
@@ -136,7 +180,8 @@ class WebSocket extends EventEmitter {
136180 /**
137181 * Set up the socket and the internal resources.
138182 *
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
140185 * @param {Buffer } head The first packet of the upgraded stream
141186 * @param {Number } [maxPayload=0] The maximum allowed message size
142187 * @private
@@ -392,11 +437,76 @@ class WebSocket extends EventEmitter {
392437 }
393438}
394439
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+ } ) ;
397448
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' )
400510} ) ;
401511
402512[
@@ -416,14 +526,7 @@ readyStates.forEach((readyState, i) => {
416526//
417527[ 'open' , 'error' , 'close' , 'message' ] . forEach ( ( method ) => {
418528 Object . defineProperty ( WebSocket . prototype , `on${ method } ` , {
419- configurable : true ,
420529 enumerable : true ,
421- /**
422- * Return the listener of the event.
423- *
424- * @return {(Function|undefined) } The event listener or `undefined`
425- * @public
426- */
427530 get ( ) {
428531 const listeners = this . listeners ( method ) ;
429532 for ( let i = 0 ; i < listeners . length ; i ++ ) {
@@ -432,12 +535,6 @@ readyStates.forEach((readyState, i) => {
432535
433536 return undefined ;
434537 } ,
435- /**
436- * Add a listener for the event.
437- *
438- * @param {Function } listener The listener to add
439- * @public
440- */
441538 set ( listener ) {
442539 const listeners = this . listeners ( method ) ;
443540 for ( let i = 0 ; i < listeners . length ; i ++ ) {
@@ -460,7 +557,7 @@ module.exports = WebSocket;
460557 * Initialize a WebSocket client.
461558 *
462559 * @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
464561 * @param {String } [protocols] The subprotocols
465562 * @param {Object } [options] Connection options
466563 * @param {(Boolean|Object) } [options.perMessageDeflate=true] Enable/disable
@@ -744,8 +841,8 @@ function tlsConnect(options) {
744841 * Abort the handshake and emit an error.
745842 *
746843 * @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
749846 * @param {String } message The error message
750847 * @private
751848 */
0 commit comments