From b45905ab863903ba0d1894fca9b4110a1a7d1004 Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Tue, 8 Nov 2016 16:33:01 +0100 Subject: [PATCH] Handle server-side disconnections Don't handle socket-close events when connected as errors. You could for example, in the VNC session run 'vncconfig -disconnect'. --- core/rfb.js | 7 ++++++- tests/test.rfb.js | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) 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; });