| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Keeps track of all the existing PlayerInfo and | 6 * @fileoverview Keeps track of all the existing PlayerInfo and |
| 7 * audio stream objects and is the entry-point for messages from the backend. | 7 * audio stream objects and is the entry-point for messages from the backend. |
| 8 * | 8 * |
| 9 * The events captured by Manager (add, remove, update) are relayed | 9 * The events captured by Manager (add, remove, update) are relayed |
| 10 * to the clientRenderer which it can choose to use to modify the UI. | 10 * to the clientRenderer which it can choose to use to modify the UI. |
| 11 */ | 11 */ |
| 12 var Manager = (function() { | 12 var Manager = (function() { |
| 13 'use strict'; | 13 'use strict'; |
| 14 | 14 |
| 15 function Manager(clientRenderer) { | 15 function Manager(clientRenderer) { |
| 16 this.players_ = {}; | 16 this.players_ = {}; |
| 17 this.audioStreams_ = {}; | 17 this.audioComponents_ = []; |
| 18 this.clientRenderer_ = clientRenderer; | 18 this.clientRenderer_ = clientRenderer; |
| 19 } | 19 } |
| 20 | 20 |
| 21 Manager.prototype = { | 21 Manager.prototype = { |
| 22 /** | 22 /** |
| 23 * Adds an audio-stream to the dictionary of audio-streams to manage. | 23 * Updates an audio-component. |
| 24 * @param id The unique-id of the audio-stream. | 24 * @param componentType Integer AudioComponent enum value; must match values |
| 25 * from the AudioLogFactory::AudioComponent enum. |
| 26 * @param componentId The unique-id of the audio-component. |
| 27 * @param componentData The actual component data dictionary. |
| 25 */ | 28 */ |
| 26 addAudioStream: function(id) { | 29 updateAudioComponent: function(componentType, componentId, componentData) { |
| 27 this.audioStreams_[id] = this.audioStreams_[id] || {}; | 30 if (!(componentType in this.audioComponents_)) |
| 28 this.clientRenderer_.audioStreamAdded(this.audioStreams_, | 31 this.audioComponents_[componentType] = {}; |
| 29 this.audioStreams_[id]); | 32 if (!(componentId in this.audioComponents_[componentType])) { |
| 30 }, | 33 this.audioComponents_[componentType][componentId] = componentData; |
| 31 | 34 } else { |
| 32 /** | 35 for (var key in componentData) { |
| 33 * Sets properties of an audiostream. | 36 this.audioComponents_[componentType][componentId][key] = |
| 34 * @param id The unique-id of the audio-stream. | 37 componentData[key]; |
| 35 * @param properties A dictionary of properties to be added to the | 38 } |
| 36 * audio-stream. | |
| 37 */ | |
| 38 updateAudioStream: function(id, properties) { | |
| 39 for (var key in properties) { | |
| 40 this.audioStreams_[id][key] = properties[key]; | |
| 41 } | 39 } |
| 42 this.clientRenderer_.audioStreamAdded( | 40 this.clientRenderer_.audioComponentAdded( |
| 43 this.audioStreams_, this.audioStreams_[id]); | 41 componentType, this.audioComponents_[componentType]); |
| 44 }, | 42 }, |
| 45 | 43 |
| 46 /** | 44 /** |
| 47 * Removes an audio-stream from the manager. | 45 * Removes an audio-stream from the manager. |
| 48 * @param id The unique-id of the audio-stream. | 46 * @param id The unique-id of the audio-stream. |
| 49 */ | 47 */ |
| 50 removeAudioStream: function(id) { | 48 removeAudioComponent: function(componentType, componentId) { |
| 51 this.clientRenderer_.audioStreamRemoved( | 49 if (!(componentType in this.audioComponents_) || |
| 52 this.audioStreams_, this.audioStreams_[id]); | 50 !(componentId in this.audioComponents_[componentType])) { |
| 53 delete this.audioStreams_[id]; | 51 return; |
| 52 } |
| 53 |
| 54 delete this.audioComponents_[componentType][componentId]; |
| 55 this.clientRenderer_.audioComponentRemoved( |
| 56 componentType, this.audioComponents_[componentType]); |
| 54 }, | 57 }, |
| 55 | 58 |
| 56 | |
| 57 /** | 59 /** |
| 58 * Adds a player to the list of players to manage. | 60 * Adds a player to the list of players to manage. |
| 59 */ | 61 */ |
| 60 addPlayer: function(id) { | 62 addPlayer: function(id) { |
| 61 if (this.players_[id]) { | 63 if (this.players_[id]) { |
| 62 return; | 64 return; |
| 63 } | 65 } |
| 64 // Make the PlayerProperty and add it to the mapping | 66 // Make the PlayerProperty and add it to the mapping |
| 65 this.players_[id] = new PlayerInfo(id); | 67 this.players_[id] = new PlayerInfo(id); |
| 66 this.clientRenderer_.playerAdded(this.players_, this.players_[id]); | 68 this.clientRenderer_.playerAdded(this.players_, this.players_[id]); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 this.players_[id].addProperty(timestamp, key, value); | 107 this.players_[id].addProperty(timestamp, key, value); |
| 106 this.clientRenderer_.playerUpdated(this.players_, | 108 this.clientRenderer_.playerUpdated(this.players_, |
| 107 this.players_[id], | 109 this.players_[id], |
| 108 key, | 110 key, |
| 109 value); | 111 value); |
| 110 } | 112 } |
| 111 }; | 113 }; |
| 112 | 114 |
| 113 return Manager; | 115 return Manager; |
| 114 }()); | 116 }()); |
| OLD | NEW |