()
| 23 | } |
| 24 | |
| 25 | function closeSocket() { |
| 26 | if (heartbeatInterval) clearInterval(heartbeatInterval); |
| 27 | heartbeatInterval = null; |
| 28 | if (reconnectTimeout) clearTimeout(reconnectTimeout); |
| 29 | reconnectTimeout = null; |
| 30 | if (ws) { |
| 31 | try { |
| 32 | ws.close(); |
| 33 | } catch (e) { |
| 34 | console.log("[Flow2API] Close socket error", e); |
| 35 | } |
| 36 | ws = null; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | function sleep(ms) { |
| 41 | return new Promise(resolve => setTimeout(resolve, ms)); |