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'.
This commit is contained in:
Samuel Mannehed 2016-11-08 16:33:01 +01:00
parent e48d1b254e
commit b45905ab86
2 changed files with 8 additions and 3 deletions

View File

@ -233,11 +233,16 @@
case 'connecting': case 'connecting':
this._fail('Failed to connect to server' + msg); this._fail('Failed to connect to server' + msg);
break; break;
case 'connected':
// Handle disconnects that were initiated server-side
this._updateConnectionState('disconnecting');
this._updateConnectionState('disconnected');
break;
case 'disconnected': case 'disconnected':
Util.Error("Received onclose while disconnected" + msg); Util.Error("Received onclose while disconnected" + msg);
break; break;
default: default:
this._fail("Server disconnected" + msg); this._fail("Unexpected server disconnect" + msg);
break; break;
} }
this._sock.off('close'); this._sock.off('close');

View File

@ -2112,10 +2112,10 @@ describe('Remote Frame Buffer Protocol Client', function() {
expect(client._rfb_connection_state).to.equal('disconnected'); 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"); sinon.spy(client, "_fail");
client.connect('host', 8675); client.connect('host', 8675);
client._rfb_connection_state = 'connected'; client._rfb_connection_state = 'connecting';
client._sock._websocket.close(); client._sock._websocket.close();
expect(client._fail).to.have.been.calledOnce; expect(client._fail).to.have.been.calledOnce;
}); });