Remove RFB.notification()

This interface was a band aid for poor design. The two cases where it
was used was replaced by logging.
This commit is contained in:
Samuel Mannehed 2017-11-05 21:47:06 +01:00
parent 4e1c5435b8
commit 5b20d338ce
8 changed files with 7 additions and 114 deletions

View File

@ -532,10 +532,6 @@ var UI = {
document.getElementById('noVNC_status').classList.remove("noVNC_open"); document.getElementById('noVNC_status').classList.remove("noVNC_open");
}, },
notification: function (e) {
UI.showStatus(e.detail.message, e.detail.level);
},
activateControlbar: function(event) { activateControlbar: function(event) {
clearTimeout(UI.idleControlbarTimeout); clearTimeout(UI.idleControlbarTimeout);
// We manipulate the anchor instead of the actual control // We manipulate the anchor instead of the actual control
@ -1038,7 +1034,6 @@ var UI = {
{ shared: UI.getSetting('shared'), { shared: UI.getSetting('shared'),
repeaterID: UI.getSetting('repeaterID'), repeaterID: UI.getSetting('repeaterID'),
credentials: { password: password } }); credentials: { password: password } });
UI.rfb.addEventListener("notification", UI.notification);
UI.rfb.addEventListener("updatestate", UI.updateState); UI.rfb.addEventListener("updatestate", UI.updateState);
UI.rfb.addEventListener("disconnect", UI.disconnectFinished); UI.rfb.addEventListener("disconnect", UI.disconnectFinished);
UI.rfb.addEventListener("credentialsrequired", UI.credentials); UI.rfb.addEventListener("credentialsrequired", UI.credentials);

View File

@ -1,7 +1,7 @@
/* /*
* noVNC: HTML5 VNC client * noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin * Copyright (C) 2012 Joel Martin
* Copyright (C) 2016 Samuel Mannehed for Cendio AB * Copyright (C) 2017 Samuel Mannehed for Cendio AB
* Licensed under MPL 2.0 (see LICENSE.txt) * Licensed under MPL 2.0 (see LICENSE.txt)
* *
* See README.md for usage and integration instructions. * See README.md for usage and integration instructions.
@ -589,30 +589,6 @@ RFB.prototype = {
return false; return false;
}, },
/*
* Send a notification to the UI. Valid levels are:
* 'normal'|'warn'|'error'
*
* NOTE: If this function is called multiple times, remember that the
* interface could be only showing the latest notification.
*/
_notification: function(msg, level) {
switch (level) {
case 'normal':
case 'warn':
case 'error':
Log.Debug("Notification[" + level + "]:" + msg);
break;
default:
Log.Error("Invalid notification level: " + level);
return;
}
var event = new CustomEvent("notification",
{ detail: { message: msg, level: level } });
this.dispatchEvent(event);
},
_setCapability: function (cap, val) { _setCapability: function (cap, val) {
this._capabilities[cap] = val; this._capabilities[cap] = val;
var event = new CustomEvent("capabilities", var event = new CustomEvent("capabilities",
@ -1262,8 +1238,7 @@ RFB.prototype = {
switch (xvp_msg) { switch (xvp_msg) {
case 0: // XVP_FAIL case 0: // XVP_FAIL
Log.Error("Operation Failed"); Log.Error("XVP Operation Failed");
this._notification("XVP Operation Failed", 'error');
break; break;
case 1: // XVP_INIT case 1: // XVP_INIT
this._rfb_xvp_ver = xvp_ver; this._rfb_xvp_ver = xvp_ver;
@ -2350,8 +2325,8 @@ RFB.encodingHandlers = {
msg = "Unknown reason"; msg = "Unknown reason";
break; break;
} }
this._notification("Server did not accept the resize request: " Log.Warn("Server did not accept the resize request: "
+ msg, 'normal'); + msg);
} else { } else {
this._resize(this._FBU.width, this._FBU.height); this._resize(this._FBU.width, this._FBU.height);
} }

View File

@ -67,10 +67,6 @@ protocol stream.
- The `updatestate` event is fired when the connection state of the - The `updatestate` event is fired when the connection state of the
`RFB` object changes. `RFB` object changes.
[`notification`](#notification)
- The `notification` event is fired when the `RFB` usage has a
message to display to the user.
[`disconnect`](#disconnected) [`disconnect`](#disconnected)
- The `disconnect` event is fired when the `RFB` object disconnects. - The `disconnect` event is fired when the `RFB` object disconnects.
@ -200,23 +196,6 @@ Note that a `RFB` objects can not transition from the disconnected
state in any way, a new instance of the object has to be created for state in any way, a new instance of the object has to be created for
new connections. new connections.
#### notification
The `notification` event is fired when the `RFB` object wants a message
displayed to the user. The `detail` property is an `Object` containing
the following properties:
| Property | Type | Description
| --------- | ----------- | -----------
| `message` | `DOMString` | The message to display
| `level` | `DOMString` | The severity of the message
The following levels are currently defined:
- `"normal"`
- `"warn"`
- `"error"`
#### disconnect #### disconnect
The `disconnect` event is fired when the connection has been The `disconnect` event is fired when the connection has been

View File

@ -52,10 +52,6 @@ function enableUI() {
encoding = VNC_frame_encoding; encoding = VNC_frame_encoding;
} }
const notification = function (rfb, mesg, level, options) {
document.getElementById('VNC_status').textContent = mesg;
}
function IterationPlayer (iterations, frames, encoding) { function IterationPlayer (iterations, frames, encoding) {
this._iterations = iterations; this._iterations = iterations;
@ -72,7 +68,6 @@ function IterationPlayer (iterations, frames, encoding) {
this.onfinish = function() {}; this.onfinish = function() {};
this.oniterationfinish = function() {}; this.oniterationfinish = function() {};
this.rfbdisconnected = function() {}; this.rfbdisconnected = function() {};
this.rfbnotification = function() {};
} }
IterationPlayer.prototype = { IterationPlayer.prototype = {
@ -87,7 +82,7 @@ IterationPlayer.prototype = {
}, },
_nextIteration: function () { _nextIteration: function () {
const player = new RecordingPlayer(this._frames, this._encoding, this._disconnected.bind(this), this._notification.bind(this)); const player = new RecordingPlayer(this._frames, this._encoding, this._disconnected.bind(this));
player.onfinish = this._iterationFinish.bind(this); player.onfinish = this._iterationFinish.bind(this);
if (this._state !== 'running') { return; } if (this._state !== 'running') { return; }
@ -131,15 +126,6 @@ IterationPlayer.prototype = {
this.onrfbdisconnected(evt); this.onrfbdisconnected(evt);
}, },
_notification: function (rfb, msg, level, options) {
var evt = new Event('rfbnotification');
evt.message = msg;
evt.level = level;
evt.options = options;
this.onrfbnotification(evt);
},
}; };
function start() { function start() {
@ -167,9 +153,6 @@ function start() {
message(`noVNC sent disconnected during iteration ${evt.iteration} frame ${evt.frame}`); message(`noVNC sent disconnected during iteration ${evt.iteration} frame ${evt.frame}`);
} }
}; };
player.onrfbnotification = function (evt) {
document.getElementById('VNC_status').textContent = evt.message;
};
player.onfinish = function (evt) { player.onfinish = function (evt) {
const iterTime = parseInt(evt.duration / evt.iterations, 10); const iterTime = parseInt(evt.duration / evt.iterations, 10);
message(`${evt.iterations} iterations took ${evt.duration}ms (average ${iterTime}ms / iteration)`); message(`${evt.iterations} iterations took ${evt.duration}ms (average ${iterTime}ms / iteration)`);

View File

@ -44,12 +44,11 @@ if (setImmediate === undefined) {
window.addEventListener("message", _onMessage); window.addEventListener("message", _onMessage);
} }
export default function RecordingPlayer (frames, encoding, disconnected, notification) { export default function RecordingPlayer (frames, encoding, disconnected) {
this._frames = frames; this._frames = frames;
this._encoding = encoding; this._encoding = encoding;
this._disconnected = disconnected; this._disconnected = disconnected;
this._notification = notification;
if (this._encoding === undefined) { if (this._encoding === undefined) {
let frame = this._frames[0]; let frame = this._frames[0];
@ -80,7 +79,6 @@ RecordingPlayer.prototype = {
this._rfb = new RFB(document.getElementById('VNC_canvas'), 'wss://test'); this._rfb = new RFB(document.getElementById('VNC_canvas'), 'wss://test');
this._rfb.viewOnly = true; this._rfb.viewOnly = true;
this._rfb.ondisconnected = this._handleDisconnect.bind(this); this._rfb.ondisconnected = this._handleDisconnect.bind(this);
this._rfb.onnotification = this._notification;
this._enablePlaybackMode(); this._enablePlaybackMode();
// reset the frame index and timer // reset the frame index and timer

View File

@ -400,27 +400,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
}); });
}); });
describe('#_notification', function () {
var client;
beforeEach(function () { client = make_rfb(); });
it('should call the notification callback', function () {
var spy = sinon.spy();
client.addEventListener("notification", spy);
client._notification('notify!', 'warn');
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.message).to.equal('notify!');
expect(spy.args[0][0].detail.level).to.equal('warn');
});
it('should not call the notification callback when level is invalid', function () {
var spy = sinon.spy();
client.addEventListener("notification", spy);
client._notification('notify!', 'invalid');
expect(spy).to.not.have.been.called;
});
});
}); });
describe('Connection States', function () { describe('Connection States', function () {
@ -1589,14 +1568,6 @@ describe('Remote Frame Buffer Protocol Client', function() {
}); });
describe('XVP Message Handling', function () { describe('XVP Message Handling', function () {
it('should send a notification on XVP_FAIL', function () {
var spy = sinon.spy();
client.addEventListener("notification", spy);
client._sock._websocket._receive_data(new Uint8Array([250, 0, 10, 0]));
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.message).to.equal('XVP Operation Failed');
});
it('should set the XVP version and fire the callback with the version on XVP_INIT', function () { it('should set the XVP version and fire the callback with the version on XVP_INIT', function () {
var spy = sinon.spy(); var spy = sinon.spy();
client.addEventListener("capabilities", spy); client.addEventListener("capabilities", spy);

View File

@ -85,10 +85,6 @@
} }
} }
notification = function (rfb, mesg, level, options) {
document.getElementById('VNC_status').textContent = mesg;
}
function do_test() { function do_test() {
document.getElementById('startButton').value = "Running"; document.getElementById('startButton').value = "Running";
document.getElementById('startButton').disabled = true; document.getElementById('startButton').disabled = true;

View File

@ -188,9 +188,6 @@
status(e.detail.reason, "error"); status(e.detail.reason, "error");
} }
} }
function notification(e) {
status(e.detail.message, e.detail.level);
}
window.onresize = function () { window.onresize = function () {
// When the window has been resized, wait until the size remains // When the window has been resized, wait until the size remains
@ -272,8 +269,7 @@
{ repeaterID: WebUtil.getConfigVar('repeaterID', ''), { repeaterID: WebUtil.getConfigVar('repeaterID', ''),
shared: WebUtil.getConfigVar('shared', true), shared: WebUtil.getConfigVar('shared', true),
credentials: { password: password } }); credentials: { password: password } });
rfb.viewOnly = WebUtil.getConfigVar('view_only', false); rfb.viewOnly = WebUtil.getConfigVar('view_only', false);
rfb.addEventListener("notification", notification);
rfb.addEventListener("updatestate", updateState); rfb.addEventListener("updatestate", updateState);
rfb.addEventListener("disconnect", disconnect); rfb.addEventListener("disconnect", disconnect);
rfb.addEventListener("capabilities", function () { updatePowerButtons(); initialResize(); }); rfb.addEventListener("capabilities", function () { updatePowerButtons(); initialResize(); });