From 34aa5d70566cbf18eb01ae1411a82275aa7c1fb6 Mon Sep 17 00:00:00 2001 From: Jo De Boeck Date: Wed, 25 Sep 2013 14:16:40 +0200 Subject: [PATCH] Allow passing queryparams to websocket Adds helper function to convert object into querystring Adds passing of token to websocket in vnc_auto.html --- include/rfb.js | 8 +++++++- include/webutil.js | 9 +++++++++ vnc_auto.html | 5 +++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/rfb.js b/include/rfb.js index 59fd785d..79abb6c7 100644 --- a/include/rfb.js +++ b/include/rfb.js @@ -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); diff --git a/include/webutil.js b/include/webutil.js index e674bf94..db100c48 100644 --- a/include/webutil.js +++ b/include/webutil.js @@ -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("&"); +} diff --git a/vnc_auto.html b/vnc_auto.html index b05024e3..2b17544d 100644 --- a/vnc_auto.html +++ b/vnc_auto.html @@ -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); };