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

Unified 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: Nitpicking, reordering methods. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/media_internals/media_internals.css ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/media_internals/media_internals.js
diff --git a/chrome/browser/resources/media_internals/media_internals.js b/chrome/browser/resources/media_internals/media_internals.js
new file mode 100644
index 0000000000000000000000000000000000000000..0801f71f982b07165b1b5ea127218feaeb670aca
--- /dev/null
+++ b/chrome/browser/resources/media_internals/media_internals.js
@@ -0,0 +1,101 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('media', function() {
+
+ var audioStreams = new media.ItemStore;
+ var audioStreamDiv;
Evan Stade 2011/07/15 23:38:58 document these vars
Scott Franklin 2011/07/16 00:07:32 Done.
+
+ /**
+ * Initialize variables and ask MediaInternals for all its data.
+ */
+ initialize = function() {
+ audioStreamDiv = document.getElementById('audio-streams');
+ // Get information about all currently active media.
+ chrome.send('getEverything');
+ };
+
+ /**
+ * Write the set of audio streams to the DOM.
+ */
+ printAudioStreams = function() {
+
+ /**
+ * Render a single stream as a <li>.
+ * @param {Object} stream The stream to render.
+ * @return {HTMLElement} A <li> containing the stream information.
+ */
+ printStream = function(stream) {
+ var out = document.createElement('li');
+ out.id = stream.id;
+ out.className = 'audio-stream';
+ out.setAttribute('status', stream.status);
+
+ out.innerHTML += 'Audio stream ' + stream.id.split('.')[1];
+ out.innerHTML += ' is ' + (stream.playing ? 'playing' : 'paused');
+ out.innerHTML += ' at ' + Math.round(stream.volume * 100) + '% volume.';
+ return out;
+ };
+
+ var out = document.createElement('ul');
+ audioStreams.map(printStream).forEach(function(s) { out.appendChild(s) });
Evan Stade 2011/07/15 23:38:58 I believe the proper spacing is audioStreams.map(
Scott Franklin 2011/07/16 00:07:32 Done.
+
+ if (audioStreamDiv.firstChild)
Evan Stade 2011/07/15 23:38:58 audioStreamDiv.textContent = '';
Scott Franklin 2011/07/16 00:07:32 Done, both in the if and below.
+ audioStreamDiv.removeChild(audioStreamDiv.firstChild);
+ audioStreamDiv.appendChild(out);
+ };
+
+ /**
+ * Receiving data for an audio stream.
+ * Add it to audioStreams and refresh.
+ * @param {Object} stream JSON representation of an audio stream.
+ */
+ onAudioUpdate = function(stream) {
Evan Stade 2011/07/15 23:38:58 I think addAudioStream is a more appropriate name
Scott Franklin 2011/07/16 00:07:32 Done.
+ media.audioStreams.addItem(stream);
+ media.printAudioStreams();
+ };
+
+ /**
+ * Receiving all data.
+ * Add it all to the appropriate stores and refresh.
Evan Stade 2011/07/15 23:38:58 I don't understand 'refresh' in this context. Do y
Scott Franklin 2011/07/16 00:07:32 It was an attempt to describe the operation of wri
+ *
Evan Stade 2011/07/15 23:38:58 remove
Scott Franklin 2011/07/16 00:07:32 Done.
+ * @param {Object} stuff JSON containing lists of data.
+ * @param {Object} stuff.audio_streams A dictionary of audio streams.
+ */
+ onReceiveEverything = function(stuff) {
+ media.audioStreams.addItems(stuff.audio_streams);
+ media.printAudioStreams();
+ };
+
+ /**
+ * Removing an item from the appropriate store.
+ * @param {string} id The id of the item to be removed, in the format
+ * "item_type.identifying_info".
+ */
+ onItemDeleted = function(id) {
+ var type = id.split('.')[0];
+ switch (type) {
+ case 'audio_streams':
+ media.audioStreams.removeItem(id);
+ media.printAudioStreams();
+ break;
+ }
+ };
+
+ return {
+ initialize: initialize,
+ printAudioStreams: printAudioStreams,
+ onAudioUpdate: onAudioUpdate,
+ onReceiveEverything: onReceiveEverything,
+ onItemDeleted: onItemDeleted,
+ audioStreams: audioStreams
+ };
+});
+
+/**
+ * Initialize everything once we have access to the DOM.
+ */
+window.onload = function() {
+ media.initialize();
+};
« 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