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 |
9 // Chromoting session API version (for this javascript). | |
10 // This is compared with the plugin API version to verify that they are | |
11 // compatible. | |
12 chromoting.apiVersion = 42; | |
Jamie
2011/05/25 00:29:34
Apart from the HHGTTG reference, why 42? Left-over
garykac
2011/05/25 16:39:44
Indeed. leftover debugging. I fixed up the webapp
| |
13 | |
14 // The oldest API version that we support. | |
15 // This will differ from the |apiVersion| if we decide to maintain backward | |
16 // compatibility with older API versions. | |
17 chromoting.apiMinVersion = 1; | |
18 | |
9 // Message id so that we can identify (and ignore) message fade operations for | 19 // Message id so that we can identify (and ignore) message fade operations for |
10 // old messages. This starts at 1 and is incremented for each new message. | 20 // old messages. This starts at 1 and is incremented for each new message. |
11 chromoting.messageId = 1; | 21 chromoting.messageId = 1; |
12 | 22 |
13 chromoting.scaleToFit = false; | 23 chromoting.scaleToFit = false; |
14 | 24 |
15 // Default to trying to sandboxed connections. | 25 // Default to trying to sandboxed connections. |
16 chromoting.connectMethod = 'sandboxed'; | 26 chromoting.connectMethod = 'sandboxed'; |
17 | 27 |
18 // This executes a poll loop on the server for more Iq packets, and feeds them | 28 // This executes a poll loop on the server for more Iq packets, and feeds them |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 var xhr = new XMLHttpRequest(); | 97 var xhr = new XMLHttpRequest(); |
88 xhr.open("POST", chromoting.httpXmppProxy + '/sendIq', true); | 98 xhr.open("POST", chromoting.httpXmppProxy + '/sendIq', true); |
89 xhr.withCredentials = true; | 99 xhr.withCredentials = true; |
90 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | 100 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
91 xhr.send("to=" + encodeURIComponent(to) + | 101 xhr.send("to=" + encodeURIComponent(to) + |
92 "&payload_xml=" + encodeURIComponent(payload_xml) + | 102 "&payload_xml=" + encodeURIComponent(payload_xml) + |
93 "&id=" + id + "&type=" + type + | 103 "&id=" + id + "&type=" + type + |
94 "&host_jid=" + encodeURIComponent(chromoting.hostjid)); | 104 "&host_jid=" + encodeURIComponent(chromoting.hostjid)); |
95 } | 105 } |
96 | 106 |
107 function checkVersion(plugin) { | |
108 return chromoting.apiVersion >= plugin.apiMinVersion && | |
109 plugin.apiVersion >= chromoting.apiMinVersion; | |
110 } | |
111 | |
97 function init() { | 112 function init() { |
98 // Kick off the connection. | 113 // Kick off the connection. |
99 var plugin = document.getElementById('chromoting'); | 114 var plugin = document.getElementById('chromoting'); |
100 | 115 |
101 chromoting.plugin = plugin; | 116 chromoting.plugin = plugin; |
102 chromoting.username = document.username; | 117 chromoting.username = document.username; |
103 chromoting.hostname = document.hostname; | 118 chromoting.hostname = document.hostname; |
104 chromoting.hostjid = document.hostjid; | 119 chromoting.hostjid = document.hostjid; |
105 chromoting.talkToken = document.talkToken; | 120 chromoting.talkToken = document.talkToken; |
106 chromoting.connectMethod = document.connectMethod; | 121 chromoting.connectMethod = document.connectMethod; |
(...skipping 10 matching lines...) Expand all Loading... | |
117 chromoting.httpXmppProxy = document.httpXmppProxy; | 132 chromoting.httpXmppProxy = document.httpXmppProxy; |
118 | 133 |
119 // Setup the callback that the plugin will call when the connection status | 134 // Setup the callback that the plugin will call when the connection status |
120 // has changes and the UI needs to be updated. It needs to be an object with | 135 // has changes and the UI needs to be updated. It needs to be an object with |
121 // a 'callback' property that contains the callback function. | 136 // a 'callback' property that contains the callback function. |
122 plugin.connectionInfoUpdate = connectionInfoUpdateCallback; | 137 plugin.connectionInfoUpdate = connectionInfoUpdateCallback; |
123 plugin.debugInfo = debugInfoCallback; | 138 plugin.debugInfo = debugInfoCallback; |
124 plugin.desktopSizeUpdate = desktopSizeChanged; | 139 plugin.desktopSizeUpdate = desktopSizeChanged; |
125 plugin.loginChallenge = loginChallengeCallback; | 140 plugin.loginChallenge = loginChallengeCallback; |
126 | 141 |
142 if (!checkVersion(plugin)) { | |
143 // TODO(garykac): We need better messaging here. Perhaps an install link. | |
144 setClientStateMessage("Out of date. Please re-install."); | |
145 return; | |
146 } | |
147 | |
127 addToDebugLog('Connect to ' + chromoting.hostname + ' as user ' + | 148 addToDebugLog('Connect to ' + chromoting.hostname + ' as user ' + |
128 chromoting.username); | 149 chromoting.username); |
129 | 150 |
130 // TODO(garykac): Clean exit if |connect| isn't a function. | 151 // TODO(garykac): Clean exit if |connect| isn't a function. |
131 if (typeof plugin.connect === 'function') { | 152 if (typeof plugin.connect === 'function') { |
132 if (chromoting.connectMethod == "sandboxed") { | 153 if (chromoting.connectMethod == "sandboxed") { |
133 registerConnection(); | 154 registerConnection(); |
134 } else { | 155 } else { |
135 // TODO:(jamiewalch): Pass in the correct nonce. | 156 // TODO:(jamiewalch): Pass in the correct nonce. |
136 plugin.connect(chromoting.username, chromoting.hostjid, | 157 plugin.connect(chromoting.username, chromoting.hostjid, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 setClientStateMessage( | 362 setClientStateMessage( |
342 "Video stats: bandwidth: " + videoBandwidth.toFixed(2) + "Kbps" + | 363 "Video stats: bandwidth: " + videoBandwidth.toFixed(2) + "Kbps" + |
343 ", Latency: capture: " + videoCaptureLatency.toFixed(2) + "ms" + | 364 ", Latency: capture: " + videoCaptureLatency.toFixed(2) + "ms" + |
344 ", encode: " + videoEncodeLatency.toFixed(2) + "ms" + | 365 ", encode: " + videoEncodeLatency.toFixed(2) + "ms" + |
345 ", decode: " + videoDecodeLatency.toFixed(2) + "ms" + | 366 ", decode: " + videoDecodeLatency.toFixed(2) + "ms" + |
346 ", render: " + videoRenderLatency.toFixed(2) + "ms"); | 367 ", render: " + videoRenderLatency.toFixed(2) + "ms"); |
347 | 368 |
348 // Update the stats once per second. | 369 // Update the stats once per second. |
349 window.setTimeout("updateStatusBarStats()", 1000); | 370 window.setTimeout("updateStatusBarStats()", 1000); |
350 } | 371 } |
OLD | NEW |