| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var remoting = chrome.extension.getBackgroundPage().remoting; | 5 var remoting = chrome.extension.getBackgroundPage().remoting; |
| 6 | 6 |
| 7 // Chromoting session API version (for this javascript). | 7 // Chromoting session API version (for this javascript). |
| 8 // This is compared with the plugin API version to verify that they are | 8 // This is compared with the plugin API version to verify that they are |
| 9 // compatible. | 9 // compatible. |
| 10 remoting.apiVersion = 2; | 10 remoting.apiVersion = 2; |
| 11 | 11 |
| 12 // The oldest API version that we support. | 12 // The oldest API version that we support. |
| 13 // This will differ from the |apiVersion| if we maintain backward | 13 // This will differ from the |apiVersion| if we maintain backward |
| 14 // compatibility with older API versions. | 14 // compatibility with older API versions. |
| 15 remoting.apiMinVersion = 1; | 15 remoting.apiMinVersion = 1; |
| 16 | 16 |
| 17 // Message id so that we can identify (and ignore) message fade operations for | 17 // Message id so that we can identify (and ignore) message fade operations for |
| 18 // old messages. This starts at 1 and is incremented for each new message. | 18 // old messages. This starts at 1 and is incremented for each new message. |
| 19 remoting.messageId = 1; | 19 remoting.messageId = 1; |
| 20 | 20 |
| 21 remoting.scaleToFit = false; | 21 remoting.scaleToFit = false; |
| 22 | 22 |
| 23 remoting.httpXmppProxy = | 23 remoting.httpXmppProxy = |
| 24 'https://chromoting-httpxmpp-oauth2-dev.corp.google.com'; | 24 'https://chromoting-httpxmpp-oauth2-dev.corp.google.com'; |
| 25 | 25 |
| 26 window.addEventListener("load", init_, false); | 26 window.addEventListener("load", init_, false); |
| 27 window.addEventListener('blur', pluginLostFocus_, false); |
| 27 | 28 |
| 28 // This executes a poll loop on the server for more Iq packets, and feeds them | 29 // This executes a poll loop on the server for more Iq packets, and feeds them |
| 29 // to the plugin. | 30 // to the plugin. |
| 30 function feedIq() { | 31 function feedIq() { |
| 31 var xhr = new XMLHttpRequest(); | 32 var xhr = new XMLHttpRequest(); |
| 32 xhr.open('GET', remoting.httpXmppProxy + '/readIq?host_jid=' + | 33 xhr.open('GET', remoting.httpXmppProxy + '/readIq?host_jid=' + |
| 33 encodeURIComponent(remoting.hostJid), true); | 34 encodeURIComponent(remoting.hostJid), true); |
| 34 xhr.withCredentials = true; | 35 xhr.withCredentials = true; |
| 35 xhr.onreadystatechange = function() { | 36 xhr.onreadystatechange = function() { |
| 36 if (xhr.readyState == 4) { | 37 if (xhr.readyState == 4) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 109 } |
| 109 | 110 |
| 110 function checkVersion(plugin) { | 111 function checkVersion(plugin) { |
| 111 return remoting.apiVersion >= plugin.apiMinVersion && | 112 return remoting.apiVersion >= plugin.apiMinVersion && |
| 112 plugin.apiVersion >= remoting.apiMinVersion; | 113 plugin.apiVersion >= remoting.apiMinVersion; |
| 113 } | 114 } |
| 114 | 115 |
| 115 function init_() { | 116 function init_() { |
| 116 // Kick off the connection. | 117 // Kick off the connection. |
| 117 var plugin = document.getElementById('remoting'); | 118 var plugin = document.getElementById('remoting'); |
| 118 | |
| 119 remoting.plugin = plugin; | 119 remoting.plugin = plugin; |
| 120 | 120 |
| 121 // Only allow https connections to the httpXmppProxy. | 121 // Only allow https connections to the httpXmppProxy. |
| 122 var regExp = /^ *https:\/\//; | 122 var regExp = /^ *https:\/\//; |
| 123 if (remoting.httpXmppProxy.search(regExp) == -1) { | 123 if (remoting.httpXmppProxy.search(regExp) == -1) { |
| 124 addToDebugLog('Aborting. httpXmppProxy does not specify https protocol: ' + | 124 addToDebugLog('Aborting. httpXmppProxy does not specify https protocol: ' + |
| 125 remoting.httpXmppProxy); | 125 remoting.httpXmppProxy); |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 | 128 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 143 if (!checkVersion(plugin)) { | 143 if (!checkVersion(plugin)) { |
| 144 // TODO(garykac): We need better messaging here. Perhaps an install link. | 144 // TODO(garykac): We need better messaging here. Perhaps an install link. |
| 145 setClientStateMessage("Out of date. Please re-install."); | 145 setClientStateMessage("Out of date. Please re-install."); |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 | 148 |
| 149 addToDebugLog('Connect as user ' + remoting.username); | 149 addToDebugLog('Connect as user ' + remoting.username); |
| 150 registerConnection(); | 150 registerConnection(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 function pluginLostFocus_() { |
| 154 // If the plug loses input focus, release all keys as a precaution against |
| 155 // leaving them 'stuck down' on the host. |
| 156 if (remoting.plugin) { |
| 157 remoting.plugin.releaseAllKeys(); |
| 158 } |
| 159 } |
| 160 |
| 153 function toggleScaleToFit() { | 161 function toggleScaleToFit() { |
| 154 remoting.scaleToFit = !remoting.scaleToFit; | 162 remoting.scaleToFit = !remoting.scaleToFit; |
| 155 document.getElementById('scale-to-fit-toggle').value = | 163 document.getElementById('scale-to-fit-toggle').value = |
| 156 remoting.scaleToFit ? 'No scaling' : 'Scale to fit'; | 164 remoting.scaleToFit ? 'No scaling' : 'Scale to fit'; |
| 157 remoting.plugin.setScaleToFit(remoting.scaleToFit); | 165 remoting.plugin.setScaleToFit(remoting.scaleToFit); |
| 158 } | 166 } |
| 159 | 167 |
| 160 /** | 168 /** |
| 161 * This is the callback method that the plugin calls to request username and | 169 * This is the callback method that the plugin calls to request username and |
| 162 * password for logging into the remote host. For Me2Mom we are pre-authorized | 170 * password for logging into the remote host. For Me2Mom we are pre-authorized |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 'Bandwidth: ' + videoBandwidth.toFixed(2) + units + | 316 'Bandwidth: ' + videoBandwidth.toFixed(2) + units + |
| 309 ', Capture: ' + videoCaptureLatency.toFixed(2) + 'ms' + | 317 ', Capture: ' + videoCaptureLatency.toFixed(2) + 'ms' + |
| 310 ', Encode: ' + videoEncodeLatency.toFixed(2) + 'ms' + | 318 ', Encode: ' + videoEncodeLatency.toFixed(2) + 'ms' + |
| 311 ', Decode: ' + videoDecodeLatency.toFixed(2) + 'ms' + | 319 ', Decode: ' + videoDecodeLatency.toFixed(2) + 'ms' + |
| 312 ', Render: ' + videoRenderLatency.toFixed(2) + 'ms' + | 320 ', Render: ' + videoRenderLatency.toFixed(2) + 'ms' + |
| 313 ', Latency: ' + roundTripLatency.toFixed(2) + 'ms'); | 321 ', Latency: ' + roundTripLatency.toFixed(2) + 'ms'); |
| 314 | 322 |
| 315 // Update the stats once per second. | 323 // Update the stats once per second. |
| 316 window.setTimeout('updateStatusBarStats()', 1000); | 324 window.setTimeout('updateStatusBarStats()', 1000); |
| 317 } | 325 } |
| OLD | NEW |