| 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 // Maximum numer of lines to record in the debug log. | 5 // Maximum numer of lines to record in the debug log. |
| 6 // Only the most recent <n> lines are displayed. | 6 // Only the most recent <n> lines are displayed. |
| 7 var MAX_DEBUG_LOG_SIZE = 1000; | 7 var MAX_DEBUG_LOG_SIZE = 1000; |
| 8 |
| 8 var remoting = chrome.extension.getBackgroundPage().remoting; | 9 var remoting = chrome.extension.getBackgroundPage().remoting; |
| 9 | 10 |
| 11 // Chromoting session API version (for this javascript). |
| 12 // This is compared with the plugin API version to verify that they are |
| 13 // compatible. |
| 14 remoting.apiVersion = 1; |
| 15 |
| 16 // The oldest API version that we support. |
| 17 // This will differ from the |apiVersion| if we maintain backward |
| 18 // compatibility with older API versions. |
| 19 remoting.apiMinVersion = 1; |
| 20 |
| 10 // Message id so that we can identify (and ignore) message fade operations for | 21 // Message id so that we can identify (and ignore) message fade operations for |
| 11 // old messages. This starts at 1 and is incremented for each new message. | 22 // old messages. This starts at 1 and is incremented for each new message. |
| 12 remoting.messageId = 1; | 23 remoting.messageId = 1; |
| 13 | 24 |
| 14 remoting.scaleToFit = false; | 25 remoting.scaleToFit = false; |
| 15 | 26 |
| 16 // Default to trying to sandboxed connections. | 27 // Default to trying to sandboxed connections. |
| 17 remoting.connectMethod = 'sandboxed'; | 28 remoting.connectMethod = 'sandboxed'; |
| 18 remoting.httpXmppProxy = | 29 remoting.httpXmppProxy = |
| 19 'https://chromoting-httpxmpp-oauth2-dev.corp.google.com'; | 30 'https://chromoting-httpxmpp-oauth2-dev.corp.google.com'; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 var xhr = new XMLHttpRequest(); | 99 var xhr = new XMLHttpRequest(); |
| 89 xhr.open('POST', remoting.httpXmppProxy + '/sendIq', true); | 100 xhr.open('POST', remoting.httpXmppProxy + '/sendIq', true); |
| 90 xhr.withCredentials = true; | 101 xhr.withCredentials = true; |
| 91 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | 102 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
| 92 xhr.send('to=' + encodeURIComponent(to) + | 103 xhr.send('to=' + encodeURIComponent(to) + |
| 93 '&payload_xml=' + encodeURIComponent(payload_xml) + | 104 '&payload_xml=' + encodeURIComponent(payload_xml) + |
| 94 '&id=' + id + '&type=' + type + | 105 '&id=' + id + '&type=' + type + |
| 95 '&host_jid=' + encodeURIComponent(remoting.hostjid)); | 106 '&host_jid=' + encodeURIComponent(remoting.hostjid)); |
| 96 } | 107 } |
| 97 | 108 |
| 109 function checkVersion(plugin) { |
| 110 return remoting.apiVersion >= plugin.apiMinVersion && |
| 111 plugin.apiVersion >= remoting.apiMinVersion; |
| 112 } |
| 113 |
| 98 function init() { | 114 function init() { |
| 99 // Kick off the connection. | 115 // Kick off the connection. |
| 100 var plugin = document.getElementById('remoting'); | 116 var plugin = document.getElementById('remoting'); |
| 101 | 117 |
| 102 remoting.plugin = plugin; | 118 remoting.plugin = plugin; |
| 103 | 119 |
| 104 // Only allow https connections to the httpXmppProxy. | 120 // Only allow https connections to the httpXmppProxy. |
| 105 if (remoting.httpXmppProxy.search(/^ *https:\/\//) == -1) { | 121 if (remoting.httpXmppProxy.search(/^ *https:\/\//) == -1) { |
| 106 addToDebugLog('Aborting. httpXmppProxy does not specify https protocol: ' + | 122 addToDebugLog('Aborting. httpXmppProxy does not specify https protocol: ' + |
| 107 remoting.httpXmppProxy); | 123 remoting.httpXmppProxy); |
| 108 return; | 124 return; |
| 109 } | 125 } |
| 110 | 126 |
| 111 // Setup the callback that the plugin will call when the connection status | 127 // Setup the callback that the plugin will call when the connection status |
| 112 // has changes and the UI needs to be updated. It needs to be an object with | 128 // has changes and the UI needs to be updated. It needs to be an object with |
| 113 // a 'callback' property that contains the callback function. | 129 // a 'callback' property that contains the callback function. |
| 114 plugin.connectionInfoUpdate = connectionInfoUpdateCallback; | 130 plugin.connectionInfoUpdate = connectionInfoUpdateCallback; |
| 115 plugin.debugInfo = debugInfoCallback; | 131 plugin.debugInfo = debugInfoCallback; |
| 116 plugin.desktopSizeUpdate = desktopSizeChanged; | 132 plugin.desktopSizeUpdate = desktopSizeChanged; |
| 117 plugin.loginChallenge = loginChallengeCallback; | 133 plugin.loginChallenge = loginChallengeCallback; |
| 118 | 134 |
| 135 if (!checkVersion(plugin)) { |
| 136 // TODO(garykac): We need better messaging here. Perhaps an install link. |
| 137 setClientStateMessage("Out of date. Please re-install."); |
| 138 return; |
| 139 } |
| 140 |
| 119 addToDebugLog('Connect as user ' + remoting.username); | 141 addToDebugLog('Connect as user ' + remoting.username); |
| 120 | 142 |
| 121 // TODO(garykac): Clean exit if |connect| isn't a function. | 143 // TODO(garykac): Clean exit if |connect| isn't a function. |
| 122 if (typeof plugin.connect === 'function') { | 144 if (typeof plugin.connect === 'function') { |
| 123 if (remoting.connectMethod == 'sandboxed') { | 145 if (remoting.connectMethod == 'sandboxed') { |
| 124 registerConnection(); | 146 registerConnection(); |
| 125 } else { | 147 } else { |
| 126 plugin.connect(remoting.username, remoting.hostjid, | 148 plugin.connect(remoting.username, remoting.hostjid, |
| 127 remoting.xmppAuthToken, remoting.accessCode); | 149 remoting.xmppAuthToken, remoting.accessCode); |
| 128 } | 150 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 setClientStateMessage( | 332 setClientStateMessage( |
| 311 'Video stats: bandwidth: ' + videoBandwidth.toFixed(2) + 'Kbps' + | 333 'Video stats: bandwidth: ' + videoBandwidth.toFixed(2) + 'Kbps' + |
| 312 ', Latency: capture: ' + videoCaptureLatency.toFixed(2) + 'ms' + | 334 ', Latency: capture: ' + videoCaptureLatency.toFixed(2) + 'ms' + |
| 313 ', encode: ' + videoEncodeLatency.toFixed(2) + 'ms' + | 335 ', encode: ' + videoEncodeLatency.toFixed(2) + 'ms' + |
| 314 ', decode: ' + videoDecodeLatency.toFixed(2) + 'ms' + | 336 ', decode: ' + videoDecodeLatency.toFixed(2) + 'ms' + |
| 315 ', render: ' + videoRenderLatency.toFixed(2) + 'ms'); | 337 ', render: ' + videoRenderLatency.toFixed(2) + 'ms'); |
| 316 | 338 |
| 317 // Update the stats once per second. | 339 // Update the stats once per second. |
| 318 window.setTimeout('updateStatusBarStats()', 1000); | 340 window.setTimeout('updateStatusBarStats()', 1000); |
| 319 } | 341 } |
| OLD | NEW |