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

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: Fixing bug and removing double quotes. 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
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..4ac9d5e240bf987e2c74909c13a033fd091025b7
--- /dev/null
+++ b/chrome/browser/resources/media_internals/media_internals.js
@@ -0,0 +1,102 @@
+// 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;
+
+ /**
+ * 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) });
+
+ if (audioStreamDiv.firstChild)
+ audioStreamDiv.removeChild(audioStreamDiv.firstChild);
+ audioStreamDiv.appendChild(out);
+ };
+
+ /**
+ * 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');
+ };
+
+ return {
+ printAudioStreams: printAudioStreams,
+ audioStreams: audioStreams,
+ initialize: initialize
+ };
+
+});
+
+/**
+ * Receiving data for an audio stream.
+ * Add it to audioStreams and refresh.
+ *
+ * @param {Object} stream JSON representation of an audio stream.
+ */
+onAudioUpdate = function(stream) {
+ media.audioStreams.addItem(stream);
+ media.printAudioStreams();
+};
+
+/**
+ * Receiving all data.
+ * Add it all to the appropriate stores and refresh.
+ *
+ * @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;
+ }
+};
+
+/**
+ * Initialize everything once we have access to the DOM.
+ */
+window.onload = function() {
+ media.initialize();
+};

Powered by Google App Engine
This is Rietveld 408576698