OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 /** @enum {string} */ var AudioNodeType = { |
| 6 HEADPHONE: 'HEADPHONE', |
| 7 MIC: 'MIC', |
| 8 USB: 'USB', |
| 9 BLUETOOTH: 'BLUETOOTH', |
| 10 HDMI: 'HDMI', |
| 11 INTERNAL_SPEAKER: 'INTERNAL_SPEAKER', |
| 12 INTERNAL_MIC: 'INTERNAL_MIC', |
| 13 KEYBOARD_MIC: 'KEYBOARD_MIC', |
| 14 AOKR: 'AOKR', |
| 15 POST_MIX_LOOPBACK: 'POST_MIX_LOOPBACK', |
| 16 POST_DSP_LOOPBACK: 'POST_DSP_LOOPBACK', |
| 17 OTHER: 'OTHER', |
| 18 NONE: '', |
| 19 }; |
| 20 |
| 21 /** |
| 22 * An audio node. Based on the struct AudioNode found in audio_node.h. |
| 23 * @constructor |
| 24 */ |
| 25 var AudioNode = function() { |
| 26 // Whether node will input or output audio. |
| 27 this.isInput = false; |
| 28 |
| 29 // Node ID. Set to arbitrary default. |
| 30 this.id = '30001'; |
| 31 |
| 32 // Display name of the node. When this is empty, cras will automatically |
| 33 // use |this.deviceName| as the display name. |
| 34 this.name = ''; |
| 35 |
| 36 // The text label of the selected node name. |
| 37 this.deviceName = 'New Device'; |
| 38 |
| 39 // Based on the AudioNodeType enum. |
| 40 this.type = AudioNodeType.HEADPHONE; |
| 41 |
| 42 // Whether the node is active or not. |
| 43 this.active = false; |
| 44 |
| 45 // The time the node was plugged in (in seconds). |
| 46 this.pluggedTime = 0; |
| 47 }; |
| 48 |
| 49 Polymer({ |
| 50 is: 'audio-settings', |
| 51 |
| 52 properties: { |
| 53 /** |
| 54 * The title to be displayed in a heading element for the element. |
| 55 */ |
| 56 title: {type: String}, |
| 57 |
| 58 /** |
| 59 * A set of audio nodes. |
| 60 * @type !Array<!AudioNode> |
| 61 */ |
| 62 nodes: {type: Array, value: function() { return []; }}, |
| 63 |
| 64 /** |
| 65 * A set of options for the possible audio node types. |
| 66 * AudioNodeType |type| is based on the AudioType emumation. |
| 67 * @type {!Array<!{name: string, type: string}>} |
| 68 */ |
| 69 nodeTypeOptions: { |
| 70 type: Array, |
| 71 value: function() { |
| 72 return [ |
| 73 {name: 'Headphones', type: AudioNodeType.HEADPHONE}, |
| 74 {name: 'Mic', type: AudioNodeType.MIC}, |
| 75 {name: 'Usb', type: AudioNodeType.USB}, |
| 76 {name: 'Bluetooth', type: AudioNodeType.BLUETOOTH}, |
| 77 {name: 'HDMI', type: AudioNodeType.HDMI}, |
| 78 {name: 'Internal Speaker', type: AudioNodeType.INTERNAL_SPEAKER}, |
| 79 {name: 'Internal Mic', type: AudioNodeType.INTERNAL_MIC}, |
| 80 {name: 'Keyboard Mic', type: AudioNodeType.KEYBOARD_MIC}, |
| 81 {name: 'Aokr', type: AudioNodeType.AOKR}, |
| 82 {name: 'Post Mix Loopback', type: AudioNodeType.POST_MIX_LOOPBACK}, |
| 83 {name: 'Post Dsp Loopback', type: AudioNodeType.POST_DSP_LOOPBACK}, |
| 84 {name: 'Other', type: AudioNodeType.OTHER} |
| 85 ]; |
| 86 } |
| 87 }, |
| 88 }, |
| 89 |
| 90 ready: function() { |
| 91 this.title = 'Audio Settings'; |
| 92 }, |
| 93 |
| 94 /** |
| 95 * Adds a new node with default settings to the list of nodes. |
| 96 */ |
| 97 appendNewNode: function() { |
| 98 this.push('nodes', new AudioNode()); |
| 99 }, |
| 100 |
| 101 /** |
| 102 * This adds or modifies an audio node to the AudioNodeList. |
| 103 * @param {model: {index: number}} e Event with a model containing |
| 104 * the index in |nodes| to add. |
| 105 */ |
| 106 insertAudioNode: function(e) { |
| 107 // Create a new audio node and add all the properties from |nodes[i]|. |
| 108 // Also, send the corresponding type value based on the name of |info.type|. |
| 109 var info = this.nodes[e.model.index]; |
| 110 chrome.send('insertAudioNode', [info]); |
| 111 }, |
| 112 |
| 113 /** |
| 114 * Removes the audio node with id |id|. |
| 115 * @param {model: {index: number}} e Event with a model containing |
| 116 * the index in |nodes| to add. |
| 117 */ |
| 118 removeAudioNode: function(e) { |
| 119 var info = this.nodes[e.model.index]; |
| 120 chrome.send('removeAudioNode', [info.id]); |
| 121 }, |
| 122 |
| 123 /** |
| 124 * Called by the WebUI which provides a list of nodes. |
| 125 * @param {!Array<!AudioNode>} nodeList A list of audio nodes. |
| 126 */ |
| 127 updateAudioNodes: function(nodeList) { |
| 128 /** @type {!Array<!AudioNode>} */ var newNodeList = []; |
| 129 for (var i = 0; i < nodeList.length; ++i) { |
| 130 // Create a new audio node and add all the properties from |nodeList[i]|. |
| 131 var node = new AudioNode(); |
| 132 Object.assign(node, nodeList[i]); |
| 133 newNodeList.push(node); |
| 134 } |
| 135 this.nodes = newNodeList; |
| 136 } |
| 137 }); |
OLD | NEW |