summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Mannehed <samuel@cendio.se>2016-08-29 15:04:11 +0200
committerSamuel Mannehed <samuel@cendio.se>2016-10-01 01:30:02 +0200
commit159c50c0096908fedb8e05d21098acd3679ef550 (patch)
treea87035282759b474f35afc75459a28ed71bc9db1
parentd5bbe50eb5990b6ba744e894de8fce84e487588a (diff)
downloadnovnc-159c50c0096908fedb8e05d21098acd3679ef550.tar.gz
Clean up special state handling for 'failed'
-rw-r--r--core/rfb.js25
-rw-r--r--tests/test.rfb.js2
2 files changed, 12 insertions, 15 deletions
diff --git a/core/rfb.js b/core/rfb.js
index 7b86579..e9cfc32 100644
--- a/core/rfb.js
+++ b/core/rfb.js
@@ -446,6 +446,8 @@
return;
}
+ this._rfb_state = state;
+
/*
* These are disconnected states. A previous connect may
* asynchronously cause a connection so make sure we are closed.
@@ -467,14 +469,7 @@
Util.Warn(cmsg);
}
- if (oldstate === 'failed' && state === 'disconnected') {
- // do disconnect action, but stay in failed state
- this._rfb_state = 'failed';
- } else {
- this._rfb_state = state;
- }
-
- if (this._disconnTimer && this._rfb_state !== 'disconnect') {
+ if (this._disconnTimer && state !== 'disconnect') {
Util.Debug("Clearing disconnect timer");
clearTimeout(this._disconnTimer);
this._disconnTimer = null;
@@ -512,12 +507,6 @@
} else if (oldstate === 'init') {
Util.Error("Error while initializing.");
}
-
- // Make sure we transition to disconnected
- setTimeout(function () {
- this._updateState('disconnected');
- }.bind(this), 50);
-
break;
default:
@@ -525,10 +514,18 @@
}
if (oldstate === 'failed' && state === 'disconnected') {
+ // do disconnect action, but stay in failed state and
+ // keep the previous status message
+ this._rfb_state = 'failed';
this._onUpdateState(this, state, oldstate);
} else {
this._onUpdateState(this, state, oldstate, statusMsg);
}
+
+ // Make sure we transition to disconnected
+ if (state === 'failed') {
+ this._updateState('disconnected');
+ }
},
_fail: function (msg) {
diff --git a/tests/test.rfb.js b/tests/test.rfb.js
index d6f1a1f..34edd26 100644
--- a/tests/test.rfb.js
+++ b/tests/test.rfb.js
@@ -677,7 +677,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
sinon.spy(client, '_fail');
client._sock._websocket._receive_data(failure_data);
- expect(client._fail).to.have.been.calledTwice;
+ expect(client._fail).to.have.been.calledOnce;
expect(client._fail).to.have.been.calledWith('Security failure: whoops');
});