Allow passing queryparams to websocket

Adds helper function to convert object into querystring
Adds passing of token to websocket in vnc_auto.html
This commit is contained in:
Jo De Boeck 2013-09-25 14:16:40 +02:00
parent fc00821eba
commit 34aa5d7056
3 changed files with 19 additions and 3 deletions

View File

@ -26,6 +26,7 @@ var RFB;
this._rfb_port = 5900;
this._rfb_password = '';
this._rfb_path = '';
this._rfb_queryargs = '';
this._rfb_state = 'disconnected';
this._rfb_version = 0;
@ -224,11 +225,12 @@ var RFB;
RFB.prototype = {
// Public methods
connect: function (host, port, password, path) {
connect: function (host, port, password, path, queryargs) {
this._rfb_host = host;
this._rfb_port = port;
this._rfb_password = (password !== undefined) ? password : "";
this._rfb_path = (path !== undefined) ? path : "";
this._rfb_queryargs = (path !== undefined) ? queryargs : null;
if (!this._rfb_host || !this._rfb_port) {
return this._fail("Must set host and port");
@ -314,6 +316,10 @@ var RFB;
}
uri += '://' + this._rfb_host + ':' + this._rfb_port + '/' + this._rfb_path;
if (self._rfb_queryargs != null) {
var querystr = WebUtil.objToQueryString(self._rfb_queryargs);
uri += "?" _ querystr;
}
Util.Info("connecting to " + uri);
this._sock.open(uri, this._wsProtocols);

View File

@ -237,3 +237,12 @@ WebUtil.selectStylesheet = function (sheet) {
}
return sheet;
};
// Method to help create query string from simple map
WebUtil.objToQueryString = function(obj) {
var str = [];
for(var p in obj) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
}

View File

@ -149,7 +149,7 @@
}
window.onscriptsload = function () {
var host, port, password, path, token;
var host, port, password, path, token, queryargs;
$D('sendCtrlAltDelButton').style.display = "inline";
$D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
@ -178,6 +178,7 @@
// This is used by nova-novncproxy.
token = WebUtil.getQueryVar('token', null);
if (token) {
queryargs = {token: token};
WebUtil.createCookie('token', token, 1)
}
@ -201,7 +202,7 @@
'onUpdateState': updateState,
'onXvpInit': xvpInit,
'onPasswordRequired': passwordRequired});
rfb.connect(host, port, password, path);
rfb.connect(host, port, password, path, queryargs);
};
</script>