* Reworked Tuitio's heartbeat code into a shared single interval tick * @return {undefined}
()
| 1343 | * @return {undefined} |
| 1344 | */ |
| 1345 | socketHeartbeat() { |
| 1346 | /* Sockets removed from `subscriptions` during a manual terminate() |
| 1347 | will no longer be at risk of having functions called on them */ |
| 1348 | for (const endpointId in this.subscriptions) { |
| 1349 | const ws = this.subscriptions[endpointId]; |
| 1350 | if (ws.isAlive) { |
| 1351 | ws.isAlive = false; |
| 1352 | if (ws.readyState === WebSocket.OPEN) ws.ping(this.noop); |
| 1353 | } else { |
| 1354 | if (this.Options.verbose) this.Options.log('Terminating inactive/broken WebSocket: ' + ws.endpoint); |
| 1355 | if (ws.readyState === WebSocket.OPEN) ws.terminate(); |
| 1356 | } |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | /** |
| 1361 | * Called when socket is opened, subscriptions are registered for later reference |