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
3 // found in the LICENSE file.
6 * @fileoverview Keeps track of all the existing PlayerInfo and
7 * audio stream objects and is the entry-point for messages from the backend.
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.
12 var Manager = (function() {
15 function Manager(clientRenderer) {
17 this.audioComponents_ = [];
18 this.clientRenderer_ = clientRenderer;
23 * Updates an audio-component.
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.
29 updateAudioComponent: function(componentType, componentId, componentData) {
30 if (!(componentType in this.audioComponents_))
31 this.audioComponents_[componentType] = {};
32 if (!(componentId in this.audioComponents_[componentType])) {
33 this.audioComponents_[componentType][componentId] = componentData;
35 for (var key in componentData) {
36 this.audioComponents_[componentType][componentId][key] =
40 this.clientRenderer_.audioComponentAdded(
41 componentType, this.audioComponents_[componentType]);
45 * Removes an audio-stream from the manager.
46 * @param id The unique-id of the audio-stream.
48 removeAudioComponent: function(componentType, componentId) {
49 if (!(componentType in this.audioComponents_) ||
50 !(componentId in this.audioComponents_[componentType])) {
54 delete this.audioComponents_[componentType][componentId];
55 this.clientRenderer_.audioComponentRemoved(
56 componentType, this.audioComponents_[componentType]);
60 * Adds a player to the list of players to manage.
62 addPlayer: function(id) {
63 if (this.players_[id]) {
66 // Make the PlayerProperty and add it to the mapping
67 this.players_[id] = new PlayerInfo(id);
68 this.clientRenderer_.playerAdded(this.players_, this.players_[id]);
72 * Attempts to remove a player from the UI.
73 * @param id The ID of the player to remove.
75 removePlayer: function(id) {
76 delete this.players_[id];
77 this.clientRenderer_.playerRemoved(this.players_, this.players_[id]);
80 updatePlayerInfoNoRecord: function(id, timestamp, key, value) {
81 if (!this.players_[id]) {
82 console.error('[updatePlayerInfo] Id ' + id + ' does not exist');
86 this.players_[id].addPropertyNoRecord(timestamp, key, value);
87 this.clientRenderer_.playerUpdated(this.players_,
95 * @param id The unique ID that identifies the player to be updated.
96 * @param timestamp The timestamp of when the change occured. This
97 * timestamp is *not* normalized.
98 * @param key The name of the property to be added/changed.
99 * @param value The value of the property.
101 updatePlayerInfo: function(id, timestamp, key, value) {
102 if (!this.players_[id]) {
103 console.error('[updatePlayerInfo] Id ' + id + ' does not exist');
107 this.players_[id].addProperty(timestamp, key, value);
108 this.clientRenderer_.playerUpdated(this.players_,