File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,7 @@ module.exports = class Connection {
224
224
// increment connection counter by 1
225
225
self . connection_progress_obj . counter ++ ;
226
226
227
+ // start heartbeat to keep connection alive
227
228
self . ping ( ) ;
228
229
229
230
/**
@@ -304,10 +305,22 @@ module.exports = class Connection {
304
305
} ) ;
305
306
}
306
307
308
+ /**
309
+ * Pings the server at a regular interval.
310
+ * Websockets require a "heartbeat" in order to keep the conneciton open.
311
+ * @returns {void }
312
+ */
307
313
ping ( ) {
314
+
315
+ // allows this to be used inside nested functions
308
316
let self = this
317
+
318
+ // send a request to the websocket server ever 5 seconds
309
319
this . pingTimer = setInterval ( function ( ) {
320
+
310
321
// create a JSON string containing the current request number
322
+ // we use 0 as to not interer with any unsigned ints on the server end, as well as any possible
323
+ // pening responses from the server
311
324
let data = JSON . stringify ( { 'c' : 0 } ) ;
312
325
313
326
// send the request to the websocket server
@@ -318,6 +331,7 @@ module.exports = class Connection {
318
331
319
332
/**
320
333
* Closes the connection to the websocket server
334
+ * @returns {void }
321
335
*/
322
336
close ( ) {
323
337
this . keep_alive = false ;
You can’t perform that action at this time.
0 commit comments