Improve the connection state names
Names such as 'disconnect' and 'disconnected' are inconsistent in the way that one describes an action and the other a state. The state that was called 'normal' didn't fit in with the others because the other names describe a connection state. The new names are: 'disconnecting', 'connecting' and 'connected'
This commit is contained in:
parent
52e9cc48b0
commit
c2a4d3ef86
10
app/ui.js
10
app/ui.js
|
@ -369,7 +369,7 @@ var UI;
|
||||||
// zero means no timeout
|
// zero means no timeout
|
||||||
UI.showStatus(msg, 'error', 0);
|
UI.showStatus(msg, 'error', 0);
|
||||||
break;
|
break;
|
||||||
case 'normal':
|
case 'connected':
|
||||||
/* falls through */
|
/* falls through */
|
||||||
case 'disconnected':
|
case 'disconnected':
|
||||||
case 'loaded':
|
case 'loaded':
|
||||||
|
@ -386,7 +386,7 @@ var UI;
|
||||||
|
|
||||||
// Disable/enable controls depending on connection state
|
// Disable/enable controls depending on connection state
|
||||||
updateVisualState: function() {
|
updateVisualState: function() {
|
||||||
var connected = UI.rfb && UI.rfb_state === 'normal';
|
var connected = UI.rfb && UI.rfb_state === 'connected';
|
||||||
|
|
||||||
//Util.Debug(">> updateVisualState");
|
//Util.Debug(">> updateVisualState");
|
||||||
document.getElementById('noVNC_setting_encrypt').disabled = connected;
|
document.getElementById('noVNC_setting_encrypt').disabled = connected;
|
||||||
|
@ -1062,7 +1062,7 @@ var UI;
|
||||||
|
|
||||||
var screen = UI.screenSize();
|
var screen = UI.screenSize();
|
||||||
|
|
||||||
if (screen && UI.rfb_state === 'normal' && UI.rfb.get_display()) {
|
if (screen && UI.rfb_state === 'connected' && UI.rfb.get_display()) {
|
||||||
|
|
||||||
var display = UI.rfb.get_display();
|
var display = UI.rfb.get_display();
|
||||||
var resizeMode = UI.getSetting('resize');
|
var resizeMode = UI.getSetting('resize');
|
||||||
|
@ -1187,7 +1187,7 @@ var UI;
|
||||||
// Handle special cases where clipping is forced on/off or locked
|
// Handle special cases where clipping is forced on/off or locked
|
||||||
enableDisableViewClip: function() {
|
enableDisableViewClip: function() {
|
||||||
var resizeSetting = document.getElementById('noVNC_setting_resize');
|
var resizeSetting = document.getElementById('noVNC_setting_resize');
|
||||||
var connected = UI.rfb && UI.rfb_state === 'normal';
|
var connected = UI.rfb && UI.rfb_state === 'connected';
|
||||||
|
|
||||||
if (UI.isSafari) {
|
if (UI.isSafari) {
|
||||||
// Safari auto-hides the scrollbars which makes them
|
// Safari auto-hides the scrollbars which makes them
|
||||||
|
@ -1243,7 +1243,7 @@ var UI;
|
||||||
updateViewDrag: function() {
|
updateViewDrag: function() {
|
||||||
var clipping = false;
|
var clipping = false;
|
||||||
|
|
||||||
if (UI.rfb_state !== 'normal') return;
|
if (UI.rfb_state !== 'connected') return;
|
||||||
|
|
||||||
// Check if viewport drag is possible. It is only possible
|
// Check if viewport drag is possible. It is only possible
|
||||||
// if the remote display is clipping the client display.
|
// if the remote display is clipping the client display.
|
||||||
|
|
60
core/rfb.js
60
core/rfb.js
|
@ -205,7 +205,7 @@
|
||||||
this._sock = new Websock();
|
this._sock = new Websock();
|
||||||
this._sock.on('message', this._handle_message.bind(this));
|
this._sock.on('message', this._handle_message.bind(this));
|
||||||
this._sock.on('open', function () {
|
this._sock.on('open', function () {
|
||||||
if ((this._rfb_connection_state === 'connect') &&
|
if ((this._rfb_connection_state === 'connecting') &&
|
||||||
(this._rfb_init_state === '')) {
|
(this._rfb_init_state === '')) {
|
||||||
this._rfb_init_state = 'ProtocolVersion';
|
this._rfb_init_state = 'ProtocolVersion';
|
||||||
Util.Debug("Starting VNC handshake");
|
Util.Debug("Starting VNC handshake");
|
||||||
|
@ -224,10 +224,10 @@
|
||||||
msg += ")";
|
msg += ")";
|
||||||
}
|
}
|
||||||
switch (this._rfb_connection_state) {
|
switch (this._rfb_connection_state) {
|
||||||
case 'disconnect':
|
case 'disconnecting':
|
||||||
this._updateConnectionState('disconnected', 'VNC disconnected' + msg);
|
this._updateConnectionState('disconnected', 'VNC disconnected' + msg);
|
||||||
break;
|
break;
|
||||||
case 'connect':
|
case 'connecting':
|
||||||
this._fail('Failed to connect to server' + msg);
|
this._fail('Failed to connect to server' + msg);
|
||||||
break;
|
break;
|
||||||
case 'failed':
|
case 'failed':
|
||||||
|
@ -267,12 +267,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this._rfb_init_state = '';
|
this._rfb_init_state = '';
|
||||||
this._updateConnectionState('connect');
|
this._updateConnectionState('connecting');
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
disconnect: function () {
|
disconnect: function () {
|
||||||
this._updateConnectionState('disconnect', 'Disconnecting');
|
this._updateConnectionState('disconnecting', 'Disconnecting');
|
||||||
this._sock.off('error');
|
this._sock.off('error');
|
||||||
this._sock.off('message');
|
this._sock.off('message');
|
||||||
this._sock.off('open');
|
this._sock.off('open');
|
||||||
|
@ -284,7 +284,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
sendCtrlAltDel: function () {
|
sendCtrlAltDel: function () {
|
||||||
if (this._rfb_connection_state !== 'normal' || this._view_only) { return false; }
|
if (this._rfb_connection_state !== 'connected' || this._view_only) { return false; }
|
||||||
Util.Info("Sending Ctrl-Alt-Del");
|
Util.Info("Sending Ctrl-Alt-Del");
|
||||||
|
|
||||||
RFB.messages.keyEvent(this._sock, KeyTable.XK_Control_L, 1);
|
RFB.messages.keyEvent(this._sock, KeyTable.XK_Control_L, 1);
|
||||||
|
@ -318,7 +318,7 @@
|
||||||
// Send a key press. If 'down' is not specified then send a down key
|
// Send a key press. If 'down' is not specified then send a down key
|
||||||
// followed by an up key.
|
// followed by an up key.
|
||||||
sendKey: function (code, down) {
|
sendKey: function (code, down) {
|
||||||
if (this._rfb_connection_state !== "normal" || this._view_only) { return false; }
|
if (this._rfb_connection_state !== 'connected' || this._view_only) { return false; }
|
||||||
if (typeof down !== 'undefined') {
|
if (typeof down !== 'undefined') {
|
||||||
Util.Info("Sending key code (" + (down ? "down" : "up") + "): " + code);
|
Util.Info("Sending key code (" + (down ? "down" : "up") + "): " + code);
|
||||||
RFB.messages.keyEvent(this._sock, code, down ? 1 : 0);
|
RFB.messages.keyEvent(this._sock, code, down ? 1 : 0);
|
||||||
|
@ -331,14 +331,14 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
clipboardPasteFrom: function (text) {
|
clipboardPasteFrom: function (text) {
|
||||||
if (this._rfb_connection_state !== 'normal') { return; }
|
if (this._rfb_connection_state !== 'connected') { return; }
|
||||||
RFB.messages.clientCutText(this._sock, text);
|
RFB.messages.clientCutText(this._sock, text);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Requests a change of remote desktop size. This message is an extension
|
// Requests a change of remote desktop size. This message is an extension
|
||||||
// and may only be sent if we have received an ExtendedDesktopSize message
|
// and may only be sent if we have received an ExtendedDesktopSize message
|
||||||
requestDesktopSize: function (width, height) {
|
requestDesktopSize: function (width, height) {
|
||||||
if (this._rfb_connection_state !== "normal") { return; }
|
if (this._rfb_connection_state !== 'connected') { return; }
|
||||||
|
|
||||||
if (this._supportsSetDesktopSize) {
|
if (this._supportsSetDesktopSize) {
|
||||||
RFB.messages.setDesktopSize(this._sock, width, height,
|
RFB.messages.setDesktopSize(this._sock, width, height,
|
||||||
|
@ -416,7 +416,7 @@
|
||||||
if (this._display && this._display.get_context()) {
|
if (this._display && this._display.get_context()) {
|
||||||
this._keyboard.ungrab();
|
this._keyboard.ungrab();
|
||||||
this._mouse.ungrab();
|
this._mouse.ungrab();
|
||||||
if (state !== 'connect' && state !== 'loaded') {
|
if (state !== 'connecting' && state !== 'loaded') {
|
||||||
this._display.defaultCursor();
|
this._display.defaultCursor();
|
||||||
}
|
}
|
||||||
if (Util.get_logging() !== 'debug' || state === 'loaded') {
|
if (Util.get_logging() !== 'debug' || state === 'loaded') {
|
||||||
|
@ -431,13 +431,13 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Connection states:
|
* Connection states:
|
||||||
* loaded - page load, equivalent to disconnected
|
* loaded - page load, equivalent to disconnected
|
||||||
* disconnected - idle state
|
* disconnected - idle state
|
||||||
* connect - starting to connect
|
* connecting
|
||||||
* normal - connected
|
* connected
|
||||||
* disconnect - starting to disconnect
|
* disconnecting
|
||||||
* failed - abnormal disconnect
|
* failed - abnormal disconnect
|
||||||
* fatal - failed to load page, or fatal error
|
* fatal - failed to load page, or fatal error
|
||||||
*/
|
*/
|
||||||
_updateConnectionState: function (state, statusMsg) {
|
_updateConnectionState: function (state, statusMsg) {
|
||||||
var oldstate = this._rfb_connection_state;
|
var oldstate = this._rfb_connection_state;
|
||||||
|
@ -454,8 +454,8 @@
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
if (state in {'disconnected': 1, 'loaded': 1, 'connect': 1,
|
if (state in {'disconnected': 1, 'loaded': 1, 'connecting': 1,
|
||||||
'disconnect': 1, 'failed': 1, 'fatal': 1}) {
|
'disconnecting': 1, 'failed': 1, 'fatal': 1}) {
|
||||||
this._cleanupSocket(state);
|
this._cleanupSocket(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,7 +475,7 @@
|
||||||
var smsg = "New state '" + state + "', was '" + oldstate + "'.";
|
var smsg = "New state '" + state + "', was '" + oldstate + "'.";
|
||||||
Util.Debug(smsg);
|
Util.Debug(smsg);
|
||||||
|
|
||||||
if (this._disconnTimer && state !== 'disconnect') {
|
if (this._disconnTimer && state !== 'disconnecting') {
|
||||||
Util.Debug("Clearing disconnect timer");
|
Util.Debug("Clearing disconnect timer");
|
||||||
clearTimeout(this._disconnTimer);
|
clearTimeout(this._disconnTimer);
|
||||||
this._disconnTimer = null;
|
this._disconnTimer = null;
|
||||||
|
@ -483,19 +483,19 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 'normal':
|
case 'connected':
|
||||||
if (oldstate === 'disconnected' || oldstate === 'failed') {
|
if (oldstate === 'disconnected' || oldstate === 'failed') {
|
||||||
Util.Error("Invalid transition from 'disconnected' or 'failed' to 'normal'");
|
Util.Error("Invalid transition from 'disconnected' or 'failed' to 'connected'");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'connect':
|
case 'connecting':
|
||||||
this._init_vars();
|
this._init_vars();
|
||||||
this._connect();
|
this._connect();
|
||||||
// WebSocket.onopen transitions to 'ProtocolVersion'
|
// WebSocket.onopen transitions to 'ProtocolVersion'
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'disconnect':
|
case 'disconnecting':
|
||||||
this._disconnTimer = setTimeout(function () {
|
this._disconnTimer = setTimeout(function () {
|
||||||
this._fail("Disconnect timeout");
|
this._fail("Disconnect timeout");
|
||||||
}.bind(this), this._disconnectTimeout * 1000);
|
}.bind(this), this._disconnectTimeout * 1000);
|
||||||
|
@ -508,7 +508,7 @@
|
||||||
case 'failed':
|
case 'failed':
|
||||||
if (oldstate === 'disconnected') {
|
if (oldstate === 'disconnected') {
|
||||||
Util.Error("Invalid transition from 'disconnected' to 'failed'");
|
Util.Error("Invalid transition from 'disconnected' to 'failed'");
|
||||||
} else if (oldstate === 'normal') {
|
} else if (oldstate === 'connected') {
|
||||||
Util.Error("Error while connected.");
|
Util.Error("Error while connected.");
|
||||||
} else if (oldstate === 'init') {
|
} else if (oldstate === 'init') {
|
||||||
Util.Error("Error while initializing.");
|
Util.Error("Error while initializing.");
|
||||||
|
@ -577,7 +577,7 @@
|
||||||
case 'failed':
|
case 'failed':
|
||||||
Util.Error("Got data while disconnected");
|
Util.Error("Got data while disconnected");
|
||||||
break;
|
break;
|
||||||
case 'normal':
|
case 'connected':
|
||||||
if (this._normal_msg() && this._sock.rQlen() > 0) {
|
if (this._normal_msg() && this._sock.rQlen() > 0) {
|
||||||
// true means we can continue processing
|
// true means we can continue processing
|
||||||
// Give other events a chance to run
|
// Give other events a chance to run
|
||||||
|
@ -644,7 +644,7 @@
|
||||||
|
|
||||||
if (this._view_only) { return; } // View only, skip mouse events
|
if (this._view_only) { return; } // View only, skip mouse events
|
||||||
|
|
||||||
if (this._rfb_connection_state !== "normal") { return; }
|
if (this._rfb_connection_state !== 'connected') { return; }
|
||||||
RFB.messages.pointerEvent(this._sock, this._display.absX(x), this._display.absY(y), this._mouse_buttonMask);
|
RFB.messages.pointerEvent(this._sock, this._display.absX(x), this._display.absY(y), this._mouse_buttonMask);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -671,7 +671,7 @@
|
||||||
|
|
||||||
if (this._view_only) { return; } // View only, skip mouse events
|
if (this._view_only) { return; } // View only, skip mouse events
|
||||||
|
|
||||||
if (this._rfb_connection_state !== "normal") { return; }
|
if (this._rfb_connection_state !== 'connected') { return; }
|
||||||
RFB.messages.pointerEvent(this._sock, this._display.absX(x), this._display.absY(y), this._mouse_buttonMask);
|
RFB.messages.pointerEvent(this._sock, this._display.absX(x), this._display.absY(y), this._mouse_buttonMask);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1058,9 +1058,9 @@
|
||||||
this._timing.pixels = 0;
|
this._timing.pixels = 0;
|
||||||
|
|
||||||
if (this._encrypt) {
|
if (this._encrypt) {
|
||||||
this._updateConnectionState('normal', 'Connected (encrypted) to: ' + this._fb_name);
|
this._updateConnectionState('connected', 'Connected (encrypted) to: ' + this._fb_name);
|
||||||
} else {
|
} else {
|
||||||
this._updateConnectionState('normal', 'Connected (unencrypted) to: ' + this._fb_name);
|
this._updateConnectionState('connected', 'Connected (unencrypted) to: ' + this._fb_name);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
@ -1275,7 +1275,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
while (this._FBU.rects > 0) {
|
while (this._FBU.rects > 0) {
|
||||||
if (this._rfb_connection_state !== "normal") { return false; }
|
if (this._rfb_connection_state !== 'connected') { return false; }
|
||||||
|
|
||||||
if (this._sock.rQwait("FBU", this._FBU.bytes)) { return false; }
|
if (this._sock.rQwait("FBU", this._FBU.bytes)) { return false; }
|
||||||
if (this._FBU.bytes === 0) {
|
if (this._FBU.bytes === 0) {
|
||||||
|
|
|
@ -67,10 +67,10 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
describe('#connect', function () {
|
describe('#connect', function () {
|
||||||
beforeEach(function () { client._updateConnectionState = sinon.spy(); });
|
beforeEach(function () { client._updateConnectionState = sinon.spy(); });
|
||||||
|
|
||||||
it('should set the current state to "connect"', function () {
|
it('should set the current state to "connecting"', function () {
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
expect(client._updateConnectionState).to.have.been.calledOnce;
|
expect(client._updateConnectionState).to.have.been.calledOnce;
|
||||||
expect(client._updateConnectionState).to.have.been.calledWith('connect');
|
expect(client._updateConnectionState).to.have.been.calledWith('connecting');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if we are missing a host', function () {
|
it('should fail if we are missing a host', function () {
|
||||||
|
@ -97,10 +97,10 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
describe('#disconnect', function () {
|
describe('#disconnect', function () {
|
||||||
beforeEach(function () { client._updateConnectionState = sinon.spy(); });
|
beforeEach(function () { client._updateConnectionState = sinon.spy(); });
|
||||||
|
|
||||||
it('should set the current state to "disconnect"', function () {
|
it('should set the current state to "disconnecting"', function () {
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
expect(client._updateConnectionState).to.have.been.calledOnce;
|
expect(client._updateConnectionState).to.have.been.calledOnce;
|
||||||
expect(client._updateConnectionState).to.have.been.calledWith('disconnect');
|
expect(client._updateConnectionState).to.have.been.calledWith('disconnecting');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should unregister error event handler', function () {
|
it('should unregister error event handler', function () {
|
||||||
|
@ -145,7 +145,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client._sock.open('ws://', 'binary');
|
client._sock.open('ws://', 'binary');
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
sinon.spy(client._sock, 'flush');
|
sinon.spy(client._sock, 'flush');
|
||||||
client._rfb_connection_state = "normal";
|
client._rfb_connection_state = 'connected';
|
||||||
client._view_only = false;
|
client._view_only = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client._sock.open('ws://', 'binary');
|
client._sock.open('ws://', 'binary');
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
sinon.spy(client._sock, 'flush');
|
sinon.spy(client._sock, 'flush');
|
||||||
client._rfb_connection_state = "normal";
|
client._rfb_connection_state = 'connected';
|
||||||
client._view_only = false;
|
client._view_only = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client._sock.open('ws://', 'binary');
|
client._sock.open('ws://', 'binary');
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
sinon.spy(client._sock, 'flush');
|
sinon.spy(client._sock, 'flush');
|
||||||
client._rfb_connection_state = "normal";
|
client._rfb_connection_state = 'connected';
|
||||||
client._view_only = false;
|
client._view_only = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client._sock.open('ws://', 'binary');
|
client._sock.open('ws://', 'binary');
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
sinon.spy(client._sock, 'flush');
|
sinon.spy(client._sock, 'flush');
|
||||||
client._rfb_connection_state = "normal";
|
client._rfb_connection_state = 'connected';
|
||||||
client._view_only = false;
|
client._view_only = false;
|
||||||
client._supportsSetDesktopSize = true;
|
client._supportsSetDesktopSize = true;
|
||||||
});
|
});
|
||||||
|
@ -285,7 +285,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client._sock.open('ws://', 'binary');
|
client._sock.open('ws://', 'binary');
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
sinon.spy(client._sock, 'flush');
|
sinon.spy(client._sock, 'flush');
|
||||||
client._rfb_connection_state = "normal";
|
client._rfb_connection_state = 'connected';
|
||||||
client._view_only = false;
|
client._view_only = false;
|
||||||
client._rfb_xvp_ver = 1;
|
client._rfb_xvp_ver = 1;
|
||||||
});
|
});
|
||||||
|
@ -329,10 +329,10 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
this.clock.restore();
|
this.clock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clear the disconnect timer if the state is not disconnect', function () {
|
it('should clear the disconnect timer if the state is not "disconnecting"', function () {
|
||||||
var spy = sinon.spy();
|
var spy = sinon.spy();
|
||||||
client._disconnTimer = setTimeout(spy, 50);
|
client._disconnTimer = setTimeout(spy, 50);
|
||||||
client._updateConnectionState('normal');
|
client._updateConnectionState('connected');
|
||||||
this.clock.tick(51);
|
this.clock.tick(51);
|
||||||
expect(spy).to.not.have.been.called;
|
expect(spy).to.not.have.been.called;
|
||||||
expect(client._disconnTimer).to.be.null;
|
expect(client._disconnTimer).to.be.null;
|
||||||
|
@ -388,33 +388,33 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('connect', function () {
|
describe('connecting', function () {
|
||||||
var client;
|
var client;
|
||||||
beforeEach(function () { client = make_rfb(); });
|
beforeEach(function () { client = make_rfb(); });
|
||||||
|
|
||||||
it('should reset the variable states', function () {
|
it('should reset the variable states', function () {
|
||||||
sinon.spy(client, '_init_vars');
|
sinon.spy(client, '_init_vars');
|
||||||
client._updateConnectionState('connect');
|
client._updateConnectionState('connecting');
|
||||||
expect(client._init_vars).to.have.been.calledOnce;
|
expect(client._init_vars).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should actually connect to the websocket', function () {
|
it('should actually connect to the websocket', function () {
|
||||||
sinon.spy(client._sock, 'open');
|
sinon.spy(client._sock, 'open');
|
||||||
client._updateConnectionState('connect');
|
client._updateConnectionState('connecting');
|
||||||
expect(client._sock.open).to.have.been.calledOnce;
|
expect(client._sock.open).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use wss:// to connect if encryption is enabled', function () {
|
it('should use wss:// to connect if encryption is enabled', function () {
|
||||||
sinon.spy(client._sock, 'open');
|
sinon.spy(client._sock, 'open');
|
||||||
client.set_encrypt(true);
|
client.set_encrypt(true);
|
||||||
client._updateConnectionState('connect');
|
client._updateConnectionState('connecting');
|
||||||
expect(client._sock.open.args[0][0]).to.contain('wss://');
|
expect(client._sock.open.args[0][0]).to.contain('wss://');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use ws:// to connect if encryption is not enabled', function () {
|
it('should use ws:// to connect if encryption is not enabled', function () {
|
||||||
sinon.spy(client._sock, 'open');
|
sinon.spy(client._sock, 'open');
|
||||||
client.set_encrypt(true);
|
client.set_encrypt(true);
|
||||||
client._updateConnectionState('connect');
|
client._updateConnectionState('connecting');
|
||||||
expect(client._sock.open.args[0][0]).to.contain('wss://');
|
expect(client._sock.open.args[0][0]).to.contain('wss://');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -424,18 +424,18 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client._rfb_host = 'HOST';
|
client._rfb_host = 'HOST';
|
||||||
client._rfb_port = 8675;
|
client._rfb_port = 8675;
|
||||||
client._rfb_path = 'PATH';
|
client._rfb_path = 'PATH';
|
||||||
client._updateConnectionState('connect');
|
client._updateConnectionState('connecting');
|
||||||
expect(client._sock.open).to.have.been.calledWith('ws://HOST:8675/PATH');
|
expect(client._sock.open).to.have.been.calledWith('ws://HOST:8675/PATH');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should attempt to close the websocket before we open an new one', function () {
|
it('should attempt to close the websocket before we open an new one', function () {
|
||||||
sinon.spy(client._sock, 'close');
|
sinon.spy(client._sock, 'close');
|
||||||
client._updateConnectionState('connect');
|
client._updateConnectionState('connecting');
|
||||||
expect(client._sock.close).to.have.been.calledOnce;
|
expect(client._sock.close).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('disconnect', function () {
|
describe('disconnecting', function () {
|
||||||
var client;
|
var client;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.clock = sinon.useFakeTimers();
|
this.clock = sinon.useFakeTimers();
|
||||||
|
@ -449,13 +449,13 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
|
|
||||||
it('should fail if we do not call Websock.onclose within the disconnection timeout', function () {
|
it('should fail if we do not call Websock.onclose within the disconnection timeout', function () {
|
||||||
client._sock._websocket.close = function () {}; // explicitly don't call onclose
|
client._sock._websocket.close = function () {}; // explicitly don't call onclose
|
||||||
client._updateConnectionState('disconnect');
|
client._updateConnectionState('disconnecting');
|
||||||
this.clock.tick(client.get_disconnectTimeout() * 1000);
|
this.clock.tick(client.get_disconnectTimeout() * 1000);
|
||||||
expect(client._rfb_connection_state).to.equal('failed');
|
expect(client._rfb_connection_state).to.equal('failed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not fail if Websock.onclose gets called within the disconnection timeout', function () {
|
it('should not fail if Websock.onclose gets called within the disconnection timeout', function () {
|
||||||
client._updateConnectionState('disconnect');
|
client._updateConnectionState('disconnecting');
|
||||||
this.clock.tick(client.get_disconnectTimeout() * 500);
|
this.clock.tick(client.get_disconnectTimeout() * 500);
|
||||||
client._sock._websocket.close();
|
client._sock._websocket.close();
|
||||||
this.clock.tick(client.get_disconnectTimeout() * 500 + 1);
|
this.clock.tick(client.get_disconnectTimeout() * 500 + 1);
|
||||||
|
@ -464,7 +464,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
|
|
||||||
it('should close the WebSocket connection', function () {
|
it('should close the WebSocket connection', function () {
|
||||||
sinon.spy(client._sock, 'close');
|
sinon.spy(client._sock, 'close');
|
||||||
client._updateConnectionState('disconnect');
|
client._updateConnectionState('disconnecting');
|
||||||
expect(client._sock.close).to.have.been.calledTwice; // once on loaded, once on disconnect
|
expect(client._sock.close).to.have.been.calledTwice; // once on loaded, once on disconnect
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -513,7 +513,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// NB(directxman12): Normal does *nothing* in updateConnectionState
|
// NB(directxman12): Connected does *nothing* in updateConnectionState
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Protocol Initialization States', function () {
|
describe('Protocol Initialization States', function () {
|
||||||
|
@ -1069,7 +1069,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
}
|
}
|
||||||
client._sock._websocket._receive_data(tight_data);
|
client._sock._websocket._receive_data(tight_data);
|
||||||
|
|
||||||
expect(client._rfb_connection_state).to.equal('normal');
|
expect(client._rfb_connection_state).to.equal('connected');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set the true color mode on the display to the configuration variable', function () {
|
it('should set the true color mode on the display to the configuration variable', function () {
|
||||||
|
@ -1131,9 +1131,9 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
expect(client._sock).to.have.sent(expected._sQ);
|
expect(client._sock).to.have.sent(expected._sQ);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should transition to the "normal" state', function () {
|
it('should transition to the "connected" state', function () {
|
||||||
send_server_init({}, client);
|
send_server_init({}, client);
|
||||||
expect(client._rfb_connection_state).to.equal('normal');
|
expect(client._rfb_connection_state).to.equal('connected');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1145,7 +1145,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client = make_rfb();
|
client = make_rfb();
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
client._fb_name = 'some device';
|
client._fb_name = 'some device';
|
||||||
client._fb_width = 640;
|
client._fb_width = 640;
|
||||||
client._fb_height = 20;
|
client._fb_height = 20;
|
||||||
|
@ -1158,7 +1158,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client = make_rfb();
|
client = make_rfb();
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
client._fb_name = 'some device';
|
client._fb_name = 'some device';
|
||||||
client._fb_width = 640;
|
client._fb_width = 640;
|
||||||
client._fb_height = 20;
|
client._fb_height = 20;
|
||||||
|
@ -1348,7 +1348,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client = make_rfb();
|
client = make_rfb();
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
client._fb_name = 'some device';
|
client._fb_name = 'some device';
|
||||||
// a really small frame
|
// a really small frame
|
||||||
client._fb_width = 4;
|
client._fb_width = 4;
|
||||||
|
@ -1425,7 +1425,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client = make_rfb();
|
client = make_rfb();
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
client._fb_name = 'some device';
|
client._fb_name = 'some device';
|
||||||
// a really small frame
|
// a really small frame
|
||||||
client._fb_width = 4;
|
client._fb_width = 4;
|
||||||
|
@ -1601,7 +1601,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client = make_rfb();
|
client = make_rfb();
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
client._fb_name = 'some device';
|
client._fb_name = 'some device';
|
||||||
client._supportsSetDesktopSize = false;
|
client._supportsSetDesktopSize = false;
|
||||||
// a really small frame
|
// a really small frame
|
||||||
|
@ -1743,7 +1743,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client = make_rfb();
|
client = make_rfb();
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
client._fb_name = 'some device';
|
client._fb_name = 'some device';
|
||||||
client._fb_width = 27;
|
client._fb_width = 27;
|
||||||
client._fb_height = 32;
|
client._fb_height = 32;
|
||||||
|
@ -1873,7 +1873,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client._sock.open('ws://', 'binary');
|
client._sock.open('ws://', 'binary');
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
sinon.spy(client._sock, 'flush');
|
sinon.spy(client._sock, 'flush');
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not send button messages in view-only mode', function () {
|
it('should not send button messages in view-only mode', function () {
|
||||||
|
@ -2014,15 +2014,15 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
// message events
|
// message events
|
||||||
it ('should do nothing if we receive an empty message and have nothing in the queue', function () {
|
it ('should do nothing if we receive an empty message and have nothing in the queue', function () {
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
client._normal_msg = sinon.spy();
|
client._normal_msg = sinon.spy();
|
||||||
client._sock._websocket._receive_data(new Uint8Array([]));
|
client._sock._websocket._receive_data(new Uint8Array([]));
|
||||||
expect(client._normal_msg).to.not.have.been.called;
|
expect(client._normal_msg).to.not.have.been.called;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle a message in the normal state as a normal message', function () {
|
it('should handle a message in the connected state as a normal message', function () {
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
client._normal_msg = sinon.spy();
|
client._normal_msg = sinon.spy();
|
||||||
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
|
client._sock._websocket._receive_data(new Uint8Array([1, 2, 3]));
|
||||||
expect(client._normal_msg).to.have.been.calledOnce;
|
expect(client._normal_msg).to.have.been.calledOnce;
|
||||||
|
@ -2039,7 +2039,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
it('should split up the handling of muplitle normal messages across 10ms intervals', function () {
|
it('should split up the handling of muplitle normal messages across 10ms intervals', function () {
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
client.set_onBell(sinon.spy());
|
client.set_onBell(sinon.spy());
|
||||||
client._sock._websocket._receive_data(new Uint8Array([0x02, 0x02]));
|
client._sock._websocket._receive_data(new Uint8Array([0x02, 0x02]));
|
||||||
expect(client.get_onBell()).to.have.been.calledOnce;
|
expect(client.get_onBell()).to.have.been.calledOnce;
|
||||||
|
@ -2048,7 +2048,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// open events
|
// open events
|
||||||
it('should update the state to ProtocolVersion on open (if the state is "connect")', function () {
|
it('should update the state to ProtocolVersion on open (if the state is "connecting")', function () {
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._sock._websocket._open();
|
client._sock._websocket._open();
|
||||||
expect(client._rfb_init_state).to.equal('ProtocolVersion');
|
expect(client._rfb_init_state).to.equal('ProtocolVersion');
|
||||||
|
@ -2062,16 +2062,16 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// close events
|
// close events
|
||||||
it('should transition to "disconnected" from "disconnect" on a close event', function () {
|
it('should transition to "disconnected" from "disconnecting" on a close event', function () {
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._rfb_connection_state = 'disconnect';
|
client._rfb_connection_state = 'disconnecting';
|
||||||
client._sock._websocket.close();
|
client._sock._websocket.close();
|
||||||
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 transition to failed if we get a close event from any non-"disconnection" state', function () {
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._rfb_connection_state = 'normal';
|
client._rfb_connection_state = 'connected';
|
||||||
client._sock._websocket.close();
|
client._sock._websocket.close();
|
||||||
expect(client._rfb_connection_state).to.equal('failed');
|
expect(client._rfb_connection_state).to.equal('failed');
|
||||||
});
|
});
|
||||||
|
@ -2079,7 +2079,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
it('should unregister close event handler', function () {
|
it('should unregister close event handler', function () {
|
||||||
sinon.spy(client._sock, 'off');
|
sinon.spy(client._sock, 'off');
|
||||||
client.connect('host', 8675);
|
client.connect('host', 8675);
|
||||||
client._rfb_connection_state = 'disconnect';
|
client._rfb_connection_state = 'disconnecting';
|
||||||
client._sock._websocket.close();
|
client._sock._websocket.close();
|
||||||
expect(client._sock.off).to.have.been.calledWith('close');
|
expect(client._sock.off).to.have.been.calledWith('close');
|
||||||
});
|
});
|
||||||
|
|
|
@ -143,13 +143,13 @@
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 'failed': level = "error"; break;
|
case 'failed': level = "error"; break;
|
||||||
case 'fatal': level = "error"; break;
|
case 'fatal': level = "error"; break;
|
||||||
case 'normal': level = "normal"; break;
|
case 'connected': level = "normal"; break;
|
||||||
case 'disconnected': level = "normal"; break;
|
case 'disconnected': level = "normal"; break;
|
||||||
case 'loaded': level = "normal"; break;
|
case 'loaded': level = "normal"; break;
|
||||||
default: level = "warn"; break;
|
default: level = "warn"; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state === "normal") {
|
if (state === 'connected') {
|
||||||
cad.disabled = false;
|
cad.disabled = false;
|
||||||
} else {
|
} else {
|
||||||
cad.disabled = true;
|
cad.disabled = true;
|
||||||
|
|
Loading…
Reference in New Issue