Fixed the reconnection algorithm in the JS API.