File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -40,19 +40,23 @@ function ping (options) {
40
40
client . once ( 'server_info' , function ( packet ) {
41
41
const data = JSON . parse ( packet . response )
42
42
const start = Date . now ( )
43
- const maxTime = setTimeout ( ( ) => {
43
+ const maxTimer = setTimeout ( ( ) => {
44
44
clearTimeout ( closeTimer )
45
45
client . end ( )
46
46
resolve ( data )
47
47
} , options . noPongTimeout )
48
+ const time = BigInt ( Date . now ( ) )
48
49
client . once ( 'ping' , function ( packet ) {
49
50
data . latency = Date . now ( ) - start
50
- clearTimeout ( maxTime )
51
- clearTimeout ( closeTimer )
52
- client . end ( )
53
- resolve ( data )
51
+ if ( BigInt ( packet . time ) === time ) {
52
+ // pong payload should be the same as ping payload
53
+ clearTimeout ( maxTimer )
54
+ clearTimeout ( closeTimer )
55
+ client . end ( )
56
+ resolve ( data )
57
+ }
54
58
} )
55
- client . write ( 'ping' , { time : [ 0 , 0 ] } )
59
+ client . write ( 'ping' , { time } )
56
60
} )
57
61
client . on ( 'state' , function ( newState ) {
58
62
if ( newState === states . STATUS ) { client . write ( 'ping_start' , { } ) }
You can’t perform that action at this time.
0 commit comments