| 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();
|
| +};
|
|
|