| 628 | * @return {undefined} |
| 629 | */ |
| 630 | const socketHeartbeat = () => { |
| 631 | /* Sockets removed from `subscriptions` during a manual terminate() |
| 632 | will no longer be at risk of having functions called on them */ |
| 633 | for (let endpointId in Binance.subscriptions) { |
| 634 | const ws = Binance.subscriptions[endpointId]; |
| 635 | if (ws.isAlive) { |
| 636 | ws.isAlive = false; |
| 637 | if (ws.readyState === WebSocket.OPEN) ws.ping(noop); |
| 638 | } else { |
| 639 | if (Binance.options.verbose) Binance.options.log('Terminating inactive/broken WebSocket: ' + ws.endpoint); |
| 640 | if (ws.readyState === WebSocket.OPEN) ws.terminate(); |
| 641 | } |
| 642 | } |
| 643 | }; |
| 644 | |
| 645 | /** |
| 646 | * Called when socket is opened, subscriptions are registered for later reference |