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

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: Removing silliness. 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 audioStreamDiv.textContent = '';
49 audioStreamDiv.appendChild(out);
50 };
51
52 /**
53 * Receiving data for an audio stream.
54 * Add it to audioStreams and update the page.
55 * @param {Object} stream JSON representation of an audio stream.
56 */
57 addAudioStream = function(stream) {
58 audioStreams.addItem(stream);
59 printAudioStreams();
60 };
61
62 /**
63 * Receiving all data.
64 * Add it all to the appropriate stores and update the page.
65 * @param {Object} stuff JSON containing lists of data.
66 * @param {Object} stuff.audio_streams A dictionary of audio streams.
67 */
68 onReceiveEverything = function(stuff) {
69 audioStreams.addItems(stuff.audio_streams);
70 printAudioStreams();
71 };
72
73 /**
74 * Removing an item from the appropriate store.
75 * @param {string} id The id of the item to be removed, in the format
76 * "item_type.identifying_info".
77 */
78 onItemDeleted = function(id) {
79 var type = id.split('.')[0];
80 switch (type) {
81 case 'audio_streams':
82 audioStreams.removeItem(id);
83 printAudioStreams();
84 break;
85 }
86 };
87
88 return {
89 initialize: initialize,
90 addAudioStream: addAudioStream,
91 onReceiveEverything: onReceiveEverything,
92 onItemDeleted: onItemDeleted,
93 };
94 });
95
96 /**
97 * Initialize everything once we have access to the DOM.
98 */
99 window.onload = function() {
100 media.initialize();
101 };
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