Clean up special state handling for 'failed'

This commit is contained in:
Samuel Mannehed 2016-08-29 15:04:11 +02:00
parent d5bbe50eb5
commit 159c50c009
2 changed files with 12 additions and 15 deletions

View File

@ -446,6 +446,8 @@
return; return;
} }
this._rfb_state = state;
/* /*
* These are disconnected states. A previous connect may * These are disconnected states. A previous connect may
* asynchronously cause a connection so make sure we are closed. * asynchronously cause a connection so make sure we are closed.
@ -467,14 +469,7 @@
Util.Warn(cmsg); Util.Warn(cmsg);
} }
if (oldstate === 'failed' && state === 'disconnected') { if (this._disconnTimer && state !== 'disconnect') {
// do disconnect action, but stay in failed state
this._rfb_state = 'failed';
} else {
this._rfb_state = state;
}
if (this._disconnTimer && this._rfb_state !== 'disconnect') {
Util.Debug("Clearing disconnect timer"); Util.Debug("Clearing disconnect timer");
clearTimeout(this._disconnTimer); clearTimeout(this._disconnTimer);
this._disconnTimer = null; this._disconnTimer = null;
@ -512,12 +507,6 @@
} else if (oldstate === 'init') { } else if (oldstate === 'init') {
Util.Error("Error while initializing."); Util.Error("Error while initializing.");
} }
// Make sure we transition to disconnected
setTimeout(function () {
this._updateState('disconnected');
}.bind(this), 50);
break; break;
default: default:
@ -525,10 +514,18 @@
} }
if (oldstate === 'failed' && state === 'disconnected') { 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); this._onUpdateState(this, state, oldstate);
} else { } else {
this._onUpdateState(this, state, oldstate, statusMsg); this._onUpdateState(this, state, oldstate, statusMsg);
} }
// Make sure we transition to disconnected
if (state === 'failed') {
this._updateState('disconnected');
}
}, },
_fail: function (msg) { _fail: function (msg) {

View File

@ -677,7 +677,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
sinon.spy(client, '_fail'); sinon.spy(client, '_fail');
client._sock._websocket._receive_data(failure_data); 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'); expect(client._fail).to.have.been.calledWith('Security failure: whoops');
}); });