OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Module to support debug overlay window with connection stats. | 7 * Module to support debug overlay window with connection stats. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
11 | 11 |
12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
14 | 14 |
15 /** | 15 /** |
16 * @constructor | 16 * @constructor |
| 17 * @param {Element} statsElement The HTML div to which to update stats. |
| 18 * @param {remoting.ClientPlugin} plugin |
| 19 * |
17 * @implements {remoting.WindowShape.ClientUI} | 20 * @implements {remoting.WindowShape.ClientUI} |
18 * @param {Element} statsElement The HTML div to which to update stats. | 21 * @implements {base.Disposable} |
19 */ | 22 */ |
20 remoting.ConnectionStats = function(statsElement) { | 23 remoting.ConnectionStats = function(statsElement, plugin) { |
21 /** @private */ | 24 /** @private */ |
22 this.statsElement_ = statsElement; | 25 this.statsElement_ = statsElement; |
23 | 26 |
24 /** @private {remoting.ClientSession.PerfStats} */ | 27 /** @private {remoting.ClientSession.PerfStats} */ |
25 this.mostRecent_ = null | 28 this.mostRecent_ = null |
26 | 29 |
| 30 /** @private */ |
| 31 this.plugin_ = plugin; |
| 32 |
| 33 var that = this; |
| 34 |
| 35 /** @private */ |
| 36 this.timer_ = new base.RepeatingTimer(function(){ |
| 37 that.update(plugin.getPerfStats()); |
| 38 }, 1000, true); |
| 39 |
27 remoting.windowShape.addCallback(this); | 40 remoting.windowShape.addCallback(this); |
28 }; | 41 }; |
29 | 42 |
| 43 remoting.ConnectionStats.prototype.dispose = function() { |
| 44 base.dispose(this.timer_); |
| 45 this.timer_ = null; |
| 46 this.plugin_ = null; |
| 47 }; |
| 48 |
30 /** | 49 /** |
31 * @return {remoting.ClientSession.PerfStats} The most recently-set PerfStats, | 50 * @return {remoting.ClientSession.PerfStats} The most recently-set PerfStats, |
32 * or null if update() has not yet been called. | 51 * or null if update() has not yet been called. |
33 */ | 52 */ |
34 remoting.ConnectionStats.prototype.mostRecent = function() { | 53 remoting.ConnectionStats.prototype.mostRecent = function() { |
35 return this.mostRecent_; | 54 return this.mostRecent_; |
36 }; | 55 }; |
37 | 56 |
38 /** | 57 /** |
39 * Show or hide the connection stats div. | 58 * Show or hide the connection stats div. |
40 */ | 59 */ |
41 remoting.ConnectionStats.prototype.toggle = function() { | 60 remoting.ConnectionStats.prototype.toggle = function() { |
42 this.statsElement_.hidden = !this.statsElement_.hidden; | 61 this.statsElement_.hidden = !this.statsElement_.hidden; |
43 }; | 62 }; |
44 | 63 |
45 /** | 64 /** |
| 65 * @return {boolean} |
| 66 */ |
| 67 remoting.ConnectionStats.prototype.isVisible = function() { |
| 68 return !this.statsElement_.hidden; |
| 69 }; |
| 70 |
| 71 /** |
46 * Show or hide the connection stats div. | 72 * Show or hide the connection stats div. |
47 * @param {boolean} show | 73 * @param {boolean} show |
48 */ | 74 */ |
49 remoting.ConnectionStats.prototype.show = function(show) { | 75 remoting.ConnectionStats.prototype.show = function(show) { |
50 this.statsElement_.hidden = !show; | 76 this.statsElement_.hidden = !show; |
51 }; | 77 }; |
52 | 78 |
53 /** | 79 /** |
54 * If the stats panel is visible, add its bounding rectangle to the specified | 80 * If the stats panel is visible, add its bounding rectangle to the specified |
55 * region. | 81 * region. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 var statistics = document.getElementById('statistics'); | 128 var statistics = document.getElementById('statistics'); |
103 this.statsElement_.innerText = ( | 129 this.statsElement_.innerText = ( |
104 'Bandwidth: ' + formatStatNumber(videoBandwidth, units) + | 130 'Bandwidth: ' + formatStatNumber(videoBandwidth, units) + |
105 ', Frame Rate: ' + formatStatNumber(stats.videoFrameRate, 'fps') + | 131 ', Frame Rate: ' + formatStatNumber(stats.videoFrameRate, 'fps') + |
106 ', Capture: ' + formatStatNumber(stats.captureLatency, 'ms') + | 132 ', Capture: ' + formatStatNumber(stats.captureLatency, 'ms') + |
107 ', Encode: ' + formatStatNumber(stats.encodeLatency, 'ms') + | 133 ', Encode: ' + formatStatNumber(stats.encodeLatency, 'ms') + |
108 ', Decode: ' + formatStatNumber(stats.decodeLatency, 'ms') + | 134 ', Decode: ' + formatStatNumber(stats.decodeLatency, 'ms') + |
109 ', Render: ' + formatStatNumber(stats.renderLatency, 'ms') + | 135 ', Render: ' + formatStatNumber(stats.renderLatency, 'ms') + |
110 ', Latency: ' + formatStatNumber(stats.roundtripLatency, 'ms')); | 136 ', Latency: ' + formatStatNumber(stats.roundtripLatency, 'ms')); |
111 }; | 137 }; |
112 | |
113 /** | |
114 * Check for the debug toggle hot-key. | |
115 * | |
116 * @param {Event} event The keyboard event. | |
117 * @return {void} Nothing. | |
118 */ | |
119 remoting.ConnectionStats.onKeydown = function(event) { | |
120 var element = /** @type {Element} */ (event.target); | |
121 if (element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') { | |
122 return; | |
123 } | |
124 if (String.fromCharCode(event.which) == 'D') { | |
125 remoting.stats.toggle(); | |
126 } | |
127 }; | |
128 | |
129 /** @type {remoting.ConnectionStats} */ | |
130 remoting.stats = null; | |
OLD | NEW |