]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Remove support for the fragment and WebUtil dep
authorSamuel Mannehed <samuel@cendio.se>
Thu, 16 Aug 2018 09:23:11 +0000 (11:23 +0200)
committerSamuel Mannehed <samuel@cendio.se>
Tue, 28 Aug 2018 08:41:56 +0000 (10:41 +0200)
The only remaining use we had of WebUtil was getConfigVar(). Let's get
rid of that dependency and use our own, query-string-only and richly
commented version of that function. It's easier for people to get an
overview of vnc_lite if it's all in one file.

This commit removes support for the fragment, parameters can only be
passed using the query string from now on.

vnc_lite.html

index fcb3e7c370c1c6bd0615a012c0bca56f67717fa7..828c5c8101a3eef192b44bc725f12a9c4ede1c3d 100644 (file)
@@ -14,8 +14,6 @@
 
     Connect parameters are provided in query string:
         http://example.com/?host=HOST&port=PORT&scale=true
-    or the fragment:
-        http://example.com/#host=HOST&port=PORT&scale=true
     -->
     <title>noVNC</title>
 
@@ -82,8 +80,6 @@
 
     <!-- actual script modules -->
     <script type="module" crossorigin="anonymous">
-        // WebUtil contains helper functions for browser features
-        import * as WebUtil from './app/webutil.js';
         // RFB holds the API to connect and communicate with a VNC server
         import RFB from './core/rfb.js';
 
             }
         }
 
+        // This function extracts the value of one variable from the
+        // query string. If the variable isn't defined in the URL
+        // it returns the default value instead.
+        function readQueryVariable(name, defaultValue) {
+            // A URL with a query parameter can look like this:
+            // https://www.example.com?myqueryparam=myvalue
+            //
+            // Note that we use location.href instead of location.search
+            // because Firefox < 53 has a bug w.r.t location.search
+            const re = new RegExp('.*[?&]' + name + '=([^&#]*)'),
+                  match = document.location.href.match(re);
+            if (typeof defaultValue === 'undefined') { defaultValue = null; }
+
+            if (match) {
+                // We have to decode the URL since want the cleartext value
+                return decodeURIComponent(match[1]);
+            }
+
+            return defaultValue;
+        }
+
         document.getElementById('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
 
-        // Read parameters specified in the URL (query string or fragment)
+        // Read parameters specified in the URL query string
         // By default, use the host and port of server that served this file
-        var host = WebUtil.getConfigVar('host', window.location.hostname);
-        var port = WebUtil.getConfigVar('port', window.location.port);
-        var password = WebUtil.getConfigVar('password', '');
-        var path = WebUtil.getConfigVar('path', 'websockify');
+        var host = readQueryVariable('host', window.location.hostname);
+        var port = readQueryVariable('port', window.location.port);
+        var password = readQueryVariable('password', '');
+        var path = readQueryVariable('path', 'websockify');
 
         // | | |         | | |
         // | | | Connect | | |
             rfb.addEventListener("desktopname", updateDesktopName);
 
             // Set parameters that can be changed on an active connection
-            rfb.viewOnly = WebUtil.getConfigVar('view_only', false);
-            rfb.scaleViewport = WebUtil.getConfigVar('scale', false);
+            rfb.viewOnly = readQueryVariable('view_only', false);
+            rfb.scaleViewport = readQueryVariable('scale', false);
         })();
     </script>
 </head>