* Terminate a WebSocket API connection * @param {string} connectionId - connection identifier * @param {boolean} reconnect - whether to reconnect * @return {undefined}
(connectionId: string, reconnect = false)
| 1690 | * @return {undefined} |
| 1691 | */ |
| 1692 | terminateWsApi(connectionId: string, reconnect = false) { |
| 1693 | if (this.Options.verbose) this.Options.log('WebSocket API terminating:', connectionId); |
| 1694 | const ws = this.wsApiConnections[connectionId]; |
| 1695 | if (!ws) return; |
| 1696 | ws.removeAllListeners('message'); |
| 1697 | ws.reconnect = reconnect; |
| 1698 | ws.terminate(); |
| 1699 | delete this.wsApiConnections[connectionId]; |
| 1700 | |
| 1701 | // Reject all pending requests for this connection |
| 1702 | const pendingIds = Object.keys(this.wsApiPendingRequests); |
| 1703 | for (const requestId of pendingIds) { |
| 1704 | const pending = this.wsApiPendingRequests[requestId]; |
| 1705 | if (pending && pending.connectionId === connectionId) { |
| 1706 | pending.reject(new Error('WebSocket API connection terminated')); |
| 1707 | } |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | /** |
| 1712 | * Futures heartbeat code with a shared single interval tick |