@@ -84,6 +84,7 @@ class WebSocket extends EventEmitter {
84
84
85
85
initAsClient ( this , address , protocols , options ) ;
86
86
} else {
87
+ this . _autoPong = options . autoPong ;
87
88
this . _isServer = true ;
88
89
}
89
90
}
@@ -625,6 +626,8 @@ module.exports = WebSocket;
625
626
* @param {Boolean } [options.allowSynchronousEvents=false] Specifies whether any
626
627
* of the `'message'`, `'ping'`, and `'pong'` events can be emitted multiple
627
628
* times in the same tick
629
+ * @param {Boolean } [options.autoPong=true] Specifies whether or not to
630
+ * automatically send a pong in response to a ping
628
631
* @param {Function } [options.finishRequest] A function which can be used to
629
632
* customize the headers of each http request before it is sent
630
633
* @param {Boolean } [options.followRedirects=false] Whether or not to follow
@@ -650,6 +653,7 @@ module.exports = WebSocket;
650
653
function initAsClient ( websocket , address , protocols , options ) {
651
654
const opts = {
652
655
allowSynchronousEvents : false ,
656
+ autoPong : true ,
653
657
protocolVersion : protocolVersions [ 1 ] ,
654
658
maxPayload : 100 * 1024 * 1024 ,
655
659
skipUTF8Validation : false ,
@@ -668,6 +672,8 @@ function initAsClient(websocket, address, protocols, options) {
668
672
port : undefined
669
673
} ;
670
674
675
+ websocket . _autoPong = opts . autoPong ;
676
+
671
677
if ( ! protocolVersions . includes ( opts . protocolVersion ) ) {
672
678
throw new RangeError (
673
679
`Unsupported protocol version: ${ opts . protocolVersion } ` +
@@ -1212,7 +1218,7 @@ function receiverOnMessage(data, isBinary) {
1212
1218
function receiverOnPing ( data ) {
1213
1219
const websocket = this [ kWebSocket ] ;
1214
1220
1215
- websocket . pong ( data , ! websocket . _isServer , NOOP ) ;
1221
+ if ( websocket . _autoPong ) websocket . pong ( data , ! this . _isServer , NOOP ) ;
1216
1222
websocket . emit ( 'ping' , data ) ;
1217
1223
}
1218
1224
0 commit comments