]> git.proxmox.com Git - mirror_novnc.git/blobdiff - vnc_lite.html
Move writeSetting from updateSetting to initSetting
[mirror_novnc.git] / vnc_lite.html
index e93efcfd98a7c4c29063aa9151c137bfb46c412e..4a96d448fc4a58f042f94b2b2f43ef6da49c9aea 100644 (file)
@@ -36,7 +36,9 @@
     <link rel="icon" sizes="144x144" type="image/png" href="app/images/icons/novnc-144x144.png">
     <link rel="icon" sizes="152x152" type="image/png" href="app/images/icons/novnc-152x152.png">
     <link rel="icon" sizes="192x192" type="image/png" href="app/images/icons/novnc-192x192.png">
+    <!-- Firefox currently mishandles SVG, see #1419039
     <link rel="icon" sizes="any" type="image/svg+xml" href="app/images/icons/novnc-icon.svg">
+    -->
     <!-- Repeated last so that legacy handling will pick this -->
     <link rel="icon" sizes="16x16" type="image/png" href="app/images/icons/novnc-16x16.png">
 
         import RFB from './core/rfb.js';
 
         var rfb;
-        var doneInitialResize;
-        var resizeTimeout;
         var desktopName;
 
-        function UIresize() {
-            if (WebUtil.getConfigVar('resize', false)) {
-                var innerW = window.innerWidth;
-                var innerH = window.innerHeight;
-                var controlbarH = document.getElementById('noVNC_status_bar').offsetHeight;
-                if (innerW !== undefined && innerH !== undefined)
-                    rfb.requestDesktopSize(innerW, innerH - controlbarH);
-            }
-        }
-        function initialResize() {
-            if (doneInitialResize) return;
-            UIresize();
-            doneInitialResize = true;
-        }
         function updateDesktopName(e) {
             desktopName = e.detail.name;
         }
             document.getElementById('noVNC_status_bar').className = "noVNC_status_" + level;
             document.getElementById('noVNC_status').textContent = text;
         }
-        function updateState(e) {
-            var cad = document.getElementById('sendCtrlAltDelButton');
-            switch (e.detail.state) {
-                case 'connecting':
-                    status("Connecting", "normal");
-                    break;
-                case 'connected':
-                    doneInitialResize = false;
-                    if (WebUtil.getConfigVar('encrypt',
-                                             (window.location.protocol === "https:"))) {
-                        status("Connected (encrypted) to " +
-                               desktopName, "normal");
-                    } else {
-                        status("Connected (unencrypted) to " +
-                               desktopName, "normal");
-                    }
-                    break;
-                case 'disconnecting':
-                    status("Disconnecting", "normal");
-                    break;
-                case 'disconnected':
-                    status("Disconnected", "normal");
-                    break;
-                default:
-                    status(e.detail.state, "warn");
-                    break;
-            }
 
-            if (e.detail.state === 'connected') {
-                cad.disabled = false;
+        function connected(e) {
+            document.getElementById('sendCtrlAltDelButton').disabled = false;
+            if (WebUtil.getConfigVar('encrypt',
+                                     (window.location.protocol === "https:"))) {
+                status("Connected (encrypted) to " + desktopName, "normal");
             } else {
-                cad.disabled = true;
-                updatePowerButtons();
+                status("Connected (unencrypted) to " + desktopName, "normal");
             }
-
         }
-        function disconnect(e) {
-            if (typeof(e.detail.reason) !== 'undefined') {
-                status(e.detail.reason, "error");
+
+        function disconnected(e) {
+            document.getElementById('sendCtrlAltDelButton').disabled = true;
+            updatePowerButtons();
+            if (e.detail.clean) {
+                status("Disconnected", "normal");
+            } else {
+                status("Something went wrong, connection is closed", "error");
             }
         }
 
-        window.onresize = function () {
-            // When the window has been resized, wait until the size remains
-            // the same for 0.5 seconds before sending the request for changing
-            // the resolution of the session
-            clearTimeout(resizeTimeout);
-            resizeTimeout = setTimeout(function(){
-                UIresize();
-            }, 500);
-        };
-
         function updatePowerButtons() {
             var powerbuttons;
             powerbuttons = document.getElementById('noVNC_power_buttons');
             if (rfb.capabilities.power) {
-                xvpbuttons.className= "noVNC_shown";
+                powerbuttons.className= "noVNC_shown";
             } else {
-                xvpbuttons.className = "noVNC_hidden";
+                powerbuttons.className = "noVNC_hidden";
             }
         }
 
 
         (function() {
 
+            status("Connecting", "normal");
+
             if ((!host) || (!port)) {
                 status('Must specify host and port in URL', 'error');
             }
             }
             url += '/' + path;
 
-            rfb = new RFB(document.getElementById('noVNC_canvas'), url,
+            rfb = new RFB(document.body, url,
                           { repeaterID: WebUtil.getConfigVar('repeaterID', ''),
                             shared: WebUtil.getConfigVar('shared', true),
                             credentials: { password: password } });
             rfb.viewOnly = WebUtil.getConfigVar('view_only', false);
-            rfb.addEventListener("updatestate",  updateState);
-            rfb.addEventListener("disconnect", disconnect);
-            rfb.addEventListener("capabilities", function () { updatePowerButtons(); initialResize(); });
+            rfb.addEventListener("connect",  connected);
+            rfb.addEventListener("disconnect", disconnected);
+            rfb.addEventListener("capabilities", function () { updatePowerButtons(); });
             rfb.addEventListener("credentialsrequired", credentials);
             rfb.addEventListener("desktopname", updateDesktopName);
+            rfb.scaleViewport = WebUtil.getConfigVar('scale', false);
+            rfb.resizeSession = WebUtil.getConfigVar('resize', false);
         })();
     </script>
 </head>
       </span>
     </div>
   </div>
-  <canvas id="noVNC_canvas" width="0" height="0">
-    Canvas not supported.
-  </canvas>
-
 </body>
 </html>