diff --git a/core/rfb.js b/core/rfb.js index d83b691d..9d968bbe 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -233,11 +233,16 @@ case 'connecting': this._fail('Failed to connect to server' + msg); break; + case 'connected': + // Handle disconnects that were initiated server-side + this._updateConnectionState('disconnecting'); + this._updateConnectionState('disconnected'); + break; case 'disconnected': Util.Error("Received onclose while disconnected" + msg); break; default: - this._fail("Server disconnected" + msg); + this._fail("Unexpected server disconnect" + msg); break; } this._sock.off('close'); diff --git a/tests/test.rfb.js b/tests/test.rfb.js index b8bc9d22..828456af 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -2112,10 +2112,10 @@ describe('Remote Frame Buffer Protocol Client', function() { expect(client._rfb_connection_state).to.equal('disconnected'); }); - it('should transition to failed if we get a close event from any non-"disconnection" state', function () { + it('should fail if we get a close event while connecting', function () { sinon.spy(client, "_fail"); client.connect('host', 8675); - client._rfb_connection_state = 'connected'; + client._rfb_connection_state = 'connecting'; client._sock._websocket.close(); expect(client._fail).to.have.been.calledOnce; });