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 3cb89f5a14
commit a9f79a63b9
3 changed files with 21 additions and 3 deletions

View File

@ -40,6 +40,7 @@ var that = {}, // Public API methods
rfb_port = 5900,
rfb_password = '',
rfb_path = '',
rfb_queryargs = '',
rfb_state = 'disconnected',
rfb_version = 0,
@ -303,6 +304,12 @@ function connect() {
}
uri += rfb_host + ":" + rfb_port + "/" + rfb_path;
}
if (rfb_queryargs != null) {
var querystr = WebUtil.objToQueryString(rfb_queryargs);
if (querystr != "") {
uri += "?" + querystr;
}
}
Util.Info("connecting to " + uri);
// TODO: make protocols a configurable
ws.open(uri, ['binary', 'base64']);
@ -1784,13 +1791,14 @@ clientCutText = function(text) {
// Public API interface functions
//
that.connect = function(host, port, password, path) {
that.connect = function(host, port, password, path, queryargs) {
//Util.Debug(">> connect");
rfb_host = host;
rfb_port = port;
rfb_password = (password !== undefined) ? password : "";
rfb_path = (path !== undefined) ? path : "";
rfb_queryargs = (queryargs !== undefined) ? queryargs : null;
if ((!rfb_host) || (!rfb_port)) {
return fail("Must set host and port");

View File

@ -214,3 +214,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

@ -114,7 +114,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;
@ -140,6 +140,7 @@
// This is used by nova-novncproxy.
token = WebUtil.getQueryVar('token', null);
if (token) {
queryargs = {token: token};
WebUtil.createCookie('token', token, 1)
}
@ -162,7 +163,7 @@
'view_only': WebUtil.getQueryVar('view_only', false),
'updateState': updateState,
'onPasswordRequired': passwordRequired});
rfb.connect(host, port, password, path);
rfb.connect(host, port, password, path, queryargs);
};
</script>