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:
parent
fc00821eba
commit
34aa5d7056
|
|
@ -26,6 +26,7 @@ var RFB;
|
||||||
this._rfb_port = 5900;
|
this._rfb_port = 5900;
|
||||||
this._rfb_password = '';
|
this._rfb_password = '';
|
||||||
this._rfb_path = '';
|
this._rfb_path = '';
|
||||||
|
this._rfb_queryargs = '';
|
||||||
|
|
||||||
this._rfb_state = 'disconnected';
|
this._rfb_state = 'disconnected';
|
||||||
this._rfb_version = 0;
|
this._rfb_version = 0;
|
||||||
|
|
@ -224,11 +225,12 @@ var RFB;
|
||||||
|
|
||||||
RFB.prototype = {
|
RFB.prototype = {
|
||||||
// Public methods
|
// Public methods
|
||||||
connect: function (host, port, password, path) {
|
connect: function (host, port, password, path, queryargs) {
|
||||||
this._rfb_host = host;
|
this._rfb_host = host;
|
||||||
this._rfb_port = port;
|
this._rfb_port = port;
|
||||||
this._rfb_password = (password !== undefined) ? password : "";
|
this._rfb_password = (password !== undefined) ? password : "";
|
||||||
this._rfb_path = (path !== undefined) ? path : "";
|
this._rfb_path = (path !== undefined) ? path : "";
|
||||||
|
this._rfb_queryargs = (path !== undefined) ? queryargs : null;
|
||||||
|
|
||||||
if (!this._rfb_host || !this._rfb_port) {
|
if (!this._rfb_host || !this._rfb_port) {
|
||||||
return this._fail("Must set host and 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;
|
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);
|
Util.Info("connecting to " + uri);
|
||||||
|
|
||||||
this._sock.open(uri, this._wsProtocols);
|
this._sock.open(uri, this._wsProtocols);
|
||||||
|
|
|
||||||
|
|
@ -237,3 +237,12 @@ WebUtil.selectStylesheet = function (sheet) {
|
||||||
}
|
}
|
||||||
return 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("&");
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onscriptsload = function () {
|
window.onscriptsload = function () {
|
||||||
var host, port, password, path, token;
|
var host, port, password, path, token, queryargs;
|
||||||
|
|
||||||
$D('sendCtrlAltDelButton').style.display = "inline";
|
$D('sendCtrlAltDelButton').style.display = "inline";
|
||||||
$D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
|
$D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
|
||||||
|
|
@ -178,6 +178,7 @@
|
||||||
// This is used by nova-novncproxy.
|
// This is used by nova-novncproxy.
|
||||||
token = WebUtil.getQueryVar('token', null);
|
token = WebUtil.getQueryVar('token', null);
|
||||||
if (token) {
|
if (token) {
|
||||||
|
queryargs = {token: token};
|
||||||
WebUtil.createCookie('token', token, 1)
|
WebUtil.createCookie('token', token, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,7 +202,7 @@
|
||||||
'onUpdateState': updateState,
|
'onUpdateState': updateState,
|
||||||
'onXvpInit': xvpInit,
|
'onXvpInit': xvpInit,
|
||||||
'onPasswordRequired': passwordRequired});
|
'onPasswordRequired': passwordRequired});
|
||||||
rfb.connect(host, port, password, path);
|
rfb.connect(host, port, password, path, queryargs);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue