@@ -43,6 +43,8 @@ interface GobanSocketOptions {
43
43
/** Don't automatically send pings */
44
44
dont_ping ?: boolean ;
45
45
46
+ ping_interval ?: number ; // milliseconds
47
+
46
48
/** Don't log connection/disconnect things*/
47
49
quiet ?: boolean ;
48
50
}
@@ -96,7 +98,7 @@ export class GobanSocket<
96
98
private reconnecting = false ;
97
99
private reconnect_tries = 0 ;
98
100
private send_queue : ( ( ) => void ) [ ] = [ ] ;
99
- private ping_interval ?: ReturnType < typeof niceInterval > ;
101
+ private ping_timer ?: ReturnType < typeof niceInterval > ;
100
102
private callbacks : Map < number , ( data ?: any , error ?: ErrorResponse ) => void > = new Map ( ) ;
101
103
private authentication ?: DataArgument < SendProtocol [ "authenticate" ] > ;
102
104
private manually_disconnected = false ;
@@ -118,6 +120,7 @@ export class GobanSocket<
118
120
this . latency = latency ;
119
121
this . clock_drift = drift ;
120
122
this . emit ( "latency" , latency , drift ) ;
123
+ ///console.log("Pong:", this.url);
121
124
} ) ;
122
125
}
123
126
@@ -153,18 +156,18 @@ export class GobanSocket<
153
156
latency : this . latency ,
154
157
} as DataArgument < SendProtocol [ "net/ping" ] > ) ;
155
158
} else {
156
- if ( this . ping_interval ) {
157
- clearInterval ( this . ping_interval ) ;
158
- this . ping_interval = undefined ;
159
+ if ( this . ping_timer ) {
160
+ clearInterval ( this . ping_timer ) ;
161
+ this . ping_timer = undefined ;
159
162
}
160
163
}
161
164
} ;
162
165
163
- if ( this . ping_interval ) {
164
- clearInterval ( this . ping_interval ) ;
166
+ if ( this . ping_timer ) {
167
+ clearInterval ( this . ping_timer ) ;
165
168
}
166
169
167
- this . ping_interval = niceInterval ( ping , PING_INTERVAL ) ;
170
+ this . ping_timer = niceInterval ( ping , this . options . ping_interval ?? PING_INTERVAL ) ;
168
171
ping ( ) ;
169
172
}
170
173
0 commit comments