| 664 | * @return {undefined} |
| 665 | */ |
| 666 | const handleSocketClose = function (reconnect, code, reason) { |
| 667 | delete Binance.subscriptions[this.endpoint]; |
| 668 | if (Binance.subscriptions && Object.keys(Binance.subscriptions).length === 0) { |
| 669 | clearInterval(Binance.socketHeartbeatInterval); |
| 670 | } |
| 671 | Binance.options.log('WebSocket closed: ' + this.endpoint + |
| 672 | (code ? ' (' + code + ')' : '') + |
| 673 | (reason ? ' ' + reason : '')); |
| 674 | if (Binance.options.reconnect && this.reconnect && reconnect) { |
| 675 | if (this.endpoint && parseInt(this.endpoint.length, 10) === 60) Binance.options.log('Account data WebSocket reconnecting...'); |
| 676 | else Binance.options.log('WebSocket reconnecting: ' + this.endpoint + '...'); |
| 677 | try { |
| 678 | reconnect(); |
| 679 | } catch (error) { |
| 680 | Binance.options.log('WebSocket reconnect error: ' + error.message); |
| 681 | } |
| 682 | } |
| 683 | }; |
| 684 | |
| 685 | /** |
| 686 | * Called when socket errors |