initRFB: function() {
try {
- UI.rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
- 'onNotification': UI.notification,
+ UI.rfb = new RFB(document.getElementById('noVNC_canvas'),
+ {'onNotification': UI.notification,
'onUpdateState': UI.updateState,
'onDisconnected': UI.disconnectFinished,
'onCredentialsRequired': UI.credentials,
document.getElementById("noVNC_keyboard_button")
.addEventListener('click', UI.toggleVirtualKeyboard);
- UI.touchKeyboard = new Keyboard({target: document.getElementById('noVNC_keyboardinput'),
- onKeyEvent: UI.keyEvent});
+ UI.touchKeyboard = new Keyboard(document.getElementById('noVNC_keyboardinput'),
+ {onKeyEvent: UI.keyEvent});
UI.touchKeyboard.grab();
document.getElementById("noVNC_keyboardinput")
.addEventListener('input', UI.keyInput);
UI.closeAllPanels();
UI.closeConnectPanel();
- UI.rfb.set_shared(UI.getSetting('shared'));
- UI.rfb.set_repeaterID(UI.getSetting('repeaterID'));
-
UI.updateLocalCursor();
UI.updateViewOnly();
}
url += '/' + path;
- UI.rfb.connect(url, { password: password });
+ UI.rfb.connect(url, { shared: UI.getSetting('shared'),
+ repeaterID: UI.getSetting('repeaterID'),
+ credentials: { password: password } });
},
disconnect: function() {
import * as Log from './util/logging.js';
import Base64 from "./base64.js";
-export default function Display(defaults) {
+export default function Display(target, defaults) {
this._drawCtx = null;
this._c_forceCanvas = false;
Log.Debug(">> Display.constructor");
// The visible canvas
+ this._target = target;
+
if (!this._target) {
throw new Error("Target must be set");
}
};
make_properties(Display, [
- ['target', 'wo', 'dom'], // Canvas element for rendering
['context', 'ro', 'raw'], // Canvas 2D context for rendering (read-only)
['logo', 'rw', 'raw'], // Logo to display when cleared: {"width": w, "height": h, "type": mime-type, "data": data}
['scale', 'rw', 'float'], // Display area scale factor 0.0 - 1.0
// Keyboard event handler
//
-export default function Keyboard(defaults) {
+export default function Keyboard(target, defaults) {
+ this._target = target || null;
+
this._keyDownList = {}; // List of depressed keys
// (even if they are happy)
this._pendingKey = null; // Key waiting for keypress
- set_defaults(this, defaults, {
- 'target': null,
- });
+ set_defaults(this, defaults, {});
// keep these here so we can refer to them later
this._eventHandlers = {
};
make_properties(Keyboard, [
- ['target', 'wo', 'dom'], // DOM element that captures keyboard input
-
['onKeyEvent', 'rw', 'func'] // Handler for key press/release
]);
var WHEEL_STEP_TIMEOUT = 50; // ms
var WHEEL_LINE_HEIGHT = 19;
-export default function Mouse(defaults) {
+export default function Mouse(target, defaults) {
+ this._target = target || document;
this._doubleClickTimer = null;
this._lastTouchPos = null;
// Configuration attributes
set_defaults(this, defaults, {
- 'target': document,
'touchButton': 1
});
};
make_properties(Mouse, [
- ['target', 'ro', 'dom'], // DOM element that captures mouse input
-
['onMouseButton', 'rw', 'func'], // Handler for mouse button click/release
['onMouseMove', 'rw', 'func'], // Handler for mouse movement
['touchButton', 'rw', 'int'] // Button mask (1, 2, 4) for touch devices (0 means ignore clicks)
/*jslint white: false, browser: true */
/*global window, Util, Display, Keyboard, Mouse, Websock, Websock_native, Base64, DES, KeyTable, Inflator, XtScancode */
-export default function RFB(defaults) {
+export default function RFB(target, defaults) {
"use strict";
if (!defaults) {
defaults = {};
}
+ this._target = target;
// Connection details
this._url = '';
// set the default value on user-facing properties
set_defaults(this, defaults, {
- 'target': 'null', // VNC display rendering Canvas object
'local_cursor': false, // Request locally rendered cursor
- 'shared': true, // Request shared mode
'view_only': false, // Disable client mouse/keyboard
'disconnectTimeout': 3, // Time (s) to wait for disconnection
- 'repeaterID': '', // [UltraVNC] RepeaterID to connect to
'viewportDrag': false, // Move the viewport on mouse drags
// Callback functions
// NB: nothing that needs explicit teardown should be done
// before this point, since this can throw an exception
try {
- this._display = new Display({target: this._target,
- onFlush: this._onFlush.bind(this)});
+ this._display = new Display(this._target,
+ {onFlush: this._onFlush.bind(this)});
} catch (exc) {
Log.Error("Display exception: " + exc);
throw exc;
}
this._display.clear();
- this._keyboard = new Keyboard({target: this._target,
- onKeyEvent: this._handleKeyEvent.bind(this)});
+ this._keyboard = new Keyboard(this._target,
+ {onKeyEvent: this._handleKeyEvent.bind(this)});
- this._mouse = new Mouse({target: this._target,
- onMouseButton: this._handleMouseButton.bind(this),
+ this._mouse = new Mouse(this._target,
+ {onMouseButton: this._handleMouseButton.bind(this),
onMouseMove: this._handleMouseMove.bind(this)});
this._sock = new Websock();
RFB.prototype = {
// Public methods
- connect: function (url, creds) {
- this._url = url;
- this._rfb_credentials = (creds !== undefined) ? creds : {};
-
+ connect: function (url, options) {
if (!url) {
this._fail(_("Must specify URL"));
return;
}
+ this._url = url;
+
+ options = options || {}
+
+ this._rfb_credentials = options.credentials || {};
+ this._shared = 'shared' in options ? !!options.shared : true;
+ this._repeaterID = options.repeaterID || '';
+
this._rfb_init_state = '';
this._updateConnectionState('connecting');
return true;
};
make_properties(RFB, [
- ['target', 'wo', 'dom'], // VNC display rendering Canvas object
['local_cursor', 'rw', 'bool'], // Request locally rendered cursor
- ['shared', 'rw', 'bool'], // Request shared mode
['view_only', 'rw', 'bool'], // Disable client mouse/keyboard
['touchButton', 'rw', 'int'], // Button mask (1, 2, 4) for touch devices (0 means ignore clicks)
['scale', 'rw', 'float'], // Display area scale factor
['viewport', 'rw', 'bool'], // Use viewport clipping
['disconnectTimeout', 'rw', 'int'], // Time (s) to wait for disconnection
- ['repeaterID', 'rw', 'str'], // [UltraVNC] RepeaterID to connect to
['viewportDrag', 'rw', 'bool'], // Move the viewport on mouse drags
['capabilities', 'ro', 'arr'], // Supported capabilities
| name | type | mode | default | description
| ----------- | ---- | ---- | -------- | ------------
-| target | DOM | WO | document | DOM element that captures mouse input
| touchButton | int | RW | 1 | Button mask (1, 2, 4) for which click to send on touch devices. 0 means ignore clicks.
### 2.1.2 Methods
### 2.2.1 Configuration Attributes
-| name | type | mode | default | description
-| ------- | ---- | ---- | -------- | ------------
-| target | DOM | WO | document | DOM element that captures keyboard input
+None
### 2.2.2 Methods
| name | type | mode | default | description
| ----------- | ----- | ---- | ------- | ------------
-| target | DOM | WO | | Canvas element for rendering
| context | raw | RO | | Canvas 2D context for rendering
| logo | raw | RW | | Logo to display when cleared: {"width": width, "height": height, "type": mime-type, "data": data}
| scale | float | RW | 1.0 | Display area scale factor 0.0 - 1.0
initializes an RFB object with the 'view_only' configuration option
enabled, then confirms it was set, then disables it:
- var rfb = new RFB({'view_only': true});
+ var rfb = new RFB(target, {'view_only': true});
if (rfb.get_view_only()) {
alert("View Only is set");
}
| name | type | mode | default | description
| ----------------- | ----- | ---- | ---------- | ------------
-| target | DOM | WO | null | Canvas element for rendering (passed to Display, Mouse and Keyboard)
| local_cursor | bool | RW | false | Request locally rendered cursor
-| shared | bool | RW | true | Request shared VNC mode
| view_only | bool | RW | false | Disable client mouse/keyboard
| touchButton | int | RW | 1 | Button mask (1, 2, 4) for which click to send on touch devices. 0 means ignore clicks.
| scale | float | RW | 1.0 | Display area scale factor
| viewport | bool | RW | false | Use viewport clipping
| disconnectTimeout | int | RW | 3 | Time (in seconds) to wait for disconnection
-| repeaterID | str | RW | '' | UltraVNC RepeaterID to connect to
| viewportDrag | bool | RW | false | Move the viewport on mouse drags
| capabilities | arr | RO | [] | Supported capabilities (can include: 'power', 'resize')
| name | parameters | description
| ------------------ | ------------------------------- | ------------
-| connect | (url, credentials) | Connect to the given URL. Optional credentials.
+| connect | (url, options) | Connect to the given URL
| disconnect | () | Disconnect
| sendCredentials | (credentials) | Send credentials after onCredentialsRequired callback
| sendCtrlAltDel | () | Send Ctrl-Alt-Del key sequence
| requestDesktopSize | (width, height) | Send a request to change the remote desktop size.
| viewportChangeSize | (width, height) | Change size of the viewport
+__connect() details__
+
+The connect() call supports the following options:
+
+| name | type | default | description
+| ----------------- | ----- | ---------- | ------------
+| shared | bool | true | Request shared VNC mode
+| credentials | obj | {} | Credentials to use when authenticating
+| repeaterID | str | '' | UltraVNC RepeaterID to connect to
+
## 3 Callbacks
RecordingPlayer.prototype = {
run: function (realtime, trafficManagement) {
// initialize a new RFB
- this._rfb = new RFB({'target': document.getElementById('VNC_canvas'),
- 'view_only': true,
+ this._rfb = new RFB(document.getElementById('VNC_canvas'),
+ {'view_only': true,
'onDisconnected': this._handleDisconnect.bind(this),
'onNotification': this._notification});
this._enablePlaybackMode();
describe('checking for cursor uri support', function () {
it('should disable cursor URIs if there is no support', function () {
_forceCursorURIs(false);
- var display = new Display({ target: document.createElement('canvas'), prefer_js: true, viewport: false });
+ var display = new Display(document.createElement('canvas'), { prefer_js: true, viewport: false });
expect(display._cursor_uri).to.be.false;
});
it('should enable cursor URIs if there is support', function () {
_forceCursorURIs(true);
- var display = new Display({ target: document.createElement('canvas'), prefer_js: true, viewport: false });
+ var display = new Display(document.createElement('canvas'), { prefer_js: true, viewport: false });
expect(display._cursor_uri).to.be.true;
});
it('respect the cursor_uri option if there is support', function () {
_forceCursorURIs(false);
- var display = new Display({ target: document.createElement('canvas'), prefer_js: true, viewport: false, cursor_uri: false });
+ var display = new Display(document.createElement('canvas'), { prefer_js: true, viewport: false, cursor_uri: false });
expect(display._cursor_uri).to.be.false;
});
});
describe('viewport handling', function () {
var display;
beforeEach(function () {
- display = new Display({ target: document.createElement('canvas'), prefer_js: false, viewport: true });
+ display = new Display(document.createElement('canvas'), { prefer_js: false, viewport: true });
display.resize(5, 5);
display.viewportChangeSize(3, 3);
display.viewportChangePos(1, 1);
describe('resizing', function () {
var display;
beforeEach(function () {
- display = new Display({ target: document.createElement('canvas'), prefer_js: false, viewport: false });
+ display = new Display(document.createElement('canvas'), { prefer_js: false, viewport: false });
display.resize(4, 4);
});
var canvas;
beforeEach(function () {
- display = new Display({ target: document.createElement('canvas'), prefer_js: false, viewport: true });
+ canvas = document.createElement('canvas');
+ display = new Display(canvas, { prefer_js: false, viewport: true });
display.resize(4, 4);
display.viewportChangeSize(3, 3);
display.viewportChangePos(1, 1);
- canvas = display.get_target();
document.body.appendChild(canvas);
});
var canvas;
beforeEach(function () {
- display = new Display({ target: document.createElement('canvas'), prefer_js: false, viewport: true });
+ canvas = document.createElement('canvas');
+ display = new Display(canvas, { prefer_js: false, viewport: true });
display.resize(4, 3);
- canvas = display.get_target();
document.body.appendChild(canvas);
});
function drawing_tests (pref_js) {
var display;
beforeEach(function () {
- display = new Display({ target: document.createElement('canvas'), prefer_js: pref_js });
+ display = new Display(document.createElement('canvas'), { prefer_js: pref_js });
display.resize(4, 4);
});
describe('the render queue processor', function () {
var display;
beforeEach(function () {
- display = new Display({ target: document.createElement('canvas'), prefer_js: false });
+ display = new Display(document.createElement('canvas'), { prefer_js: false });
display.resize(4, 4);
sinon.spy(display, '_scan_renderQ');
});
describe('Decode Keyboard Events', function() {
it('should decode keydown events', function(done) {
if (isIE() || isEdge()) this.skip();
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('KeyA');
it('should decode keyup events', function(done) {
if (isIE() || isEdge()) this.skip();
var calls = 0;
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('KeyA');
describe('Legacy keypress Events', function() {
it('should wait for keypress when needed', function() {
var callback = sinon.spy();
- var kbd = new Keyboard({onKeyEvent: callback});
+ var kbd = new Keyboard(document, {onKeyEvent: callback});
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
expect(callback).to.not.have.been.called;
});
it('should decode keypress events', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('KeyA');
});
it('should ignore keypress with different code', function() {
var callback = sinon.spy();
- var kbd = new Keyboard({onKeyEvent: callback});
+ var kbd = new Keyboard(document, {onKeyEvent: callback});
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41}));
kbd._handleKeyPress(keyevent('keypress', {code: 'KeyB', charCode: 0x61}));
expect(callback).to.not.have.been.called;
});
it('should handle keypress with missing code', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('KeyA');
kbd._handleKeyPress(keyevent('keypress', {charCode: 0x61}));
});
it('should guess key if no keypress and numeric key', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x32);
expect(code).to.be.equal('Digit2');
kbd._handleKeyDown(keyevent('keydown', {code: 'Digit2', keyCode: 0x32}));
});
it('should guess key if no keypress and alpha key', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('KeyA');
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: false}));
});
it('should guess key if no keypress and alpha key (with shift)', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x41);
expect(code).to.be.equal('KeyA');
kbd._handleKeyDown(keyevent('keydown', {code: 'KeyA', keyCode: 0x41, shiftKey: true}));
});
it('should not guess key if no keypress and unknown key', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0);
expect(code).to.be.equal('KeyA');
if (isIE() || isEdge()) this.skip();
});
it('should suppress anything with a valid key', function() {
- var kbd = new Keyboard({});
+ var kbd = new Keyboard(document, {});
var evt = keyevent('keydown', {code: 'KeyA', key: 'a'});
kbd._handleKeyDown(evt);
expect(evt.preventDefault).to.have.been.called;
expect(evt.preventDefault).to.have.been.called;
});
it('should not suppress keys without key', function() {
- var kbd = new Keyboard({});
+ var kbd = new Keyboard(document, {});
var evt = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
kbd._handleKeyDown(evt);
expect(evt.preventDefault).to.not.have.been.called;
});
it('should suppress the following keypress event', function() {
- var kbd = new Keyboard({});
+ var kbd = new Keyboard(document, {});
var evt = keyevent('keydown', {code: 'KeyA', keyCode: 0x41});
kbd._handleKeyDown(evt);
var evt = keyevent('keypress', {code: 'KeyA', charCode: 0x41});
it('should fake keyup events for virtual keyboards', function(done) {
if (isIE() || isEdge()) this.skip();
var count = 0;
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
switch (count++) {
case 0:
it('should fake keyup events on iOS', function(done) {
if (isIE() || isEdge()) this.skip();
var count = 0;
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
switch (count++) {
case 0:
if (isIE() || isEdge()) this.skip();
});
it('should send release using the same keysym as the press', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('KeyA');
});
it('should send the same keysym for multiple presses', function() {
var count = 0;
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('KeyA');
});
it('should do nothing on keyup events if no keys are down', function() {
var callback = sinon.spy();
- var kbd = new Keyboard({onKeyEvent: callback});
+ var kbd = new Keyboard(document, {onKeyEvent: callback});
kbd._handleKeyUp(keyevent('keyup', {code: 'KeyA', key: 'a'}));
expect(callback).to.not.have.been.called;
});
describe('Legacy Events', function() {
it('should track keys using keyCode if no code', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('Platform65');
kbd._handleKeyDown(keyevent('keydown', {keyCode: 229, key: 'a'}));
});
it('should track keys using keyIdentifier if no code', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0x61);
expect(code).to.be.equal('Platform65');
it('should change Alt to AltGraph', function() {
var count = 0;
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
switch (count++) {
case 0:
expect(count).to.be.equal(2);
});
it('should change left Super to Alt', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0xFFE9);
expect(code).to.be.equal('MetaLeft');
kbd._handleKeyDown(keyevent('keydown', {code: 'MetaLeft', key: 'Meta', location: 1}));
});
it('should change right Super to left Super', function(done) {
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
expect(keysym).to.be.equal(0xFFEB);
expect(code).to.be.equal('MetaRight');
it('should generate fake undo/redo events on press when AltGraph is down', function() {
var times_called = 0;
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
switch(times_called++) {
case 0:
});
it('should no do anything on key release', function() {
var times_called = 0;
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
switch(times_called++) {
case 7:
});
it('should not consider a char modifier to be down on the modifier key itself', function() {
var times_called = 0;
- var kbd = new Keyboard({
+ var kbd = new Keyboard(document, {
onKeyEvent: function(keysym, code, down) {
switch(times_called++) {
case 0:
describe('Decode Mouse Events', function() {
it('should decode mousedown events', function(done) {
- var mouse = new Mouse({
+ var mouse = new Mouse(target, {
onMouseButton: function(x, y, down, bmask) {
expect(bmask).to.be.equal(0x01);
expect(down).to.be.equal(1);
done();
- },
- target: target
+ }
});
mouse._handleMouseDown(mouseevent('mousedown', { button: '0x01' }));
});
it('should decode mouseup events', function(done) {
var calls = 0;
- var mouse = new Mouse({
+ var mouse = new Mouse(target, {
onMouseButton: function(x, y, down, bmask) {
expect(bmask).to.be.equal(0x01);
if (calls++ === 1) {
expect(down).to.not.be.equal(1);
done();
}
- },
- target: target
+ }
});
mouse._handleMouseDown(mouseevent('mousedown', { button: '0x01' }));
mouse._handleMouseUp(mouseevent('mouseup', { button: '0x01' }));
});
it('should decode mousemove events', function(done) {
- var mouse = new Mouse({
+ var mouse = new Mouse(target, {
onMouseMove: function(x, y) {
// Note that target relative coordinates are sent
expect(x).to.be.equal(40);
expect(y).to.be.equal(10);
done();
- },
- target: target
+ }
});
mouse._handleMouseMove(mouseevent('mousemove',
{ clientX: 50, clientY: 20 }));
});
it('should decode mousewheel events', function(done) {
var calls = 0;
- var mouse = new Mouse({
+ var mouse = new Mouse(target, {
onMouseButton: function(x, y, down, bmask) {
calls++;
expect(bmask).to.be.equal(1<<6);
expect(down).to.not.be.equal(1);
done();
}
- },
- target: target
+ }
});
mouse._handleMouseWheel(mouseevent('mousewheel',
{ deltaX: 50, deltaY: 0,
it('should use same pos for 2nd tap if close enough', function(done) {
var calls = 0;
- var mouse = new Mouse({
+ var mouse = new Mouse(target, {
onMouseButton: function(x, y, down, bmask) {
calls++;
if (calls === 1) {
expect(y).to.be.equal(36);
done();
}
- },
- target: target
+ }
});
// touch events are sent in an array of events
// with one item for each touch point
it('should not modify 2nd tap pos if far apart', function(done) {
var calls = 0;
- var mouse = new Mouse({
+ var mouse = new Mouse(target, {
onMouseButton: function(x, y, down, bmask) {
calls++;
if (calls === 1) {
expect(y).to.not.be.equal(36);
done();
}
- },
- target: target
+ }
});
mouse._handleMouseDown(touchevent(
'touchstart', { touches: [{ clientX: 78, clientY: 46 }]}));
it('should not modify 2nd tap pos if not soon enough', function(done) {
var calls = 0;
- var mouse = new Mouse({
+ var mouse = new Mouse(target, {
onMouseButton: function(x, y, down, bmask) {
calls++;
if (calls === 1) {
expect(y).to.not.be.equal(36);
done();
}
- },
- target: target
+ }
});
mouse._handleMouseDown(touchevent(
'touchstart', { touches: [{ clientX: 78, clientY: 46 }]}));
it('should not modify 2nd tap pos if not touch', function(done) {
var calls = 0;
- var mouse = new Mouse({
+ var mouse = new Mouse(target, {
onMouseButton: function(x, y, down, bmask) {
calls++;
if (calls === 1) {
expect(y).to.not.be.equal(36);
done();
}
- },
- target: target
+ }
});
mouse._handleMouseDown(mouseevent(
'mousedown', { button: '0x01', clientX: 78, clientY: 46 }));
it('should accumulate wheel events if small enough', function () {
var callback = sinon.spy();
- var mouse = new Mouse({ onMouseButton: callback, target: target });
+ var mouse = new Mouse(target, { onMouseButton: callback });
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
it('should not accumulate large wheel events', function () {
var callback = sinon.spy();
- var mouse = new Mouse({ onMouseButton: callback, target: target });
+ var mouse = new Mouse(target, { onMouseButton: callback });
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
it('should send even small wheel events after a timeout', function () {
var callback = sinon.spy();
- var mouse = new Mouse({ onMouseButton: callback, target: target });
+ var mouse = new Mouse(target, { onMouseButton: callback });
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
it('should account for non-zero deltaMode', function () {
var callback = sinon.spy();
- var mouse = new Mouse({ onMouseButton: callback, target: target });
+ var mouse = new Mouse(target, { onMouseButton: callback });
mouse._handleMouseWheel(mouseevent(
'mousewheel', { clientX: 18, clientY: 40,
import sinon from '../vendor/sinon.js';
function make_rfb (extra_opts) {
- if (!extra_opts) {
- extra_opts = {};
- }
-
- extra_opts.target = extra_opts.target || document.createElement('canvas');
- return new RFB(extra_opts);
+ extra_opts = extra_opts || {};
+ return new RFB(document.createElement('canvas'), extra_opts);
}
var push8 = function (arr, num) {
client._sock._websocket._open();
});
- it('should interpret version 000.000 as a repeater', function () {
- client._repeaterID = '12345';
- send_ver('000.000', client);
- expect(client._rfb_version).to.equal(0);
-
- var sent_data = client._sock._websocket._get_sent_data();
- expect(new Uint8Array(sent_data.buffer, 0, 9)).to.array.equal(new Uint8Array([73, 68, 58, 49, 50, 51, 52, 53, 0]));
- });
-
it('should interpret version 003.003 as version 3.3', function () {
send_ver('003.003', client);
expect(client._rfb_version).to.equal(3.3);
});
});
- it('should handle two step repeater negotiation', function () {
- client._repeaterID = '12345';
-
- send_ver('000.000', client);
- expect(client._rfb_version).to.equal(0);
- var sent_data = client._sock._websocket._get_sent_data();
- expect(new Uint8Array(sent_data.buffer, 0, 9)).to.array.equal(new Uint8Array([73, 68, 58, 49, 50, 51, 52, 53, 0]));
- expect(sent_data).to.have.length(250);
-
- send_ver('003.008', client);
- expect(client._rfb_version).to.equal(3.8);
- });
-
it('should send back the interpreted version', function () {
send_ver('004.000', client);
send_ver('003.008', client);
expect(client._rfb_init_state).to.equal('Security');
});
+
+ describe('Repeater', function () {
+ it('should interpret version 000.000 as a repeater', function () {
+ client = make_rfb();
+ client.connect('wss://host:8675', { repeaterID: "12345" });
+ client._sock._websocket._open();
+ send_ver('000.000', client);
+ expect(client._rfb_version).to.equal(0);
+
+ var sent_data = client._sock._websocket._get_sent_data();
+ expect(new Uint8Array(sent_data.buffer, 0, 9)).to.array.equal(new Uint8Array([73, 68, 58, 49, 50, 51, 52, 53, 0]));
+ expect(sent_data).to.have.length(250);
+ });
+
+ it('should handle two step repeater negotiation', function () {
+ client = make_rfb();
+ client.connect('wss://host:8675', { repeaterID: "12345" });
+ client._sock._websocket._open();
+ send_ver('000.000', client);
+ send_ver('003.008', client);
+ expect(client._rfb_version).to.equal(3.8);
+ });
+ });
});
describe('Security', function () {
beforeEach(function () {
client = make_rfb();
- client.connect('wss://host:8675');
- client._sock._websocket._open();
- client._rfb_init_state = 'SecurityResult';
});
it('should transition to the ServerInitialisation state', function () {
+ client.connect('wss://host:8675');
+ client._sock._websocket._open();
+ client._rfb_init_state = 'SecurityResult';
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
expect(client._rfb_init_state).to.equal('ServerInitialisation');
});
it('should send 1 if we are in shared mode', function () {
- client.set_shared(true);
+ client.connect('wss://host:8675', { shared: true });
+ client._sock._websocket._open();
+ client._rfb_init_state = 'SecurityResult';
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
expect(client._sock).to.have.sent(new Uint8Array([1]));
});
it('should send 0 if we are not in shared mode', function () {
- client.set_shared(false);
+ client.connect('wss://host:8675', { shared: false });
+ client._sock._websocket._open();
+ client._rfb_init_state = 'SecurityResult';
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 0]));
expect(client._sock).to.have.sent(new Uint8Array([0]));
});
}
try {
- rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
- 'repeaterID': WebUtil.getConfigVar('repeaterID', ''),
- 'local_cursor': WebUtil.getConfigVar('cursor', true),
- 'shared': WebUtil.getConfigVar('shared', true),
+ rfb = new RFB(document.getElementById('noVNC_canvas'),
+ {'local_cursor': WebUtil.getConfigVar('cursor', true),
'view_only': WebUtil.getConfigVar('view_only', false),
'onNotification': notification,
'onUpdateState': updateState,
}
url += '/' + path;
- rfb.connect(url, { password: password });
+ rfb.connect(url, { repeaterID: WebUtil.getConfigVar('repeaterID', ''),
+ shared: WebUtil.getConfigVar('shared', true),
+ credentials: { password: password } });
})();
</script>
</head>