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 var remoting = chrome.extension.getBackgroundPage().remoting; | 9 var remoting = chrome.extension.getBackgroundPage().remoting; |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 // 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. |
23 remoting.messageId = 1; | 23 remoting.messageId = 1; |
24 | 24 |
25 remoting.scaleToFit = false; | 25 remoting.scaleToFit = false; |
26 | 26 |
27 // Default to trying to sandboxed connections. | 27 // Default to trying to sandboxed connections. |
28 remoting.connectMethod = 'sandboxed'; | 28 remoting.connectMethod = 'sandboxed'; |
29 remoting.httpXmppProxy = | 29 remoting.httpXmppProxy = |
30 'https://chromoting-httpxmpp-oauth2-dev.corp.google.com'; | 30 'https://chromoting-httpxmpp-oauth2-dev.corp.google.com'; |
31 | 31 |
| 32 window.addEventListener("load", init_, false); |
| 33 |
32 // This executes a poll loop on the server for more Iq packets, and feeds them | 34 // This executes a poll loop on the server for more Iq packets, and feeds them |
33 // to the plugin. | 35 // to the plugin. |
34 function feedIq() { | 36 function feedIq() { |
35 var xhr = new XMLHttpRequest(); | 37 var xhr = new XMLHttpRequest(); |
36 xhr.open('GET', remoting.httpXmppProxy + '/readIq?host_jid=' + | 38 xhr.open('GET', remoting.httpXmppProxy + '/readIq?host_jid=' + |
37 encodeURIComponent(remoting.hostjid), true); | 39 encodeURIComponent(remoting.hostjid), true); |
38 xhr.withCredentials = true; | 40 xhr.withCredentials = true; |
39 xhr.onreadystatechange = function() { | 41 xhr.onreadystatechange = function() { |
40 if (xhr.readyState == 4) { | 42 if (xhr.readyState == 4) { |
41 if (xhr.status == 200) { | 43 if (xhr.status == 200) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 '&payload_xml=' + encodeURIComponent(payload_xml) + | 106 '&payload_xml=' + encodeURIComponent(payload_xml) + |
105 '&id=' + id + '&type=' + type + | 107 '&id=' + id + '&type=' + type + |
106 '&host_jid=' + encodeURIComponent(remoting.hostjid)); | 108 '&host_jid=' + encodeURIComponent(remoting.hostjid)); |
107 } | 109 } |
108 | 110 |
109 function checkVersion(plugin) { | 111 function checkVersion(plugin) { |
110 return remoting.apiVersion >= plugin.apiMinVersion && | 112 return remoting.apiVersion >= plugin.apiMinVersion && |
111 plugin.apiVersion >= remoting.apiMinVersion; | 113 plugin.apiVersion >= remoting.apiMinVersion; |
112 } | 114 } |
113 | 115 |
114 function init() { | 116 function init_() { |
115 // Kick off the connection. | 117 // Kick off the connection. |
116 var plugin = document.getElementById('remoting'); | 118 var plugin = document.getElementById('remoting'); |
117 | 119 |
118 remoting.plugin = plugin; | 120 remoting.plugin = plugin; |
119 | 121 |
120 // Only allow https connections to the httpXmppProxy. | 122 // Only allow https connections to the httpXmppProxy. |
121 var regExp = /^ *https:\/\//; | 123 var regExp = /^ *https:\/\//; |
122 if (remoting.httpXmppProxy.search(regExp) == -1) { | 124 if (remoting.httpXmppProxy.search(regExp) == -1) { |
123 addToDebugLog('Aborting. httpXmppProxy does not specify https protocol: ' + | 125 addToDebugLog('Aborting. httpXmppProxy does not specify https protocol: ' + |
124 remoting.httpXmppProxy); | 126 remoting.httpXmppProxy); |
(...skipping 26 matching lines...) Expand all Loading... |
151 remoting.accessCode); | 153 remoting.accessCode); |
152 } | 154 } |
153 } else { | 155 } else { |
154 addToDebugLog('ERROR: remoting plugin not loaded'); | 156 addToDebugLog('ERROR: remoting plugin not loaded'); |
155 setClientStateMessage('Plugin not loaded'); | 157 setClientStateMessage('Plugin not loaded'); |
156 } | 158 } |
157 | 159 |
158 } | 160 } |
159 | 161 |
160 function toggleDebugLog() { | 162 function toggleDebugLog() { |
161 debugLog = document.getElementById('debug_log'); | 163 debugLog = document.getElementById('debug-log'); |
162 toggleButton = document.getElementById('debug_log_toggle'); | 164 toggleButton = document.getElementById('debug-log-toggle'); |
163 | 165 |
164 if (!debugLog.style.display || debugLog.style.display == 'none') { | 166 if (!debugLog.style.display || debugLog.style.display == 'none') { |
165 debugLog.style.display = 'block'; | 167 debugLog.style.display = 'block'; |
166 toggleButton.value = 'Hide Debug Log'; | 168 toggleButton.value = 'Hide Debug Log'; |
167 } else { | 169 } else { |
168 debugLog.style.display = 'none'; | 170 debugLog.style.display = 'none'; |
169 toggleButton.value = 'Show Debug Log'; | 171 toggleButton.value = 'Show Debug Log'; |
170 } | 172 } |
171 } | 173 } |
172 | 174 |
173 function toggleScaleToFit() { | 175 function toggleScaleToFit() { |
174 remoting.scaleToFit = !remoting.scaleToFit; | 176 remoting.scaleToFit = !remoting.scaleToFit; |
175 document.getElementById('scale_to_fit_toggle').value = | 177 document.getElementById('scale-to-fit-toggle').value = |
176 remoting.scaleToFit ? 'No scaling' : 'Scale to fit'; | 178 remoting.scaleToFit ? 'No scaling' : 'Scale to fit'; |
177 remoting.plugin.setScaleToFit(remoting.scaleToFit); | 179 remoting.plugin.setScaleToFit(remoting.scaleToFit); |
178 } | 180 } |
179 | 181 |
180 /** | 182 /** |
181 * This is the callback method that the plugin calls to request username and | 183 * This is the callback method that the plugin calls to request username and |
182 * password for logging into the remote host. For Me2Mom we are pre-authorized | 184 * password for logging into the remote host. For Me2Mom we are pre-authorized |
183 * so this is a no-op. | 185 * so this is a no-op. |
184 */ | 186 */ |
185 function loginChallengeCallback() { | 187 function loginChallengeCallback() { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 /** | 228 /** |
227 * Show a client message that stays on the screeen until the state changes. | 229 * Show a client message that stays on the screeen until the state changes. |
228 * | 230 * |
229 * @param {string} message The message to display. | 231 * @param {string} message The message to display. |
230 */ | 232 */ |
231 function setClientStateMessage(message) { | 233 function setClientStateMessage(message) { |
232 // Increment message id to ignore any previous fadeout requests. | 234 // Increment message id to ignore any previous fadeout requests. |
233 remoting.messageId++; | 235 remoting.messageId++; |
234 | 236 |
235 // Update the status message. | 237 // Update the status message. |
236 var msg = document.getElementById('status_msg'); | 238 var msg = document.getElementById('status-msg'); |
237 msg.innerText = message; | 239 msg.innerText = message; |
238 msg.style.opacity = 1; | 240 msg.style.opacity = 1; |
239 msg.style.display = ''; | 241 msg.style.display = ''; |
240 } | 242 } |
241 | 243 |
242 /** | 244 /** |
243 * Show a client message for the specified amount of time. | 245 * Show a client message for the specified amount of time. |
244 * | 246 * |
245 * @param {string} message The message to display. | 247 * @param {string} message The message to display. |
246 * @param {number} duration Milliseconds to show message before fading. | 248 * @param {number} duration Milliseconds to show message before fading. |
247 */ | 249 */ |
248 function setClientStateMessageFade(message, duration) { | 250 function setClientStateMessageFade(message, duration) { |
249 setClientStateMessage(message); | 251 setClientStateMessage(message); |
250 | 252 |
251 // Set message duration. | 253 // Set message duration. |
252 window.setTimeout("fade('status_msg', " + remoting.messageId + ', ' + | 254 window.setTimeout("fade('status-msg', " + remoting.messageId + ', ' + |
253 '100, 10, 200)', | 255 '100, 10, 200)', |
254 duration); | 256 duration); |
255 } | 257 } |
256 | 258 |
257 /** | 259 /** |
258 * Fade the specified element. | 260 * Fade the specified element. |
259 * For example, to have element 'foo' fade away over 2 seconds, you could use | 261 * For example, to have element 'foo' fade away over 2 seconds, you could use |
260 * either: | 262 * either: |
261 * fade('foo', 100, 10, 200) | 263 * fade('foo', 100, 10, 200) |
262 * - Start at 100%, decrease by 10% each time, wait 200ms between updates. | 264 * - Start at 100%, decrease by 10% each time, wait 200ms between updates. |
(...skipping 11 matching lines...) Expand all Loading... |
274 if (id != remoting.messageId) { | 276 if (id != remoting.messageId) { |
275 return; | 277 return; |
276 } | 278 } |
277 | 279 |
278 var e = document.getElementById(name); | 280 var e = document.getElementById(name); |
279 if (e) { | 281 if (e) { |
280 var newVal = val - delta; | 282 var newVal = val - delta; |
281 if (newVal > 0) { | 283 if (newVal > 0) { |
282 // Decrease opacity and set timer for next fade event. | 284 // Decrease opacity and set timer for next fade event. |
283 e.style.opacity = newVal / 100; | 285 e.style.opacity = newVal / 100; |
284 window.setTimeout("fade('status_msg', " + id + ', ' + newVal + ', ' + | 286 window.setTimeout("fade('status-msg', " + id + ', ' + newVal + ', ' + |
285 delta + ', ' + delay + ')', | 287 delta + ', ' + delay + ')', |
286 delay); | 288 delay); |
287 } else { | 289 } else { |
288 // Completely hide the text and stop fading. | 290 // Completely hide the text and stop fading. |
289 e.style.opacity = 0; | 291 e.style.opacity = 0; |
290 e.style.display = 'none'; | 292 e.style.display = 'none'; |
291 } | 293 } |
292 } | 294 } |
293 } | 295 } |
294 | 296 |
295 /** | 297 /** |
296 * This is that callback that the plugin invokes to indicate that there | 298 * This is that callback that the plugin invokes to indicate that there |
297 * is additional debug log info to display. | 299 * is additional debug log info to display. |
298 */ | 300 */ |
299 function debugInfoCallback(msg) { | 301 function debugInfoCallback(msg) { |
300 addToDebugLog('plugin: ' + msg); | 302 addToDebugLog('plugin: ' + msg); |
301 } | 303 } |
302 | 304 |
303 /** | 305 /** |
304 * Add the given message to the debug log. | 306 * Add the given message to the debug log. |
305 * | 307 * |
306 * @param {string} message The debug info to add to the log. | 308 * @param {string} message The debug info to add to the log. |
307 */ | 309 */ |
308 function addToDebugLog(message) { | 310 function addToDebugLog(message) { |
309 var debugLog = document.getElementById('debug_log'); | 311 var debugLog = document.getElementById('debug-log'); |
310 | 312 |
311 // Remove lines from top if we've hit our max log size. | 313 // Remove lines from top if we've hit our max log size. |
312 if (debugLog.childNodes.length == MAX_DEBUG_LOG_SIZE) { | 314 if (debugLog.childNodes.length == MAX_DEBUG_LOG_SIZE) { |
313 debugLog.removeChild(debugLog.firstChild); | 315 debugLog.removeChild(debugLog.firstChild); |
314 } | 316 } |
315 | 317 |
316 // Add the new <p> to the end of the debug log. | 318 // Add the new <p> to the end of the debug log. |
317 var p = document.createElement('p'); | 319 var p = document.createElement('p'); |
318 p.appendChild(document.createTextNode(message)); | 320 p.appendChild(document.createTextNode(message)); |
319 debugLog.appendChild(p); | 321 debugLog.appendChild(p); |
320 | 322 |
321 // Scroll to bottom of div | 323 // Scroll to bottom of div |
322 debugLog.scrollTop = debugLog.scrollHeight; | 324 debugLog.scrollTop = debugLog.scrollHeight; |
323 } | 325 } |
324 | 326 |
325 function updateStatusBarStats() { | 327 function updateStatusBarStats() { |
326 if (remoting.plugin.status != remoting.plugin.STATUS_CONNECTED) | 328 if (remoting.plugin.status != remoting.plugin.STATUS_CONNECTED) |
327 return; | 329 return; |
328 var videoBandwidth = remoting.plugin.videoBandwidth; | 330 var videoBandwidth = remoting.plugin.videoBandwidth; |
329 var videoCaptureLatency = remoting.plugin.videoCaptureLatency; | 331 var videoCaptureLatency = remoting.plugin.videoCaptureLatency; |
330 var videoEncodeLatency = remoting.plugin.videoEncodeLatency; | 332 var videoEncodeLatency = remoting.plugin.videoEncodeLatency; |
331 var videoDecodeLatency = remoting.plugin.videoDecodeLatency; | 333 var videoDecodeLatency = remoting.plugin.videoDecodeLatency; |
332 var videoRenderLatency = remoting.plugin.videoRenderLatency; | 334 var videoRenderLatency = remoting.plugin.videoRenderLatency; |
333 | 335 |
334 var units = ''; | 336 var units = ''; |
335 if (videoBandwidth < 1024) { | 337 if (videoBandwidth < 1024) { |
336 units = 'Bps'; | 338 units = 'Bps'; |
337 } else if (videoBandwidth < 1048576) { | 339 } else if (videoBandwidth < 1048576) { |
338 units = 'KBps'; | 340 units = 'KiBps'; |
339 videoBandwidth = videoBandwidth / 1024; | 341 videoBandwidth = videoBandwidth / 1024; |
340 } else if (videoBandwidth < 1073741824) { | 342 } else if (videoBandwidth < 1073741824) { |
341 units = 'MBps'; | 343 units = 'MiBps'; |
342 videoBandwidth = videoBandwidth / 1048576; | 344 videoBandwidth = videoBandwidth / 1048576; |
343 } else { | 345 } else { |
344 units = 'GBps'; | 346 units = 'GiBps'; |
345 videoBandwidth = videoBandwidth / 1073741824; | 347 videoBandwidth = videoBandwidth / 1073741824; |
346 } | 348 } |
347 | 349 |
348 setClientStateMessage( | 350 setClientStateMessage( |
349 'Video stats: bandwidth: ' + videoBandwidth.toFixed(2) + units + | 351 'Bandwidth: ' + videoBandwidth.toFixed(2) + units + |
350 ', Latency: capture: ' + videoCaptureLatency.toFixed(2) + 'ms' + | 352 ', Capture: ' + videoCaptureLatency.toFixed(2) + 'ms' + |
351 ', encode: ' + videoEncodeLatency.toFixed(2) + 'ms' + | 353 ', Encode: ' + videoEncodeLatency.toFixed(2) + 'ms' + |
352 ', decode: ' + videoDecodeLatency.toFixed(2) + 'ms' + | 354 ', Decode: ' + videoDecodeLatency.toFixed(2) + 'ms' + |
353 ', render: ' + videoRenderLatency.toFixed(2) + 'ms'); | 355 ', Render: ' + videoRenderLatency.toFixed(2) + 'ms'); |
354 | 356 |
355 // Update the stats once per second. | 357 // Update the stats once per second. |
356 window.setTimeout('updateStatusBarStats()', 1000); | 358 window.setTimeout('updateStatusBarStats()', 1000); |
357 } | 359 } |
OLD | NEW |