Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1326)

Side by Side Diff: chrome/browser/resources/media_internals/media_internals.js

Issue 7273089: Display active audio streams on chrome://media-internals. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Final(?) nits. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/media_internals/media_internals.css ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 cr.define('media', function() {
6
7 // Stores information on open audio streams, referenced by id.
8 var audioStreams = new media.ItemStore;
9 // The <div> on the page in which to display audio stream data.
10 var audioStreamDiv;
11
12 /**
13 * Initialize variables and ask MediaInternals for all its data.
14 */
15 initialize = function() {
16 audioStreamDiv = document.getElementById('audio-streams');
17 // Get information about all currently active media.
18 chrome.send('getEverything');
19 };
20
21 /**
22 * Write the set of audio streams to the DOM.
23 */
24 printAudioStreams = function() {
25
26 /**
27 * Render a single stream as a <li>.
28 * @param {Object} stream The stream to render.
29 * @return {HTMLElement} A <li> containing the stream information.
30 */
31 printStream = function(stream) {
32 var out = document.createElement('li');
33 out.id = stream.id;
34 out.className = 'audio-stream';
35 out.setAttribute('status', stream.status);
36
37 out.innerHTML += 'Audio stream ' + stream.id.split('.')[1];
38 out.innerHTML += ' is ' + (stream.playing ? 'playing' : 'paused');
39 out.innerHTML += ' at ' + Math.round(stream.volume * 100) + '% volume.';
40 return out;
41 };
42
43 var out = document.createElement('ul');
44 audioStreams.map(printStream).forEach(function(s) {
45 out.appendChild(s)
46 });
47
48 if (audioStreamDiv.textContent)
49 audioStreamDiv.textContent = '';
Evan Stade 2011/07/16 00:34:43 the if is not necessary
Scott Franklin 2011/07/16 00:54:55 Huh... Did not think that one through very clearly
50 audioStreamDiv.appendChild(out);
51 };
52
53 /**
54 * Receiving data for an audio stream.
55 * Add it to audioStreams and update the page.
56 * @param {Object} stream JSON representation of an audio stream.
57 */
58 addAudioStream = function(stream) {
59 audioStreams.addItem(stream);
60 printAudioStreams();
61 };
62
63 /**
64 * Receiving all data.
65 * Add it all to the appropriate stores and update the page.
66 * @param {Object} stuff JSON containing lists of data.
67 * @param {Object} stuff.audio_streams A dictionary of audio streams.
68 */
69 onReceiveEverything = function(stuff) {
70 audioStreams.addItems(stuff.audio_streams);
71 printAudioStreams();
72 };
73
74 /**
75 * Removing an item from the appropriate store.
76 * @param {string} id The id of the item to be removed, in the format
77 * "item_type.identifying_info".
78 */
79 onItemDeleted = function(id) {
80 var type = id.split('.')[0];
81 switch (type) {
82 case 'audio_streams':
83 audioStreams.removeItem(id);
84 printAudioStreams();
85 break;
86 }
87 };
88
89 return {
90 initialize: initialize,
91 addAudioStream: addAudioStream,
92 onReceiveEverything: onReceiveEverything,
93 onItemDeleted: onItemDeleted,
94 };
95 });
96
97 /**
98 * Initialize everything once we have access to the DOM.
99 */
100 window.onload = function() {
101 media.initialize();
102 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/media_internals/media_internals.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698