summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Mannehed <samuel@cendio.se>2016-11-08 16:33:01 +0100
committerSamuel Mannehed <samuel@cendio.se>2016-11-10 14:33:29 +0100
commitb45905ab863903ba0d1894fca9b4110a1a7d1004 (patch)
tree5618e87b64b2252cc45361119fa99f795127327c
parente48d1b254ea14a3679fc40e241cf80176343fca1 (diff)
downloadnovnc-b45905ab863903ba0d1894fca9b4110a1a7d1004.tar.gz
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'.
-rw-r--r--core/rfb.js7
-rw-r--r--tests/test.rfb.js4
2 files changed, 8 insertions, 3 deletions
diff --git a/core/rfb.js b/core/rfb.js
index d83b691..9d968bb 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 b8bc9d2..828456a 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;
});